game picker
This commit is contained in:
@@ -2,7 +2,7 @@ use std::{f32::consts::E, path::PathBuf, sync::Arc, thread, time::Duration};
|
||||
|
||||
use crossbeam_channel::Receiver;
|
||||
use egui::{mutex::Mutex};
|
||||
use log::debug;
|
||||
use log::{debug, info};
|
||||
|
||||
use crate::{config::{self, ConfigProvider}, omori_locator};
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{config::{self, ConfigProvider}, omori_locator};
|
||||
pub enum UiState {
|
||||
Loading,
|
||||
KeyRequired(String),
|
||||
PickGame(Result<PathBuf, String>, Vec<PathBuf>),
|
||||
PickGame(Result<PathBuf, String>, Vec<(PathBuf, u64)>),
|
||||
Error(String)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ pub struct UiStateHolder {
|
||||
}
|
||||
|
||||
pub enum UiEvent {
|
||||
SetKey(Vec<u8>)
|
||||
SetKey(Vec<u8>),
|
||||
UsePath(PathBuf),
|
||||
UseSteamPath
|
||||
}
|
||||
|
||||
pub struct AppThread {
|
||||
@@ -49,7 +51,7 @@ impl AppThread {
|
||||
}
|
||||
}
|
||||
|
||||
fn pick_game(&mut self, provider: &ConfigProvider) -> anyhow::Result<()> {
|
||||
fn pick_game(&mut self, provider: &mut ConfigProvider) -> anyhow::Result<PathBuf> {
|
||||
let steam_location = match omori_locator::get_omori_path() {
|
||||
Ok(l) => Ok(l),
|
||||
Err(e) => Err(String::from(format!("{:#}", e)))
|
||||
@@ -59,7 +61,20 @@ impl AppThread {
|
||||
|
||||
self.commit(UiState::PickGame(steam_location.clone(), location_history.clone()));
|
||||
|
||||
Ok(())
|
||||
loop {
|
||||
match self.ui_event_channel.recv()? {
|
||||
UiEvent::UsePath(path) => {
|
||||
provider.set_game_path_used(&path)?;
|
||||
self.commit(UiState::Loading);
|
||||
return Ok(path);
|
||||
},
|
||||
UiEvent::UseSteamPath => {
|
||||
self.commit(UiState::Loading);
|
||||
return Ok(steam_location.expect("The steam location was not set even if the UI told us to use it. This should never happen"));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
|
||||
@@ -87,7 +102,8 @@ impl AppThread {
|
||||
|
||||
config_provider.set_key(&self.decryption_key)?;
|
||||
|
||||
self.pick_game(&config_provider);
|
||||
let game_path = self.pick_game(&mut config_provider)?;
|
||||
info!("Will use {:?}", game_path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user