From 3da5106f1d2448674ef748d72f961cf89d8b67e3 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 22 Apr 2023 12:07:14 -0500 Subject: [PATCH] b/game: support launching `gk` at version 0.1.35 and above (#163) --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/src/commands/binaries.rs | 48 +++++++++++++++++-- .../settings/versions/OfficialVersions.svelte | 10 +++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ddbe348..462ffa6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2289,6 +2289,7 @@ dependencies = [ "log", "reqwest", "rev_buf_reader", + "semver", "serde", "serde_json", "sysinfo", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index a0e3fd0..61485aa 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -26,6 +26,7 @@ futures-util = "0.3.26" log = "0.4.17" reqwest = { version = "0.11", features = ["json"] } rev_buf_reader = "0.3.0" +semver = "1.0.17" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.95" sysinfo = "0.28.4" diff --git a/src-tauri/src/commands/binaries.rs b/src-tauri/src/commands/binaries.rs index eb7edf0..99a8185 100644 --- a/src-tauri/src/commands/binaries.rs +++ b/src-tauri/src/commands/binaries.rs @@ -7,6 +7,7 @@ use std::{ }; use log::{info, warn}; +use semver::Version; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -493,16 +494,53 @@ pub async fn launch_game( let config_lock = config.lock().await; let config_info = common_prelude(&config_lock)?; + let tooling_version = Version::parse( + config_info + .active_version + .strip_prefix("v") + .unwrap_or(&config_info.active_version), + ) + .unwrap_or(Version::new(0, 1, 35)); // assume new format if none can be found + let data_folder = get_data_dir(&config_info, &game_name, false)?; let exec_info = get_exec_location(&config_info, "gk")?; - let mut args = vec!["-boot".to_string(), "-fakeiso".to_string()]; + let mut args; // NOTE - order unfortunately matters for gk args - if in_debug { - args.push("-debug".to_string()); + if tooling_version.major == 0 && tooling_version.minor <= 1 && tooling_version.patch < 35 { + // old argument format + args = vec![ + "-boot".to_string(), + "-fakeiso".to_string(), + "-proj-path".to_string(), + data_folder.to_string_lossy().into_owned(), + ]; + if in_debug { + args.push("-debug".to_string()); + } + } else { + args = vec![ + "-v".to_string(), + "--game".to_string(), + game_name, + "--proj-path".to_string(), + data_folder.to_string_lossy().into_owned(), + "--".to_string(), + "-boot".to_string(), + "-fakeiso".to_string(), + ]; + if in_debug { + args.push("-debug".to_string()); + } } - args.push("-proj-path".to_string()); - args.push(data_folder.to_string_lossy().into_owned()); + + log::info!( + "Launching game version {:?} -> {:?} with args: {:?}", + &config_info.active_version, + tooling_version, + args + ); + let log_file = create_log_file(&app_handle, "game.log", false)?; let mut command = Command::new(exec_info.executable_path); command diff --git a/src/routes/settings/versions/OfficialVersions.svelte b/src/routes/settings/versions/OfficialVersions.svelte index e05a09c..fdc7dd7 100644 --- a/src/routes/settings/versions/OfficialVersions.svelte +++ b/src/routes/settings/versions/OfficialVersions.svelte @@ -80,7 +80,15 @@ } // Sort releases by published date - releases = releases.sort((a, b) => b.date.localeCompare(a.date)); + releases = releases.sort((a, b) => { + if (a.date === undefined) { + return 1; + } + if (b.date === undefined) { + return -1; + } + return b.date.localeCompare(a.date); + }); versionsLoaded = true; }