diff --git a/src/defaultconfig.toml b/src/defaultconfig.toml new file mode 100644 index 0000000..246ed20 --- /dev/null +++ b/src/defaultconfig.toml @@ -0,0 +1,4 @@ +debug= false + +[steamgrid_db] +enabled = true \ No newline at end of file diff --git a/src/egs/settings.rs b/src/egs/settings.rs index 22f5c0a..949d401 100644 --- a/src/egs/settings.rs +++ b/src/egs/settings.rs @@ -6,24 +6,4 @@ pub struct EpicGamesLauncherSettings { pub location: Option, } -impl Default for EpicGamesLauncherSettings { - fn default() -> Self { - - // On windows - // Even if no path is given, we can try to guess, so lets enable by default - #[cfg(target_os = "windows")] - let enabled = true; - - - // On linux - // We can not guess, so lets not enable by default - #[cfg(target_os = "linux")] - let enabled = false; - - EpicGamesLauncherSettings { - enabled, - location: None, - } - } -} diff --git a/src/legendary/settings.rs b/src/legendary/settings.rs index a9a29e5..fdab6eb 100644 --- a/src/legendary/settings.rs +++ b/src/legendary/settings.rs @@ -4,13 +4,4 @@ use serde::Deserialize; pub struct LegendarySettings { pub enabled: bool, pub executable: Option, -} - -impl Default for LegendarySettings { - fn default() -> Self { - Self { - enabled: true, - executable: None, - } - } -} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7ed208..3f15d3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,8 +84,14 @@ where { if platform.enabled() { let shortcuts_to_add_result = platform.get_shortcuts(); + match shortcuts_to_add_result { Ok(shortcuts_to_add) => { + println!( + "Found {} games for platform {}", + shortcuts_to_add.len(), + platform.name() + ); current_shortcuts.retain(|f| !f.tags.contains(&platform.name().to_owned())); for shortcut in shortcuts_to_add { let shortcut_owned: ShortcutOwned = shortcut.into(); diff --git a/src/settings.rs b/src/settings.rs index fcf7603..3592a4b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -4,9 +4,9 @@ use crate::{ use config::{Config, ConfigError, Environment, File}; use serde::Deserialize; -use std::{env, path::Path}; +use std::{env}; -#[derive(Debug, Deserialize, Default)] +#[derive(Debug, Deserialize)] pub struct Settings { pub debug: bool, pub epic_games: EpicGamesLauncherSettings, @@ -14,35 +14,27 @@ pub struct Settings { pub steamgrid_db: SteamGridDbSettings, } -#[derive(Debug, Deserialize, Default)] -struct SettingsOptional { - pub debug: Option, - pub epic_games: Option, - pub legendary: Option, - pub steamgrid_db: Option, -} - -impl From for Settings { - fn from(optional: SettingsOptional) -> Self { - Self { - debug: optional.debug.unwrap_or(false), - epic_games: optional.epic_games.unwrap_or(Default::default()), - legendary: optional.legendary.unwrap_or(Default::default()), - steamgrid_db: optional.steamgrid_db.unwrap_or(Default::default()), - } - } -} - //https://github.com/JosefNemec/Playnite/tree/master/source/Plugins/OriginLibrary //https://github.com/JosefNemec/Playnite/blob/master/source/Plugins/OriginLibrary/Origin.cs#L109 impl Settings { pub fn new() -> Result { - let default = Self::default(); - if !Path::new("config.toml").exists() { - return Ok(default); - } let mut s = Config::new(); + let default_str = include_str!("defaultconfig.toml"); + s.merge(File::from_str(default_str, config::FileFormat::Toml))?; + + let enable_legendary = true; + let enable_epic = false; + + #[cfg(target_os = "windows")] + let enable_legendary = false; + #[cfg(target_os = "windows")] + let enable_epic = true; + + s.set_default("legendary.enabled", enable_legendary)?; + s.set_default("epic_games.enabled", enable_epic)?; + + // Start off by merging in the "default" configuration file s.merge(File::with_name("config.toml").required(false))?; @@ -60,9 +52,6 @@ impl Settings { // Eg.. `STEAM_SYNC_DEBUG=1 ./target/app` would set the `debug` key s.merge(Environment::with_prefix("steam_sync"))?; - // You can deserialize (and thus freeze) the entire configuration as - let optionals: SettingsOptional = s.try_into()?; - - Ok(optionals.into()) + s.try_into() } } diff --git a/src/steamgriddb/settings.rs b/src/steamgriddb/settings.rs index 57bd082..1eac065 100644 --- a/src/steamgriddb/settings.rs +++ b/src/steamgriddb/settings.rs @@ -4,13 +4,4 @@ use serde::Deserialize; pub struct SteamGridDbSettings { pub enabled: bool, pub auth_key: Option, -} - -impl Default for SteamGridDbSettings { - fn default() -> Self { - Self { - enabled: true, - auth_key: None, - } - } -} +} \ No newline at end of file