Write a config file if it is missing

This commit is contained in:
Philip
2022-03-12 07:44:26 +01:00
parent 4cc2672c5f
commit a942c3c016
3 changed files with 41 additions and 17 deletions
+5 -6
View File
@@ -1,6 +1,9 @@
debug= false debug= false
[steamgrid_db] [steamgrid_db]
auth_key = "Write your authentication key between these quotes"
enabled = true
prefer_animated = false
[origin] [origin]
enabled = true enabled = true
@@ -19,15 +22,11 @@ enabled = true
[legendary] [legendary]
enabled = true enabled = true
[steam]
[itch] [itch]
enabled = true enabled = true
create_symlinks = true create_symlinks = true
[steamgrid_db]
enabled = true
prefer_animated = false
[lutris] [lutris]
enabled = true enabled = true
[steam]
+1
View File
@@ -25,6 +25,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[cfg(not(feature = "ui"))] #[cfg(not(feature = "ui"))]
{ {
let settings = settings::Settings::new()?; let settings = settings::Settings::new()?;
settings::Settings::write_config_if_missing();
sync::run_sync(&settings).await sync::run_sync(&settings).await
} }
} }
+34 -10
View File
@@ -1,13 +1,7 @@
use crate::{ use crate::{
egs::EpicGamesLauncherSettings, egs::EpicGamesLauncherSettings, gog::GogSettings, itch::ItchSettings,
gog::GogSettings, legendary::LegendarySettings, lutris::settings::LutrisSettings, origin::OriginSettings,
itch::ItchSettings, steam::SteamSettings, steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
legendary::LegendarySettings,
origin::OriginSettings,
steam::SteamSettings,
steamgriddb::SteamGridDbSettings,
uplay::UplaySettings,
lutris::settings::LutrisSettings,
}; };
use config::{Config, ConfigError, Environment, File}; use config::{Config, ConfigError, Environment, File};
@@ -52,6 +46,36 @@ impl Settings {
// Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key // Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key
s.merge(Environment::with_prefix("steamsync").separator("-"))?; s.merge(Environment::with_prefix("steamsync").separator("-"))?;
s.try_into() let mut result: Result<Self, ConfigError> = s.try_into();
sanitize_auth_key(&mut result);
result
}
pub fn write_config_if_missing() {
let config_path = std::path::Path::new("config.toml");
if !config_path.exists() {
let worked = std::fs::write(config_path, include_str!("defaultconfig.toml"));
match worked {
Ok(_) => println!("Create configuration file at {:?}", &config_path),
Err(err) => println!(
"Could not create configuration file at {:?}, reason: {:?}",
&config_path, err
),
}
}
}
}
fn sanitize_auth_key(result: &mut Result<Settings, ConfigError>) {
if let Ok(result) = result.as_mut() {
if let Some(auth_key) = result.steamgrid_db.auth_key.as_ref() {
if auth_key == "Write your authentication key between these quotes" {
result.steamgrid_db.auth_key = None;
}
}
} }
} }