use config values

This commit is contained in:
mxve 2023-09-10 17:36:01 +02:00
parent ad7e78ec47
commit 8a14008706
3 changed files with 28 additions and 15 deletions

View File

@ -2,19 +2,14 @@ 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);
let cfg: Config = serde_json::from_str(&cfg).unwrap_or(Config::default());
return cfg;
}
DEFAULT
save(config_path.clone(), Config::default());
Config::default()
}
pub fn save(config_path: PathBuf, config: Config) {

View File

@ -1,3 +1,4 @@
mod config;
mod github;
mod global;
mod http;
@ -223,23 +224,30 @@ fn launch(file_path: &PathBuf) {
fn main() {
let mut args: Vec<String> = std::env::args().collect();
let mut cfg = config::load(PathBuf::from("alterware-launcher.json"));
let mut update_only = false;
if args.contains(&String::from("update")) {
update_only = true;
cfg.update_only = true;
args.iter()
.position(|r| r == "update")
.map(|e| args.remove(e));
}
if !args.contains(&String::from("skip-launcher-update")) {
self_update::run(update_only);
if !args.contains(&String::from("skip-launcher-update")) && !cfg.skip_self_update {
self_update::run(cfg.update_only);
} else {
args.iter()
.position(|r| r == "skip-launcher-update")
.map(|e| args.remove(e));
}
if args.contains(&String::from("bonus")) {
cfg.bonus_content = true;
args.iter()
.position(|r| r == "bonus")
.map(|e| args.remove(e));
}
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
let games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
@ -251,7 +259,7 @@ fn main() {
for r in g.references.iter() {
if std::path::Path::new(r).exists() {
if g.client.len() > 1 {
if update_only {
if cfg.update_only {
game = String::from(g.client[0]);
break 'main;
}
@ -279,7 +287,7 @@ fn main() {
for c in g.client.iter() {
if c == &game {
update(g, &std::env::current_dir().unwrap());
if !update_only {
if !cfg.update_only {
launch(&PathBuf::from(format!("{}.exe", c)));
}
return;

View File

@ -13,9 +13,19 @@ pub struct Game<'a> {
pub app_id: u32,
}
#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Default, serde::Deserialize, serde::Serialize)]
pub struct Config {
pub update_only: bool,
pub skip_self_update: bool,
pub bonus_content: bool,
}
// impl Default for Config {
// fn default() -> Self {
// Self {
// update_only: false,
// skip_self_update: false,
// bonus_content: false,
// }
// }
// }