Skip to content

Commit

Permalink
Use implicit default primary manifest URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jul 20, 2024
1 parent a466c6e commit 266883d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* Fixed:
* CLI: Some commands would fail with relative path arguments.
* Changed:
* In the config file, `manifest.url` is now set to `null` by default
to indicate that the default URL should be used,
rather than explicitly putting the default URL in the file.
* Updated translations.
(Thanks to contributors on the [Crowdin project](https://crowdin.com/project/ludusavi))

Expand Down
6 changes: 3 additions & 3 deletions src/gui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ pub fn manifest<'a>(
.spacing(0)
.style(style::Checkbox),
)
.push(iced::widget::TextInput::new("", &config.manifest.url).width(Length::Fill))
.push_maybe(get_checked(Some(&config.manifest.url), cache))
.push_maybe(get_updated(Some(&config.manifest.url), cache))
.push(iced::widget::TextInput::new("", config.manifest.url()).width(Length::Fill))
.push_maybe(get_checked(Some(config.manifest.url()), cache))
.push_maybe(get_updated(Some(config.manifest.url()), cache))
.push_if(!config.manifest.secondary.is_empty(), || {
Space::with_width(right_offset)
}),
Expand Down
16 changes: 15 additions & 1 deletion src/resource/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
lang::Language,
prelude::{app_dir, CANONICAL_VERSION},
resource::{
config::{Config, Root},
config::{self, Config, Root},
manifest::ManifestUpdate,
ResourceFile, SaveableResourceFile,
},
Expand Down Expand Up @@ -34,6 +34,7 @@ pub struct Release {
pub struct Migrations {
pub adopted_cache: bool,
pub fixed_spanish_config: bool,
pub set_default_manifest_url_to_null: bool,
}

pub type Manifests = HashMap<String, Manifest>;
Expand Down Expand Up @@ -82,6 +83,19 @@ impl Cache {
updated = true;
}

if !self.migrations.set_default_manifest_url_to_null {
if config
.manifest
.url
.as_ref()
.is_some_and(|url| url == config::MANIFEST_URL)
{
config.manifest.url = None;
}
self.migrations.set_default_manifest_url_to_null = true;
updated = true;
}

if self.roots.is_empty() && !config.roots.is_empty() {
self.add_roots(&config.roots);
updated = true;
Expand Down
21 changes: 14 additions & 7 deletions src/resource/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use crate::{
scan::registry_compat::RegistryItem,
};

const MANIFEST_URL: &str = "https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/master/data/manifest.yaml";
pub const MANIFEST_URL: &str =
"https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/master/data/manifest.yaml";

fn default_backup_dir() -> StrictPath {
StrictPath::new(format!("{}/ludusavi-backup", CommonPath::Home.get().unwrap()))
Expand Down Expand Up @@ -67,14 +68,20 @@ impl Default for Release {
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(default, rename_all = "camelCase")]
pub struct ManifestConfig {
pub url: String,
pub enable: bool,
/// Where to download the primary manifest.
/// Default: https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/master/data/manifest.yaml
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
pub enable: bool,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub secondary: Vec<SecondaryManifestConfig>,
}

impl ManifestConfig {
pub fn url(&self) -> &str {
self.url.as_deref().unwrap_or(MANIFEST_URL)
}

pub fn secondary_manifest_urls(&self, force: bool) -> Vec<&str> {
self.secondary
.iter()
Expand Down Expand Up @@ -1150,7 +1157,7 @@ impl ToString for CustomGameKind {
impl Default for ManifestConfig {
fn default() -> Self {
Self {
url: MANIFEST_URL.to_string(),
url: None,
enable: true,
secondary: vec![],
}
Expand Down Expand Up @@ -1894,7 +1901,7 @@ mod tests {
Config {
runtime: Default::default(),
manifest: ManifestConfig {
url: s("example.com"),
url: Some(s("example.com")),
enable: true,
secondary: vec![]
},
Expand Down Expand Up @@ -2004,7 +2011,7 @@ mod tests {
runtime: Default::default(),
release: Release { check: true },
manifest: ManifestConfig {
url: s("example.com"),
url: Some(s("example.com")),
enable: true,
secondary: vec![SecondaryManifestConfig::Remote {
url: s("example.com/2"),
Expand Down Expand Up @@ -2193,7 +2200,7 @@ customGames:
runtime: Default::default(),
release: Default::default(),
manifest: ManifestConfig {
url: s("example.com"),
url: Some(s("example.com")),
enable: true,
secondary: vec![]
},
Expand Down
2 changes: 1 addition & 1 deletion src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl Manifest {
let mut out = vec![];

if config.enable || force {
out.push(Self::update_one(&config.url, &cache, force, true));
out.push(Self::update_one(config.url(), &cache, force, true));
}

for secondary in config.secondary_manifest_urls(force) {
Expand Down

0 comments on commit 266883d

Please sign in to comment.