diff --git a/Cargo.lock b/Cargo.lock index 1970460..94ddee6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3081,7 +3081,7 @@ dependencies = [ [[package]] name = "objdiff-cli" -version = "0.1.0" +version = "2.0.0-alpha.1" dependencies = [ "anyhow", "argp", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "objdiff-core" -version = "1.0.0" +version = "2.0.0-alpha.1" dependencies = [ "anyhow", "byteorder", @@ -3127,7 +3127,7 @@ dependencies = [ [[package]] name = "objdiff-gui" -version = "1.0.0" +version = "2.0.0-alpha.1" dependencies = [ "anyhow", "bytes", diff --git a/objdiff-cli/Cargo.toml b/objdiff-cli/Cargo.toml index 54c9c0c..396643d 100644 --- a/objdiff-cli/Cargo.toml +++ b/objdiff-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "objdiff-cli" -version = "0.1.0" +version = "2.0.0-alpha.1" edition = "2021" rust-version = "1.70" authors = ["Luke Street "] diff --git a/objdiff-core/Cargo.toml b/objdiff-core/Cargo.toml index 16a0a94..fd5d820 100644 --- a/objdiff-core/Cargo.toml +++ b/objdiff-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "objdiff-core" -version = "1.0.0" +version = "2.0.0-alpha.1" edition = "2021" rust-version = "1.70" authors = ["Luke Street "] diff --git a/objdiff-core/src/config/mod.rs b/objdiff-core/src/config/mod.rs index 9f0f54b..f1fd1fb 100644 --- a/objdiff-core/src/config/mod.rs +++ b/objdiff-core/src/config/mod.rs @@ -143,10 +143,11 @@ fn validate_min_version(config: &ProjectConfig) -> Result<()> { let Some(min_version) = &config.min_version else { return Ok(()) }; let version = semver::Version::parse(env!("CARGO_PKG_VERSION")) .context("Failed to parse package version")?; - match semver::VersionReq::parse(&format!(">={min_version}")) { - Ok(version_req) if version_req.matches(&version) => Ok(()), - Ok(_) => Err(anyhow!("Project requires objdiff version {min_version} or higher")), - Err(e) => Err(anyhow::Error::new(e).context("Failed to parse min_version")), + let min_version = semver::Version::parse(min_version).context("Failed to parse min_version")?; + if version >= min_version { + Ok(()) + } else { + Err(anyhow!("Project requires objdiff version {min_version} or higher")) } } diff --git a/objdiff-gui/Cargo.toml b/objdiff-gui/Cargo.toml index e57a881..63b21a8 100644 --- a/objdiff-gui/Cargo.toml +++ b/objdiff-gui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "objdiff-gui" -version = "1.0.0" +version = "2.0.0-alpha.1" edition = "2021" rust-version = "1.70" authors = ["Luke Street "] diff --git a/objdiff-gui/src/jobs/check_update.rs b/objdiff-gui/src/jobs/check_update.rs index 89bd288..671cd9a 100644 --- a/objdiff-gui/src/jobs/check_update.rs +++ b/objdiff-gui/src/jobs/check_update.rs @@ -5,13 +5,13 @@ use self_update::{cargo_crate_version, update::Release}; use crate::{ jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}, - update::{build_updater, BIN_NAME}, + update::{build_updater, BIN_NAME_NEW, BIN_NAME_OLD}, }; pub struct CheckUpdateResult { pub update_available: bool, pub latest_release: Release, - pub found_binary: bool, + pub found_binary: Option, } fn run_check_update(context: &JobContext, cancel: Receiver<()>) -> Result> { @@ -20,7 +20,13 @@ fn run_check_update(context: &JobContext, cancel: Receiver<()>) -> Result) -> Result> { +fn run_update( + status: &JobContext, + cancel: Receiver<()>, + bin_name: String, +) -> Result> { update_status(status, "Fetching latest release".to_string(), 0, 3, &cancel)?; let updater = build_updater().context("Failed to create release updater")?; let latest_release = updater.get_latest_release()?; let asset = latest_release .assets .iter() - .find(|a| a.name == BIN_NAME) - .ok_or_else(|| anyhow::Error::msg(formatcp!("No release asset for {}", BIN_NAME)))?; + .find(|a| a.name == bin_name) + .ok_or_else(|| anyhow::Error::msg(format!("No release asset for {bin_name}")))?; update_status(status, "Downloading release".to_string(), 1, 3, &cancel)?; let tmp_dir = tempfile::Builder::new().prefix("update").tempdir_in(current_dir()?)?; @@ -53,8 +56,8 @@ fn run_update(status: &JobContext, cancel: Receiver<()>) -> Result JobState { +pub fn start_update(ctx: &egui::Context, bin_name: String) -> JobState { start_job(ctx, "Update app", Job::Update, move |context, cancel| { - run_update(&context, cancel).map(JobResult::Update) + run_update(&context, cancel, bin_name).map(JobResult::Update) }) } diff --git a/objdiff-gui/src/update.rs b/objdiff-gui/src/update.rs index fcd33c9..b2605f2 100644 --- a/objdiff-gui/src/update.rs +++ b/objdiff-gui/src/update.rs @@ -20,8 +20,9 @@ cfg_if! { } pub const GITHUB_USER: &str = "encounter"; pub const GITHUB_REPO: &str = "objdiff"; -pub const BIN_NAME: &str = - formatcp!("{}-{}-{}{}", GITHUB_REPO, OS, ARCH, std::env::consts::EXE_SUFFIX); +pub const BIN_NAME_NEW: &str = + formatcp!("objdiff-gui-{}-{}{}", OS, ARCH, std::env::consts::EXE_SUFFIX); +pub const BIN_NAME_OLD: &str = formatcp!("objdiff-{}-{}{}", OS, ARCH, std::env::consts::EXE_SUFFIX); pub const RELEASE_URL: &str = formatcp!("https://github.com/{}/{}/releases/latest", GITHUB_USER, GITHUB_REPO); @@ -29,7 +30,8 @@ pub fn build_updater() -> self_update::errors::Result> { self_update::backends::github::Update::configure() .repo_owner(GITHUB_USER) .repo_name(GITHUB_REPO) - .bin_name(BIN_NAME) + // bin_name is required, but unused? + .bin_name(BIN_NAME_NEW) .no_confirm(true) .show_output(false) .current_version(cargo_crate_version!()) diff --git a/objdiff-gui/src/views/config.rs b/objdiff-gui/src/views/config.rs index 1c5c298..b04e1f4 100644 --- a/objdiff-gui/src/views/config.rs +++ b/objdiff-gui/src/views/config.rs @@ -41,7 +41,7 @@ pub struct ConfigViewState { pub check_update_running: bool, pub queue_check_update: bool, pub update_running: bool, - pub queue_update: bool, + pub queue_update: Option, pub build_running: bool, pub queue_build: bool, pub watch_pattern_text: String, @@ -127,9 +127,8 @@ impl ConfigViewState { jobs.push_once(Job::CheckUpdate, || start_check_update(ctx)); } - if self.queue_update { - self.queue_update = false; - jobs.push_once(Job::Update, || start_update(ctx)); + if let Some(bin_name) = self.queue_update.take() { + jobs.push_once(Job::Update, || start_update(ctx, bin_name)); } } } @@ -201,15 +200,16 @@ pub fn config_ui( if result.update_available { ui.colored_label(appearance.insert_color, "Update available"); ui.horizontal(|ui| { - if result.found_binary - && ui + if let Some(bin_name) = &result.found_binary { + if ui .add_enabled(!state.update_running, egui::Button::new("Automatic")) .on_hover_text_at_pointer( "Automatically download and replace the current build", ) .clicked() - { - state.queue_update = true; + { + state.queue_update = Some(bin_name.clone()); + } } if ui .button("Manual")