From 67872bc4d1a82e7f1d68f45be77691d552718485 Mon Sep 17 00:00:00 2001 From: akanyan Date: Fri, 9 May 2025 21:45:59 +0000 Subject: [PATCH] fix: also add post scripts --- CHANGELOG.md | 11 ++++++++--- rust/src/profiles/mod.rs | 34 +++++++++++++-------------------- rust/src/profiles/template.rs | 20 ++++++++++--------- rust/src/util.rs | 34 +++++++++++++++++++++++++++++++++ rust/tauri.conf.json | 2 +- src/components/InfoPage.vue | 4 ++-- src/components/ModStore.vue | 2 ++ src/components/ProfileList.vue | 18 +++++++++++------ src/components/options/Misc.vue | 27 ++++++++++++++++++++------ src/i18n/en.ts | 7 +++++-- src/i18n/ja.ts | 8 +++++--- src/i18n/pl.ts | 7 +++++-- 12 files changed, 119 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f411464..063b476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ -## 0.20.0 +## 0.20.1 -- Added user-customizable pre-launch scripts - Added japanese localization -- Fixed the file editor not updating state properly +- Added user-customizable scripts + - The launch script runs directly before the game, and is equivalent to adding lines above `start "AM Daemon" ...` in start.bat + - The end script runs after the game has closed for any reason, and is equivalent to adding lines below `taskkill /f /im amdaemon.exe ...` in start.bat + - This functionality is needed for cursed things such as brokenithm +- Fixed the file editor not updating its state properly +- Fixed diagnostic exports not exporting paths +- Fixed "Install recommended packages" not enabling the segatools hook ## 0.19.1 diff --git a/rust/src/profiles/mod.rs b/rust/src/profiles/mod.rs index 2708ce5..db5e10d 100644 --- a/rust/src/profiles/mod.rs +++ b/rust/src/profiles/mod.rs @@ -255,7 +255,7 @@ impl Profile { let mut game_builder; let mut amd_builder; - let mut prelaunch = None; + let mut prescript = None; let target_path = PathBuf::from(&self.data.sgt.target); let exe_dir = target_path.parent().ok_or_else(|| anyhow!("Invalid target path"))?; @@ -265,17 +265,6 @@ impl Profile { { game_builder = Command::new(sgt_dir.join(self.meta.game.inject_exe())); amd_builder = Command::new("cmd.exe"); - - let prelaunch_path = self.config_dir().join("prelaunch.bat"); - if prelaunch_path.exists() { - let mut c = Command::new("cmd"); - c.args(["/C", "start"]); - c.raw_arg("\"STARTLINER Prelaunch\""); - c.args(["cmd", "/C"]); - c.arg(prelaunch_path); - log::debug!("Prelaunch: {:?}", c); - prelaunch = Some(c.spawn()?); - } } #[cfg(target_os = "linux")] { @@ -284,14 +273,12 @@ impl Profile { game_builder.arg(sgt_dir.join(self.meta.game.inject_exe())); amd_builder.arg("cmd.exe"); + } - let prelaunch_path = self.config_dir().join("prelaunch.sh"); - if prelaunch_path.exists() { - prelaunch_builder = Some(Command::new("sh")); - c.arg(prelaunch_path); - log::debug!("Prelaunch: {:?}", c); - prelaunch = Some(c.spawn()?); - } + let script_ext = if cfg!(target_os = "windows") { "bat" } else { "sh" }; + let prescript_path = self.config_dir().join(format!("pre.{script_ext}")); + if prescript_path.exists() { + prescript = util::spawn_script(prescript_path, &exe_dir, "\"STARTLINER launch script\""); } amd_builder.env( @@ -440,11 +427,11 @@ impl Profile { util::pkill("amdaemon.exe").await; } - if let Some(mut _child) = prelaunch { + if let Some(mut _child) = prescript { #[cfg(target_os = "windows")] { // child.kill() doesn't work - util::pkill_title("STARTLINER Prelaunch").await; + util::pkill_title("STARTLINER launch script").await; } #[cfg(target_os = "linux")] { @@ -452,6 +439,11 @@ impl Profile { } } + let postscript_path = self.config_dir().join(format!("post.{script_ext}")); + if postscript_path.exists() { + _ = util::spawn_script(postscript_path, &exe_dir, "\"STARTLINER end script\""); + } + set.join_next().await.expect("No spawn").expect("No result"); log::debug!("Fin"); diff --git a/rust/src/profiles/template.rs b/rust/src/profiles/template.rs index ce87c8e..58987ff 100644 --- a/rust/src/profiles/template.rs +++ b/rust/src/profiles/template.rs @@ -49,15 +49,17 @@ impl Profile { { let sgt = &mut prf.data.sgt; - sgt.target = PathBuf::new(); - if sgt.amfs.is_absolute() { - sgt.amfs = PathBuf::new(); - } - if sgt.option.is_absolute() { - sgt.option = PathBuf::new(); - } - if sgt.appdata.is_absolute() { - sgt.appdata = PathBuf::new(); + if !is_diagnostic { + sgt.target = PathBuf::new(); + if sgt.amfs.is_absolute() { + sgt.amfs = PathBuf::new(); + } + if sgt.option.is_absolute() { + sgt.option = PathBuf::new(); + } + if sgt.appdata.is_absolute() { + sgt.appdata = PathBuf::new(); + } } } diff --git a/rust/src/util.rs b/rust/src/util.rs index a3cbfa2..5634c07 100644 --- a/rust/src/util.rs +++ b/rust/src/util.rs @@ -220,4 +220,38 @@ pub fn create_shortcut( file.Save(Some(lnk_path.to_str().ok_or_else(|| anyhow!("Illegal shortcut path"))?), true)?; Ok(()) +} + +pub fn spawn_script(path: impl AsRef, cwd: impl AsRef, title: &str) -> Option { + // Seems? like this autism is needed to: + // 1. pop up a cmd window + // 2. launch the batch + // 3. die afterwards + let mut c; + + #[cfg(target_os = "windows")] + { + c = Command::new("cmd"); + c.args(["/C", "start"]); + c.raw_arg(title); + c.args(["cmd", "/C"]); + c.arg(path.as_ref()); + c.current_dir(cwd); + } + + #[cfg(target_os = "linux")] + { + c = Command::new("sh"); + c.arg(path.as_ref()); + c.current_dir(cwd); + } + + log::debug!("Script launch: {:?}", c); + match c.spawn() { + Ok(child) => Some(child), + Err(e) => { + log::error!("unable to launch {:?}: {e}", path.as_ref()); + None + } + } } \ No newline at end of file diff --git a/rust/tauri.conf.json b/rust/tauri.conf.json index 951ef42..d7a257a 100644 --- a/rust/tauri.conf.json +++ b/rust/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "STARTLINER", - "version": "0.20.0", + "version": "0.20.1", "identifier": "zip.patafour.startliner", "build": { "beforeDevCommand": "bun run dev", diff --git a/src/components/InfoPage.vue b/src/components/InfoPage.vue index 6c862bf..8cc41cb 100644 --- a/src/components/InfoPage.vue +++ b/src/components/InfoPage.vue @@ -12,8 +12,8 @@ invoke('get_changelog').then((s) => (changelog.value = s as string));