diff --git a/src/app_logic.rs b/src/app_logic.rs index ad65d33..34dc46d 100644 --- a/src/app_logic.rs +++ b/src/app_logic.rs @@ -34,21 +34,17 @@ impl AppThread { *state = s; } - fn get_key(&mut self, reason: String) -> anyhow::Result<()> { + fn get_key(&mut self, reason: String) -> anyhow::Result> { self.commit(UiState::KeyRequired(reason)); loop { match self.ui_event_channel.recv()? { UiEvent::SetKey(key) => { - self.decryption_key = key; - break + self.commit(UiState::Loading); + return Ok(key); } _ => {} } } - - self.commit(UiState::Loading); - - Ok(()) } pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver) -> AppThread { @@ -64,12 +60,16 @@ impl AppThread { self.commit(UiState::Loading); let mut config_provider = config::ConfigProvider::new()?; - println!("{:?}", config_provider); - - match omori_locator::get_omori_key() { - Ok(key) => self.decryption_key = key, - Err(reason) => self.get_key(format!("{:?}", reason))?, - } + + self.decryption_key = match config_provider.get_key() { + Some(key) => key, + None => match omori_locator::get_omori_key() { + Ok(key) => key, + Err(reason) => self.get_key(format!("{:#}", reason))?, + } + }; + + config_provider.set_key(&self.decryption_key)?; Ok(()) } @@ -77,7 +77,7 @@ impl AppThread { pub fn main(&mut self) { match self.real_main() { Ok(_) => {}, - Err(e) => self.commit(UiState::Error(format!("{:?}", e))), + Err(e) => self.commit(UiState::Error(format!("{:#}", e))), } } } diff --git a/src/config.rs b/src/config.rs index bb30304..36cd730 100644 --- a/src/config.rs +++ b/src/config.rs @@ -42,7 +42,22 @@ impl ConfigProvider { Ok(ConfigProvider { config, base_path }) } - fn get_key(&self) -> Option> { + fn commit(&mut self) -> anyhow::Result<()> { + let mut fd = File::create(&self.base_path)?; + serde_json::to_writer(&mut fd, &self.config)?; + drop(fd); + + Ok(()) + } + + pub fn get_key(&self) -> Option> { return self.config.key.clone(); } + + pub fn set_key(&mut self, key: &Vec) -> anyhow::Result<()> { + self.config.key = Some(key.clone()); + self.commit()?; + + Ok(()) + } } diff --git a/src/omori_locator.rs b/src/omori_locator.rs index f794bb2..b69d56d 100644 --- a/src/omori_locator.rs +++ b/src/omori_locator.rs @@ -35,7 +35,8 @@ fn get_steam_root() -> anyhow::Result { pub fn get_omori_path() -> anyhow::Result { let mut base = get_steam_root()?; - base.push("steamapps/libraryfolders.vdf"); + base.push("steamapps"); + base.push("libraryfolders.vdf"); let mut buffer = Vec::new(); @@ -67,11 +68,24 @@ pub fn get_omori_path() -> anyhow::Result { let mut base = PathBuf::from(path); #[cfg(not(target_os = "macos"))] - base.push("steamapps/common/OMORI/www"); + { + base.push("steamapps"); + base.push("common"); + base.push("OMORI"); + base.push("www"); + } #[cfg(target_os = "macos")] - base.push("steamapps/common/OMORI/OMORI.app/Contents/Resources/app.nw"); - + { + base.push("steamapps"); + base.push("common"); + base.push("OMORI"); + base.push("OMORI.app"); + base.push("Contents"); + base.push("Resources"); + base.push("app.nw"); + } + omori_path = Some(base); } } @@ -85,7 +99,8 @@ const GAME_KEY_HASH: &[u8; 32] = include_bytes!("keyhash"); pub fn get_omori_key() -> anyhow::Result> { let mut base: PathBuf = get_steam_root()?; - base.push("appcache/appinfo.vdf"); + base.push("appcache"); + base.push("appinfo.vdf"); let mut buffer = Vec::new();