latest
This commit is contained in:
parent
772f1c634c
commit
6eb5da9599
@ -3,12 +3,13 @@ use std::{sync::Arc, thread, time::Duration};
|
|||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
use egui::{mutex::Mutex};
|
use egui::{mutex::Mutex};
|
||||||
|
|
||||||
use crate::omori_locator;
|
use crate::{config, omori_locator};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum UiState {
|
pub enum UiState {
|
||||||
Loading,
|
Loading,
|
||||||
KeyRequired(String)
|
KeyRequired(String),
|
||||||
|
Error(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -33,10 +34,10 @@ impl AppThread {
|
|||||||
*state = s;
|
*state = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_key(&mut self, reason: String) {
|
fn get_key(&mut self, reason: String) -> anyhow::Result<()> {
|
||||||
self.commit(UiState::KeyRequired(reason));
|
self.commit(UiState::KeyRequired(reason));
|
||||||
loop {
|
loop {
|
||||||
match self.ui_event_channel.recv().expect("The UI event channel was closed.") {
|
match self.ui_event_channel.recv()? {
|
||||||
UiEvent::SetKey(key) => {
|
UiEvent::SetKey(key) => {
|
||||||
self.decryption_key = key;
|
self.decryption_key = key;
|
||||||
break
|
break
|
||||||
@ -46,6 +47,8 @@ impl AppThread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.commit(UiState::Loading);
|
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 {
|
||||||
@ -57,14 +60,24 @@ impl AppThread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(&mut self) {
|
fn real_main(&mut self) -> anyhow::Result<()> {
|
||||||
self.commit(UiState::Loading);
|
self.commit(UiState::Loading);
|
||||||
|
|
||||||
|
let mut config_provider = config::ConfigProvider::new()?;
|
||||||
|
println!("{:?}", config_provider);
|
||||||
|
|
||||||
match omori_locator::get_omori_key() {
|
match omori_locator::get_omori_key() {
|
||||||
Ok(key) => self.decryption_key = key,
|
Ok(key) => self.decryption_key = key,
|
||||||
Err(reason) => self.get_key(format!("{:?}", reason)),
|
Err(reason) => self.get_key(format!("{:?}", reason))?,
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{:?}", self.decryption_key);
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(&mut self) {
|
||||||
|
match self.real_main() {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => self.commit(UiState::Error(format!("{:?}", e))),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
use std::{fs::{self, File}, path::PathBuf};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
use serde::{de, Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct Config {
|
struct Config {
|
||||||
key: Option<Vec<u8>>
|
key: Option<Vec<u8>>
|
||||||
}
|
}
|
||||||
@ -7,3 +13,36 @@ impl Default for Config {
|
|||||||
Self { key: Default::default() }
|
Self { key: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ConfigProvider {
|
||||||
|
config: Config,
|
||||||
|
base_path: PathBuf
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConfigProvider {
|
||||||
|
pub fn new() -> anyhow::Result<ConfigProvider> {
|
||||||
|
let mut base_path = dirs::preference_dir().with_context(|| "Failed to find your preference directory")?;
|
||||||
|
base_path.push(env!("CARGO_PKG_NAME"));
|
||||||
|
|
||||||
|
fs::create_dir_all(&base_path)?;
|
||||||
|
|
||||||
|
base_path.push("config.json");
|
||||||
|
|
||||||
|
if !fs::exists(&base_path)? {
|
||||||
|
let mut fd = File::create(&base_path)?;
|
||||||
|
serde_json::to_writer(&mut fd, &Config::default())?;
|
||||||
|
drop(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut fd = File::open(&base_path)?;
|
||||||
|
let config: Config = serde_json::from_reader(&mut fd)?;
|
||||||
|
drop(fd);
|
||||||
|
|
||||||
|
Ok(ConfigProvider { config, base_path })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_key(&self) -> Option<Vec<u8>> {
|
||||||
|
return self.config.key.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
13
src/main.rs
13
src/main.rs
@ -74,6 +74,19 @@ impl eframe::App for Application {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
UiState::Error(reason) => {
|
||||||
|
egui::TopBottomPanel::top("error_title_bar").show(ctx, |ui| {
|
||||||
|
ui.with_layout(Layout::top_down(Align::Center), |ui| {
|
||||||
|
ui.label(RichText::new("An error has occured :(").size(32.0));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
center_vertical(ui,|ui| {
|
||||||
|
ui.label(RichText::new(reason).size(32.0));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
UiState::KeyRequired(reason) => {
|
UiState::KeyRequired(reason) => {
|
||||||
let mut is_valid = true;
|
let mut is_valid = true;
|
||||||
let hash = sha2::Sha256::digest(&self.key_input.as_bytes());
|
let hash = sha2::Sha256::digest(&self.key_input.as_bytes());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user