diff --git a/crates/allium-menu/src/allium_menu.rs b/crates/allium-menu/src/allium_menu.rs index 92674cf..cc56cab 100644 --- a/crates/allium-menu/src/allium_menu.rs +++ b/crates/allium-menu/src/allium_menu.rs @@ -118,12 +118,13 @@ impl AlliumMenu { self.display.load(self.display.bounding_box().into())?; self.view.set_should_draw(); } - Command::SaveStateScreenshot { path, slot } => { + Command::SaveStateScreenshot { path, core, slot } => { if self.display.pop() { self.display.load(self.display.bounding_box().into())?; self.display.flush()?; let mut hasher = Sha256::new(); hasher.update(path); + hasher.update(core); hasher.update(slot.to_le_bytes()); let hash = hasher.finalize(); let base32 = encode(base32::Alphabet::Crockford, &hash); diff --git a/crates/allium-menu/src/view/ingame_menu.rs b/crates/allium-menu/src/view/ingame_menu.rs index 03124fb..fa1fa5a 100644 --- a/crates/allium-menu/src/view/ingame_menu.rs +++ b/crates/allium-menu/src/view/ingame_menu.rs @@ -225,6 +225,7 @@ where commands .send(Command::SaveStateScreenshot { path: self.path.canonicalize()?.to_string_lossy().to_string(), + core: self.res.get::().core.clone(), slot, }) .await?; @@ -257,6 +258,7 @@ where commands .send(Command::SaveStateScreenshot { path: self.path.canonicalize()?.to_string_lossy().to_string(), + core: self.res.get::().core.clone(), slot: -1, }) .await?; @@ -306,14 +308,28 @@ where .to_string_lossy() .to_string(); let slot = self.retroarch_info.as_ref().unwrap().state_slot.unwrap(); + let mut hasher = Sha256::new(); - hasher.update(path); + hasher.update(&path); + hasher.update(&self.res.get::().core); hasher.update(slot.to_le_bytes()); let hash = hasher.finalize(); let base32 = encode(base32::Alphabet::Crockford, &hash); let file_name = format!("{}.png", base32); - let path = ALLIUM_SCREENSHOTS_DIR.join(file_name); - self.image.set_path(Some(path)); + let mut screenshot_path = ALLIUM_SCREENSHOTS_DIR.join(file_name); + + // Previously, the hash did not include the core name. We try looking for that path as well. + if !screenshot_path.exists() { + let mut hasher = Sha256::new(); + hasher.update(&path); + hasher.update(slot.to_le_bytes()); + let hash = hasher.finalize(); + let base32 = encode(base32::Alphabet::Crockford, &hash); + let file_name = format!("{}.png", base32); + screenshot_path = ALLIUM_SCREENSHOTS_DIR.join(file_name); + } + + self.image.set_path(Some(screenshot_path)); } } diff --git a/crates/common/src/command.rs b/crates/common/src/command.rs index 59e5d6f..6efa563 100644 --- a/crates/common/src/command.rs +++ b/crates/common/src/command.rs @@ -20,7 +20,11 @@ pub enum Command { Search(String), Toast(String, Option), PopulateDb, - SaveStateScreenshot { path: String, slot: i8 }, + SaveStateScreenshot { + path: String, + core: String, + slot: i8, + }, } #[derive(Debug, Clone)] diff --git a/crates/common/src/game_info.rs b/crates/common/src/game_info.rs index bade67e..bda96f4 100644 --- a/crates/common/src/game_info.rs +++ b/crates/common/src/game_info.rs @@ -16,8 +16,10 @@ use crate::constants::{ALLIUM_GAMES_DIR, ALLIUM_GAME_INFO, ALLIUM_SCRIPTS_DIR}; pub struct GameInfo { /// Display name of the game. pub name: String, - /// Path to the game rom. + /// Path to the game rom. This is used to generate the screenshot name. pub path: PathBuf, + /// Core used to run the game. This is used to generate the screenshot name. + pub core: String, /// Command to run the core. pub command: String, /// Arguments to pass to the core to run the game. @@ -39,6 +41,7 @@ impl Default for GameInfo { Self { name: String::new(), path: PathBuf::new(), + core: String::new(), command: String::new(), args: Vec::new(), has_menu: false, @@ -52,9 +55,11 @@ impl Default for GameInfo { impl GameInfo { /// Create a new GameInfo object. + #[allow(clippy::too_many_arguments)] pub fn new( name: String, path: PathBuf, + core: String, image: Option, command: String, args: Vec, @@ -66,6 +71,7 @@ impl GameInfo { Self { name, path, + core, command, args, has_menu,