From c62bf22d4658e674e17985d51cac14a1be885e7a Mon Sep 17 00:00:00 2001 From: simon-wh Date: Mon, 3 Apr 2023 12:17:06 +0100 Subject: [PATCH] Fix updater to work with new self_update pacakge --- Cargo.lock | 1 + wooting-analog-sdk-updater/Cargo.toml | 1 + wooting-analog-sdk-updater/src/main.rs | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7995c41..20a66c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3913,6 +3913,7 @@ dependencies = [ "clap", "json", "log", + "reqwest", "self_update", "simplelog", "winapi 0.3.9", diff --git a/wooting-analog-sdk-updater/Cargo.toml b/wooting-analog-sdk-updater/Cargo.toml index 09b1ff0..b8dbdb7 100644 --- a/wooting-analog-sdk-updater/Cargo.toml +++ b/wooting-analog-sdk-updater/Cargo.toml @@ -13,6 +13,7 @@ log = "^0.4" json = "^0.11" simplelog = "^0.7" chrono = "0.4" +reqwest = "0.11" [dependencies.winapi] diff --git a/wooting-analog-sdk-updater/src/main.rs b/wooting-analog-sdk-updater/src/main.rs index 03dfc2b..ee2ac23 100644 --- a/wooting-analog-sdk-updater/src/main.rs +++ b/wooting-analog-sdk-updater/src/main.rs @@ -10,7 +10,7 @@ extern crate chrono; use chrono::Utc; use clap::{App, Arg}; -use self_update::backends::github::{Release, ReleaseAsset}; +use self_update::update::{Release, ReleaseAsset}; use self_update::version::bump_is_greater; use simplelog::*; use std::fs::OpenOptions; @@ -19,7 +19,7 @@ use std::process::Command; #[cfg(windows)] use winapi::um::winuser; -const INSTALLER_PATH: &str = "installer.msi"; +const INSTALLER_PATH: &str = "wooting_analog_sdk_installer.msi"; const PKG_VER: &str = env!("CARGO_PKG_VERSION"); fn find_installer_asset(release: &Release) -> Option<&ReleaseAsset> { @@ -50,14 +50,17 @@ fn install_update(release: &Release) -> Result<(), Box> info!("installing"); match find_installer_asset(&release) { Some(asset) => { - let tmp_dir = self_update::TempDir::new("wooting_analog_sdk_updater")?; + let tmp_dir = self_update::TempDir::new()?; let tmp_msi_path = tmp_dir.path().join(INSTALLER_PATH); - info!("Downloading into temp file: {:?}", tmp_msi_path); + info!("Downloading {:?} into temp file: {:?}", asset, tmp_msi_path); //Put it into lower scope to force File to go out of scope to close it & finish writing { let tmp_msi = ::std::fs::File::create(&tmp_msi_path)?; - self_update::Download::from_url(&asset.download_url).download_to(&tmp_msi)?; + self_update::Download::from_url(&asset.download_url) + .set_header(reqwest::header::ACCEPT, "application/octet-stream".parse()?) + .show_progress(true) + .download_to(&tmp_msi)?; info!("Finished downloading update"); } @@ -149,7 +152,7 @@ fn main() { debug!("Called with parameters {:?}", matches); let r = check_for_update().expect("Failed to check for updates"); - let release_ver = r.tag.trim_start_matches('v'); + let release_ver = r.version.trim_start_matches('v'); let update_available = bump_is_greater(PKG_VER, release_ver).unwrap_or(false); debug!( "Github release: {} ours: {}, update available: {}", @@ -159,7 +162,7 @@ fn main() { let data = object! { "name" => "Wooting Analog SDK", "update_available" => update_available, - "new_version" => r.version(), + "new_version" => r.version.clone(), "version" => PKG_VER, "release_title" => r.name.clone(), "release_notes" => r.body.clone() @@ -173,7 +176,7 @@ fn main() { { if !matches.is_present("quiet") { let title = "Wooting Analog SDK Update\0"; - let message = format!("A new Wooting Analog SDK update is available ({}, you've got v{}), would you like to install?\0", r.tag, PKG_VER); + let message = format!("A new Wooting Analog SDK update is available ({}, you've got v{}), would you like to install?\0", r.version, PKG_VER); let l_msg: Vec = message.encode_utf16().collect(); let l_title: Vec = title.encode_utf16().collect(); unsafe {