|
1 | 1 | 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, |
11 | 5 | };
|
12 | 6 |
|
13 | 7 | use config::{Config, ConfigError, Environment, File};
|
@@ -52,6 +46,36 @@ impl Settings {
|
52 | 46 | // Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key
|
53 | 47 | s.merge(Environment::with_prefix("steamsync").separator("-"))?;
|
54 | 48 |
|
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 | + } |
56 | 80 | }
|
57 | 81 | }
|
0 commit comments