This commit is contained in:
mxve 2023-10-06 08:34:42 +02:00
parent 6a8c11b101
commit 4bdecabbe5
3 changed files with 21 additions and 12 deletions

View File

@ -13,17 +13,18 @@ pub fn load(config_path: PathBuf) -> Config {
} }
pub fn save(config_path: PathBuf, config: 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(_) => (), Ok(_) => (),
Err(e) => { Err(e) => match e.kind() {
match e.kind() { std::io::ErrorKind::NotFound => {
std::io::ErrorKind::NotFound => { fs::create_dir_all(config_path.parent().unwrap()).unwrap();
fs::create_dir_all(config_path.parent().unwrap()).unwrap(); save(config_path, config);
return save(config_path, config);
}
_ => println!("Could not save config file, got:\n{}\n", e),
} }
} _ => println!("Could not save config file, got:\n{}\n", e),
},
} }
} }

View File

@ -1,3 +1,4 @@
use crate::global;
use crate::misc; use crate::misc;
use std::{fs, io::Write, path::Path, str}; use std::{fs, io::Write, path::Path, str};
@ -7,7 +8,11 @@ pub fn get_body(url: &str) -> Vec<u8> {
match http_req::request::Request::new(&url.try_into().unwrap()) match http_req::request::Request::new(&url.try_into().unwrap())
.header( .header(
"User-Agent", "User-Agent",
"AlterWare Launcher | github.com/mxve/alterware-launcher", &format!(
"AlterWare Launcher | github.com/{}/{}",
global::GH_OWNER,
global::GH_REPO
),
) )
.send(&mut res) .send(&mut res)
{ {

View File

@ -29,8 +29,8 @@ pub fn run(_update_only: bool) {
pub fn run(update_only: bool) { pub fn run(update_only: bool) {
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use crate::misc;
use crate::http; use crate::http;
use crate::misc;
let working_dir = std::env::current_dir().unwrap(); let working_dir = std::env::current_dir().unwrap();
let files = fs::read_dir(&working_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(); self_replace::self_replace("alterware-launcher-update.exe").unwrap();
fs::remove_file(&file_path).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."); println!("Please restart the launcher.");
if !update_only { if !update_only {
misc::stdin(); misc::stdin();