From 39240807a19538142fb46f23f61f54ded98a22aa Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 7 May 2023 01:42:02 +0200 Subject: refactor: Prepare code for installing older Northstar versions (#305) * refactor: Rename function Rename `install_northstar` to `install_latest_northstar` to better indicate what it does * refactor: Have updater just call installer * refactor: Move package selection to calling func During installation, package should already be known so get package name earlier as opposed to passing `Option` * chore: Format fix * refactor: Allow passing NS version to install If no version is passed, fallback is to latest * refactor: Rename function Back to `install_northstar` from `install_latest_northstar` as the function can now install any Northstar version * refactor: Do a borrow instead of clone * refactor: Use `map` and `unwrap_or` instead of `match` --- src-tauri/src/lib.rs | 19 ++++++------------- src-tauri/src/main.rs | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9a05e1db..b5a5a5e9 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -279,19 +279,9 @@ async fn do_install( pub async fn install_northstar( window: tauri::Window, game_path: &str, - northstar_package_name: Option, + northstar_package_name: String, + version_number: Option, ) -> Result { - let northstar_package_name = match northstar_package_name { - Some(northstar_package_name) => { - if northstar_package_name.len() <= 1 { - "Northstar".to_string() - } else { - northstar_package_name - } - } - None => "Northstar".to_string(), - }; - let index = thermite::api::get_package_index().unwrap().to_vec(); let nmod = index .iter() @@ -299,11 +289,14 @@ pub async fn install_northstar( .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???")) .unwrap(); + // Use passed version or latest if no version was passed + let version = version_number.as_ref().unwrap_or(&nmod.latest); + log::info!("Install path \"{}\"", game_path); match do_install( window, - nmod.versions.get(&nmod.latest).unwrap(), + nmod.versions.get(version).unwrap(), std::path::Path::new(game_path), ) .await diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2e4b3370..1ba12474 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -327,9 +327,22 @@ async fn install_northstar_caller( window: tauri::Window, game_path: String, northstar_package_name: Option, + version_number: Option, ) -> Result { log::info!("Running"); - match install_northstar(window, &game_path, northstar_package_name).await { + + // Get Northstar package name (`Northstar` vs `NorthstarReleaseCandidate`) + let northstar_package_name = northstar_package_name + .map(|name| { + if name.len() <= 1 { + "Northstar".to_string() + } else { + name + } + }) + .unwrap_or("Northstar".to_string()); + + match install_northstar(window, &game_path, northstar_package_name, version_number).await { Ok(_) => Ok(true), Err(err) => { log::error!("{}", err); @@ -348,13 +361,7 @@ async fn update_northstar_caller( log::info!("Updating Northstar"); // Simply re-run install with up-to-date version for upate - match install_northstar(window, &game_path, northstar_package_name).await { - Ok(_) => Ok(true), - Err(err) => { - log::error!("{}", err); - Err(err) - } - } + install_northstar_caller(window, game_path, northstar_package_name, None).await } #[tauri::command] -- cgit v1.2.3