rework storage paths a bit

This commit is contained in:
2025-05-13 09:40:45 +01:00
parent ef0b6de6ba
commit 9dbfbc4419
4 changed files with 16 additions and 17 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ use crate::{
ui_ext::UiExt, ui_ext::UiExt,
}, },
util::consts::{ util::consts::{
APP_STORAGE_PATH,
game::{EXE_ENHANCED, EXE_LEGACY}, game::{EXE_ENHANCED, EXE_LEGACY},
path,
}, },
}; };
use eframe::egui; use eframe::egui;
@@ -15,7 +15,7 @@ impl App {
fn add_debug_viewport_contents(&mut self, ui: &mut egui::Ui) { fn add_debug_viewport_contents(&mut self, ui: &mut egui::Ui) {
ui.collapsing("misc", |ui| { ui.collapsing("misc", |ui| {
if ui.button("open storage path").clicked() { if ui.button("open storage path").clicked() {
open::that_detached(APP_STORAGE_PATH.as_path()).unwrap(); open::that_detached(path::APP_STORAGE.as_path()).unwrap();
} }
ui.checkbox( ui.checkbox(
&mut self.meta.newer_version_available, &mut self.meta.newer_version_available,
+2 -3
View File
@@ -3,7 +3,7 @@ use crate::{
app::{App, WINDOW_SIZE}, app::{App, WINDOW_SIZE},
tools, tools,
}, },
util::{consts::APP_STORAGE_PATH, persistent_state::PersistentState, win}, util::{consts::path, persistent_state::PersistentState, win},
}; };
use eframe::egui; use eframe::egui;
use std::{ use std::{
@@ -13,11 +13,10 @@ use std::{
}; };
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) { fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
let log_path = APP_STORAGE_PATH.join("panic.log");
let mut file = File::options() let mut file = File::options()
.create(true) .create(true)
.append(true) .append(true)
.open(log_path) .open(path::APP_ERROR.as_path())
.unwrap(); .unwrap();
let timestamp = SystemTime::now() let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
+9 -5
View File
@@ -1,8 +1,12 @@
use std::{env, path::PathBuf, sync::LazyLock}; pub mod path {
use std::{env, path::PathBuf, sync::LazyLock};
pub static APP_STORAGE_PATH: LazyLock<PathBuf> = LazyLock::new(|| { pub static APP_STORAGE: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(env::var("LOCALAPPDATA").unwrap_or_else(|_| String::from("."))).join("GTA Tools") PathBuf::from(env::var("LOCALAPPDATA").unwrap_or_else(|_| String::from(".")))
}); .join("GTA Tools")
});
pub static APP_CONFIG: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("config.json"));
pub static APP_ERROR: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("error.log"));
}
pub mod game { pub mod game {
pub const EXE_ENHANCED: &str = "GTA5_Enhanced.exe"; pub const EXE_ENHANCED: &str = "GTA5_Enhanced.exe";
+3 -7
View File
@@ -1,14 +1,10 @@
use crate::{features::launch::Platform, gui::settings::Settings, util::consts::APP_STORAGE_PATH}; use crate::{features::launch::Platform, gui::settings::Settings, util::consts::path};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
fs::{self, File}, fs::{self, File},
io::Write, io::Write,
path::PathBuf,
sync::LazyLock,
}; };
static CONFIG_PATH: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE_PATH.join("config.json"));
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct PersistentState { pub struct PersistentState {
pub launcher: Platform, pub launcher: Platform,
@@ -17,13 +13,13 @@ pub struct PersistentState {
impl PersistentState { impl PersistentState {
pub fn get() -> Option<Self> { pub fn get() -> Option<Self> {
fs::read_to_string(CONFIG_PATH.as_path()) fs::read_to_string(path::APP_CONFIG.as_path())
.ok() .ok()
.and_then(|config| serde_json::from_str::<Self>(&config).ok()) .and_then(|config| serde_json::from_str::<Self>(&config).ok())
} }
pub fn set(&self) { pub fn set(&self) {
let config_path = CONFIG_PATH.as_path(); let config_path = path::APP_CONFIG.as_path();
let config_path_parent = config_path.parent().unwrap(); let config_path_parent = config_path.parent().unwrap();
if !config_path_parent.exists() { if !config_path_parent.exists() {
fs::create_dir(config_path_parent).unwrap(); fs::create_dir(config_path_parent).unwrap();