Skip to content

Commit a942c3c

Browse files
committed
Write a config file if it is missing
1 parent 4cc2672 commit a942c3c

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

src/defaultconfig.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
debug= false
22

33
[steamgrid_db]
4+
auth_key = "Write your authentication key between these quotes"
5+
enabled = true
6+
prefer_animated = false
47

58
[origin]
69
enabled = true
@@ -19,15 +22,11 @@ enabled = true
1922
[legendary]
2023
enabled = true
2124

22-
[steam]
23-
2425
[itch]
2526
enabled = true
2627
create_symlinks = true
2728

28-
[steamgrid_db]
29+
[lutris]
2930
enabled = true
30-
prefer_animated = false
3131

32-
[lutris]
33-
enabled = true
32+
[steam]

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
2525
#[cfg(not(feature = "ui"))]
2626
{
2727
let settings = settings::Settings::new()?;
28+
settings::Settings::write_config_if_missing();
2829
sync::run_sync(&settings).await
2930
}
3031
}

src/settings.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
use crate::{
2-
egs::EpicGamesLauncherSettings,
3-
gog::GogSettings,
4-
itch::ItchSettings,
5-
legendary::LegendarySettings,
6-
origin::OriginSettings,
7-
steam::SteamSettings,
8-
steamgriddb::SteamGridDbSettings,
9-
uplay::UplaySettings,
10-
lutris::settings::LutrisSettings,
2+
egs::EpicGamesLauncherSettings, gog::GogSettings, itch::ItchSettings,
3+
legendary::LegendarySettings, lutris::settings::LutrisSettings, origin::OriginSettings,
4+
steam::SteamSettings, steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
115
};
126

137
use config::{Config, ConfigError, Environment, File};
@@ -52,6 +46,36 @@ impl Settings {
5246
// Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key
5347
s.merge(Environment::with_prefix("steamsync").separator("-"))?;
5448

55-
s.try_into()
49+
let mut result: Result<Self, ConfigError> = s.try_into();
50+
51+
sanitize_auth_key(&mut result);
52+
53+
54+
55+
result
56+
}
57+
58+
pub fn write_config_if_missing() {
59+
let config_path = std::path::Path::new("config.toml");
60+
if !config_path.exists() {
61+
let worked = std::fs::write(config_path, include_str!("defaultconfig.toml"));
62+
match worked {
63+
Ok(_) => println!("Create configuration file at {:?}", &config_path),
64+
Err(err) => println!(
65+
"Could not create configuration file at {:?}, reason: {:?}",
66+
&config_path, err
67+
),
68+
}
69+
}
70+
}
71+
}
72+
73+
fn sanitize_auth_key(result: &mut Result<Settings, ConfigError>) {
74+
if let Ok(result) = result.as_mut() {
75+
if let Some(auth_key) = result.steamgrid_db.auth_key.as_ref() {
76+
if auth_key == "Write your authentication key between these quotes" {
77+
result.steamgrid_db.auth_key = None;
78+
}
79+
}
5680
}
5781
}

0 commit comments

Comments
 (0)