From 4bdecabbe53c86271c9c7a4ba259c11e691f26d1 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Fri, 6 Oct 2023 08:34:42 +0200 Subject: [PATCH] misc --- src/config.rs | 19 ++++++++++--------- src/http.rs | 7 ++++++- src/self_update.rs | 7 +++++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/config.rs b/src/config.rs index f1d92b5..be4c165 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,17 +13,18 @@ pub fn load(config_path: PathBuf) -> Config { } pub fn save(config_path: PathBuf, config: Config) { - match fs::write(config_path.clone(), serde_json::to_string_pretty(&config).unwrap()) { + match fs::write( + config_path.clone(), + serde_json::to_string_pretty(&config).unwrap(), + ) { Ok(_) => (), - Err(e) => { - match e.kind() { - std::io::ErrorKind::NotFound => { - fs::create_dir_all(config_path.parent().unwrap()).unwrap(); - return save(config_path, config); - } - _ => println!("Could not save config file, got:\n{}\n", e), + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => { + fs::create_dir_all(config_path.parent().unwrap()).unwrap(); + save(config_path, config); } - } + _ => println!("Could not save config file, got:\n{}\n", e), + }, } } diff --git a/src/http.rs b/src/http.rs index 4fc567e..b749015 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,3 +1,4 @@ +use crate::global; use crate::misc; use std::{fs, io::Write, path::Path, str}; @@ -7,7 +8,11 @@ pub fn get_body(url: &str) -> Vec { match http_req::request::Request::new(&url.try_into().unwrap()) .header( "User-Agent", - "AlterWare Launcher | github.com/mxve/alterware-launcher", + &format!( + "AlterWare Launcher | github.com/{}/{}", + global::GH_OWNER, + global::GH_REPO + ), ) .send(&mut res) { diff --git a/src/self_update.rs b/src/self_update.rs index c075919..701ece9 100644 --- a/src/self_update.rs +++ b/src/self_update.rs @@ -29,8 +29,8 @@ pub fn run(_update_only: bool) { pub fn run(update_only: bool) { use std::{fs, path::PathBuf}; - use crate::misc; use crate::http; + use crate::misc; let working_dir = std::env::current_dir().unwrap(); let files = fs::read_dir(&working_dir).unwrap(); @@ -83,7 +83,10 @@ pub fn run(update_only: bool) { self_replace::self_replace("alterware-launcher-update.exe").unwrap(); fs::remove_file(&file_path).unwrap(); - println!("Launcher updated. View the changelog at https://github.com/{}/{}/releases/latest", GH_OWNER, GH_REPO,); + println!( + "Launcher updated. View the changelog at https://github.com/{}/{}/releases/latest", + GH_OWNER, GH_REPO, + ); println!("Please restart the launcher."); if !update_only { misc::stdin();