From d63d81e3490782ddbf85518eb9a7b7929e038bee Mon Sep 17 00:00:00 2001 From: akanyan Date: Thu, 10 Apr 2025 13:53:20 +0000 Subject: [PATCH] feat: also copy aime.txt --- rust/src/cmd.rs | 2 +- rust/src/modules/segatools.rs | 22 +++++++++++++++++++--- src/components/options/Aime.vue | 9 +++++++-- src/components/options/Segatools.vue | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/rust/src/cmd.rs b/rust/src/cmd.rs index a6a4b36..0cd8159 100644 --- a/rust/src/cmd.rs +++ b/rust/src/cmd.rs @@ -357,7 +357,7 @@ pub async fn load_segatools_ini(state: State<'_, Mutex>, path: PathBuf) // Stupid path escape hack for the ini reader let str = str.replace("\\", "\\\\").replace("\\\\\\\\", "\\\\"); let ini = Ini::load_from_str(&str).map_err(|e| e.to_string())?; - p.data.sgt.load_from_ini(&ini); + p.data.sgt.load_from_ini(&ini, p.config_dir()).map_err(|e| e.to_string())?; p.data.network.load_from_ini(&ini).map_err(|e| e.to_string())?; if let Some(kb) = &mut p.data.keyboard { kb.load_from_ini(&ini).map_err(|e| e.to_string())?; diff --git a/rust/src/modules/segatools.rs b/rust/src/modules/segatools.rs index 7d1baa8..a7c6374 100644 --- a/rust/src/modules/segatools.rs +++ b/rust/src/modules/segatools.rs @@ -1,5 +1,4 @@ -use std::path::PathBuf; - +use std::path::{PathBuf, Path}; use anyhow::{anyhow, Result}; use ini::Ini; use crate::{model::{misc::Game, profile::{Aime, Segatools}, segatools_base::segatools_base}, profiles::ProfilePaths, util::{self, PathStr}}; @@ -31,13 +30,30 @@ impl Segatools { _ => {}, } } - pub fn load_from_ini(&mut self, ini: &Ini) { + pub fn load_from_ini(&mut self, ini: &Ini, config_dir: impl AsRef) -> Result<()> { log::debug!("loading sgt"); if let Some(s) = ini.section(Some("vfs")) { s.get("amfs").map(|v| self.amfs = PathBuf::from(v)); s.get("appdata").map(|v| self.appdata = PathBuf::from(v)); s.get("option").map(|v| self.option = PathBuf::from(v)); } + + if let Some(s) = ini.section(Some("aime")) { + if s.get("enable").unwrap_or("0") == "1" { + if let Some(aime_path) = s.get("aimePath") { + if let Some(game_dir) = self.target.parent() { + let target = game_dir.join(aime_path); + std::fs::copy(target, config_dir.as_ref().join("aime.txt"))?; + } else { + log::error!("profile doesn't have a game directory"); + } + } else { + log::warn!("aime emulation is enabled, but no aimePath specified"); + } + } + } + + Ok(()) } pub async fn line_up(&self, p: &impl ProfilePaths, game: Game) -> Result { log::debug!("begin line-up: segatools"); diff --git a/src/components/options/Aime.vue b/src/components/options/Aime.vue index afa2305..2be9f60 100644 --- a/src/components/options/Aime.vue +++ b/src/components/options/Aime.vue @@ -3,6 +3,7 @@ import { computed, ref } from 'vue'; import InputText from 'primevue/inputtext'; import Select from 'primevue/select'; import ToggleSwitch from 'primevue/toggleswitch'; +import { listen } from '@tauri-apps/api/event'; import * as path from '@tauri-apps/api/path'; import { readTextFile, writeTextFile } from '@tauri-apps/plugin-fs'; import OptionCategory from '../OptionCategory.vue'; @@ -40,10 +41,14 @@ const aimeCodePaste = (ev: ClipboardEvent) => { .join('') ?? ''; }; -(async () => { +const load = async () => { const aime_path = await path.join(await prf.configDir, 'aime.txt'); aimeCode.value = await readTextFile(aime_path).catch(() => ''); -})(); +}; + +listen('reload-aime-code', load); + +load();