slight re factor ing
This commit is contained in:
parent
6eb5da9599
commit
c595a3d879
@ -34,21 +34,17 @@ impl AppThread {
|
|||||||
*state = s;
|
*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));
|
self.commit(UiState::KeyRequired(reason));
|
||||||
loop {
|
loop {
|
||||||
match self.ui_event_channel.recv()? {
|
match self.ui_event_channel.recv()? {
|
||||||
UiEvent::SetKey(key) => {
|
UiEvent::SetKey(key) => {
|
||||||
self.decryption_key = key;
|
self.commit(UiState::Loading);
|
||||||
break
|
return Ok(key);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.commit(UiState::Loading);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
|
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);
|
self.commit(UiState::Loading);
|
||||||
|
|
||||||
let mut config_provider = config::ConfigProvider::new()?;
|
let mut config_provider = config::ConfigProvider::new()?;
|
||||||
println!("{:?}", config_provider);
|
|
||||||
|
|
||||||
match omori_locator::get_omori_key() {
|
self.decryption_key = match config_provider.get_key() {
|
||||||
Ok(key) => self.decryption_key = key,
|
Some(key) => key,
|
||||||
Err(reason) => self.get_key(format!("{:?}", reason))?,
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ impl AppThread {
|
|||||||
pub fn main(&mut self) {
|
pub fn main(&mut self) {
|
||||||
match self.real_main() {
|
match self.real_main() {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => self.commit(UiState::Error(format!("{:?}", e))),
|
Err(e) => self.commit(UiState::Error(format!("{:#}", e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,22 @@ impl ConfigProvider {
|
|||||||
Ok(ConfigProvider { config, base_path })
|
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();
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ fn get_steam_root() -> anyhow::Result<PathBuf> {
|
|||||||
pub fn get_omori_path() -> anyhow::Result<PathBuf> {
|
pub fn get_omori_path() -> anyhow::Result<PathBuf> {
|
||||||
let mut base = get_steam_root()?;
|
let mut base = get_steam_root()?;
|
||||||
|
|
||||||
base.push("steamapps/libraryfolders.vdf");
|
base.push("steamapps");
|
||||||
|
base.push("libraryfolders.vdf");
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
|
|
||||||
@ -67,10 +68,23 @@ pub fn get_omori_path() -> anyhow::Result<PathBuf> {
|
|||||||
let mut base = PathBuf::from(path);
|
let mut base = PathBuf::from(path);
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[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")]
|
#[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);
|
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>> {
|
pub fn get_omori_key() -> anyhow::Result<Vec<u8>> {
|
||||||
let mut base: PathBuf = get_steam_root()?;
|
let mut base: PathBuf = get_steam_root()?;
|
||||||
|
|
||||||
base.push("appcache/appinfo.vdf");
|
base.push("appcache");
|
||||||
|
base.push("appinfo.vdf");
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user