From 32b1272ff6dd769f54b950fe4e8ac05ef3b0eec2 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Sun, 10 Sep 2023 16:58:42 +0200 Subject: [PATCH] cfg --- src/config.rs | 22 ++++++++++++++++++++++ src/structs.rs | 7 +++++++ 2 files changed, 29 insertions(+) create mode 100644 src/config.rs diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..4c231b0 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,22 @@ +use crate::structs::Config; + +use std::{fs, path::PathBuf}; + +const DEFAULT: Config = Config { + update_only: false, + skip_self_update: false, + bonus_content: false, +}; + +pub fn load(config_path: PathBuf) -> Config { + if config_path.exists() { + let cfg = fs::read_to_string(&config_path).unwrap(); + let cfg: Config = serde_json::from_str(&cfg).unwrap_or(DEFAULT); + return cfg; + } + DEFAULT +} + +pub fn save(config_path: PathBuf, config: Config) { + fs::write(config_path, serde_json::to_string(&config).unwrap()).unwrap(); +} diff --git a/src/structs.rs b/src/structs.rs index 1a188dc..97bb5ab 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -12,3 +12,10 @@ pub struct Game<'a> { pub references: Vec<&'a str>, pub app_id: u32, } + +#[derive(serde::Deserialize, serde::Serialize)] +pub struct Config { + pub update_only: bool, + pub skip_self_update: bool, + pub bonus_content: bool, +}