From c64d8729e383f865e2f995d16e3868f8f64d7938 Mon Sep 17 00:00:00 2001 From: alterwain Date: Tue, 25 Mar 2025 01:25:30 +0300 Subject: [PATCH] modified: src/main.rs modified: src/util.rs --- src/main.rs | 9 ++++++++- src/util.rs | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 06348e2..ea99c3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,8 +344,15 @@ async fn main() { "check_updates" => { // if let Ok(Some(file_url)) = launcher::check_updates().await { - responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["sidebar_off".to_string(), "show_loading".to_string(), "update_downloads".to_string(), "Updating launcher...".to_string(), "100".to_string()] }).unwrap())); + let current_exe = std::env::current_exe().unwrap(); + let mut downloaded_file = std::env::current_dir().unwrap(); + downloaded_file.push("launcher_new.exe"); + util::simple_download(&file_url, downloaded_file.to_str().unwrap()).await.unwrap(); + let _ = std::fs::rename(¤t_exe, "old_launcher.bak"); + let _ = std::fs::rename(downloaded_file, current_exe); + let _ = std::fs::remove_file("old_launcher.bak"); + std::process::exit(0); } } _ => {} diff --git a/src/util.rs b/src/util.rs index 4d69790..fa035a7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,6 +21,13 @@ pub async fn get_image(url: &str) -> Result Ok(format!("data:image/png;base64,{}", base64_string)) } +pub async fn simple_download(url: &str, file_path: &str) -> Result<(), Box> { + let bytes = surf::get(url).recv_bytes().await?; + let mut f = File::create(file_path).await?; + f.write_all(&bytes).await?; + Ok(()) +} + pub async fn download_file(url: &str, file_path: &str, sender: UnboundedSender<(usize, String)>, status: &str, join: bool) -> Result<(), Box> { let url = url.to_string(); let file_path = file_path.to_string();