slight re factor ing

This commit is contained in:
Rph :3 2025-04-16 18:44:53 +02:00
parent 6eb5da9599
commit c595a3d879
No known key found for this signature in database
3 changed files with 50 additions and 20 deletions

View File

@ -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<Vec<u8>> {
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<UiEvent>) -> 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))),
}
}
}

View File

@ -42,7 +42,22 @@ impl ConfigProvider {
Ok(ConfigProvider { config, base_path })
}
fn get_key(&self) -> Option<Vec<u8>> {
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<Vec<u8>> {
return self.config.key.clone();
}
pub fn set_key(&mut self, key: &Vec<u8>) -> anyhow::Result<()> {
self.config.key = Some(key.clone());
self.commit()?;
Ok(())
}
}

View File

@ -35,7 +35,8 @@ fn get_steam_root() -> anyhow::Result<PathBuf> {
pub fn get_omori_path() -> anyhow::Result<PathBuf> {
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<PathBuf> {
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<Vec<u8>> {
let mut base: PathBuf = get_steam_root()?;
base.push("appcache/appinfo.vdf");
base.push("appcache");
base.push("appinfo.vdf");
let mut buffer = Vec::new();