Skip to content

Commit

Permalink
#348: Allow disabling specific manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jul 17, 2024
1 parent 0195367 commit a4c35da
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

* Added:
* You can now ignore specific manifests during scans.
For example, if you only want to back up custom games,
you can now disable the primary manifest's entries.
* Fixed:
* CLI: Some commands would fail with relative path arguments.

Expand Down
10 changes: 10 additions & 0 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,16 @@ impl Application for App {
self.save_config();
Command::none()
}
Message::TogglePrimaryManifestEnabled { enabled } => {
self.config.manifest.enable = enabled;
self.save_config();
Command::none()
}
Message::ToggleSecondaryManifestEnabled { index, enabled } => {
self.config.manifest.secondary[index].enable(enabled);
self.save_config();
Command::none()
}
Message::ToggleSearch { screen } => match screen {
Screen::Backup => {
self.backup_screen.log.search.show = !self.backup_screen.log.search.show;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ pub enum Message {
index: usize,
enabled: bool,
},
TogglePrimaryManifestEnabled {
enabled: bool,
},
ToggleSecondaryManifestEnabled {
index: usize,
enabled: bool,
},
EditedSearchGameName {
screen: Screen,
value: String,
Expand Down
14 changes: 14 additions & 0 deletions src/gui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ pub fn manifest<'a>(
Row::new()
.spacing(20)
.align_items(Alignment::Center)
.push(
checkbox("", config.manifest.enable, move |enabled| {
Message::TogglePrimaryManifestEnabled { enabled }
})
.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))
Expand All @@ -152,6 +159,13 @@ pub fn manifest<'a>(
Row::new()
.spacing(20)
.align_items(Alignment::Center)
.push(
checkbox("", config.manifest.secondary[i].enabled(), move |enabled| {
Message::ToggleSecondaryManifestEnabled { index: i, enabled }
})
.spacing(0)
.style(style::Checkbox),
)
.push(button::move_up(Message::EditedSecondaryManifest, i))
.push(button::move_down(
Message::EditedSecondaryManifest,
Expand Down
76 changes: 60 additions & 16 deletions src/resource/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Runtime {
#[serde(default, rename_all = "camelCase")]
pub struct ManifestConfig {
pub url: String,
pub enable: bool,
/// Where to download the primary manifest.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub secondary: Vec<SecondaryManifestConfig>,
Expand All @@ -64,7 +65,7 @@ impl ManifestConfig {
.iter()
.filter_map(|x| match x {
SecondaryManifestConfig::Local { .. } => None,
SecondaryManifestConfig::Remote { url } => Some(url.as_str()),
SecondaryManifestConfig::Remote { url, .. } => Some(url.as_str()),
})
.collect()
}
Expand All @@ -73,14 +74,22 @@ impl ManifestConfig {
self.secondary
.iter()
.filter_map(|x| match x {
SecondaryManifestConfig::Local { path } => {
SecondaryManifestConfig::Local { path, enable } => {
if !enable {
return None;
}

let manifest = Manifest::load_from_existing(path);
if let Err(e) = &manifest {
log::error!("Cannot load secondary manifest: {:?} | {}", &path, e);
}
Some((path.clone(), manifest.ok()?))
}
SecondaryManifestConfig::Remote { url } => {
SecondaryManifestConfig::Remote { url, enable } => {
if !enable {
return None;
}

let path = Manifest::path_for(url, false);
let manifest = Manifest::load_from(&path);
if let Err(e) = &manifest {
Expand Down Expand Up @@ -116,36 +125,58 @@ impl ToString for SecondaryManifestConfigKind {
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[serde(untagged)]
pub enum SecondaryManifestConfig {
Local { path: StrictPath },
Remote { url: String },
Local {
path: StrictPath,
#[serde(default = "crate::serialization::default_true")]
enable: bool,
},
Remote {
url: String,
#[serde(default = "crate::serialization::default_true")]
enable: bool,
},
}

impl SecondaryManifestConfig {
pub fn url(&self) -> Option<&str> {
match self {
Self::Local { .. } => None,
Self::Remote { url } => Some(url.as_str()),
Self::Remote { url, .. } => Some(url.as_str()),
}
}

pub fn path(&self) -> Option<&StrictPath> {
match self {
Self::Local { path } => Some(path),
Self::Local { path, .. } => Some(path),
Self::Remote { .. } => None,
}
}

pub fn value(&self) -> String {
match self {
Self::Local { path } => path.raw(),
Self::Remote { url } => url.to_string(),
Self::Local { path, .. } => path.raw(),
Self::Remote { url, .. } => url.to_string(),
}
}

pub fn enabled(&self) -> bool {
match self {
Self::Local { enable, .. } => *enable,
Self::Remote { enable, .. } => *enable,
}
}

pub fn set(&mut self, value: String) {
match self {
Self::Local { path } => *path = StrictPath::new(value),
Self::Remote { url } => *url = value,
Self::Local { path, .. } => *path = StrictPath::new(value),
Self::Remote { url, .. } => *url = value,
}
}

pub fn enable(&mut self, enabled: bool) {
match self {
Self::Local { enable, .. } => *enable = enabled,
Self::Remote { enable, .. } => *enable = enabled,
}
}

Expand All @@ -158,12 +189,16 @@ impl SecondaryManifestConfig {

pub fn convert(&mut self, kind: SecondaryManifestConfigKind) {
match (&self, kind) {
(Self::Local { path }, SecondaryManifestConfigKind::Remote) => {
*self = Self::Remote { url: path.raw() };
(Self::Local { path, enable }, SecondaryManifestConfigKind::Remote) => {
*self = Self::Remote {
url: path.raw(),
enable: *enable,
};
}
(Self::Remote { url }, SecondaryManifestConfigKind::Local) => {
(Self::Remote { url, enable }, SecondaryManifestConfigKind::Local) => {
*self = Self::Local {
path: StrictPath::new(url.clone()),
enable: *enable,
};
}
_ => {}
Expand All @@ -173,7 +208,10 @@ impl SecondaryManifestConfig {

impl Default for SecondaryManifestConfig {
fn default() -> Self {
Self::Remote { url: "".to_string() }
Self::Remote {
url: "".to_string(),
enable: true,
}
}
}

Expand Down Expand Up @@ -1098,6 +1136,7 @@ impl Default for ManifestConfig {
fn default() -> Self {
Self {
url: MANIFEST_URL.to_string(),
enable: true,
secondary: vec![],
}
}
Expand Down Expand Up @@ -1841,6 +1880,7 @@ mod tests {
runtime: Default::default(),
manifest: ManifestConfig {
url: s("example.com"),
enable: true,
secondary: vec![]
},
language: Language::English,
Expand Down Expand Up @@ -1947,8 +1987,10 @@ mod tests {
runtime: Default::default(),
manifest: ManifestConfig {
url: s("example.com"),
enable: true,
secondary: vec![SecondaryManifestConfig::Remote {
url: s("example.com/2")
url: s("example.com/2"),
enable: true,
}]
},
language: Language::English,
Expand Down Expand Up @@ -2035,6 +2077,7 @@ runtime:
threads: ~
manifest:
url: example.com
enable: true
language: en-US
theme: light
roots:
Expand Down Expand Up @@ -2130,6 +2173,7 @@ customGames:
runtime: Default::default(),
manifest: ManifestConfig {
url: s("example.com"),
enable: true,
secondary: vec![]
},
language: Language::English,
Expand Down
4 changes: 4 additions & 0 deletions src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ impl Manifest {
}

pub fn incorporate_extensions(&mut self, config: &Config) {
if !config.manifest.enable {
self.0.clear();
}

for (path, secondary) in config.manifest.load_secondary_manifests() {
self.incorporate_secondary_manifest(path, secondary);
}
Expand Down
4 changes: 4 additions & 0 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ where
let ordered: BTreeMap<_, _> = value.iter().collect();
ordered.serialize(serializer)
}

pub const fn default_true() -> bool {
true
}

0 comments on commit a4c35da

Please sign in to comment.