mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Use more proper path for storing proxy config
This commit is contained in:
parent
b136fdc26c
commit
4f1096d8d6
3 changed files with 71 additions and 7 deletions
39
noita-proxy/Cargo.lock
generated
39
noita-proxy/Cargo.lock
generated
|
@ -1067,6 +1067,27 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
|
@ -2841,6 +2862,7 @@ dependencies = [
|
|||
"cpal",
|
||||
"crossbeam",
|
||||
"dashmap",
|
||||
"directories",
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
"eyre",
|
||||
|
@ -3339,6 +3361,12 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||
|
||||
[[package]]
|
||||
name = "opus"
|
||||
version = "0.3.0"
|
||||
|
@ -3816,6 +3844,17 @@ dependencies = [
|
|||
"bitflags 2.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
|
||||
dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
"libredox",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
|
|
|
@ -53,6 +53,7 @@ cpal = {version="0.15.3", features=["jack"]}
|
|||
rodio = "0.20.1"
|
||||
opus = "0.3.0"
|
||||
rubato = "0.16.1"
|
||||
directories = "6.0.0"
|
||||
#fundsp = {version = "0.20.0", default-features = false, features = ["std"]}
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -7,6 +7,7 @@ use bookkeeping::{
|
|||
};
|
||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||
use cpal::traits::{DeviceTrait, HostTrait};
|
||||
use directories::ProjectDirs;
|
||||
use eframe::egui::load::TexturePoll;
|
||||
use eframe::egui::{
|
||||
self, Align2, Button, Color32, ComboBox, Context, DragValue, FontDefinitions, FontFamily,
|
||||
|
@ -15,6 +16,7 @@ use eframe::egui::{
|
|||
Visuals, Window, pos2,
|
||||
};
|
||||
use eframe::epaint::TextureHandle;
|
||||
use eyre::{Context as _, OptionExt};
|
||||
use image::DynamicImage::ImageRgba8;
|
||||
use image::RgbaImage;
|
||||
use lang::{LANGS, set_current_locale, tr};
|
||||
|
@ -47,7 +49,7 @@ use std::{net::IpAddr, path::PathBuf};
|
|||
use steamworks::{LobbyId, SteamAPIInitError};
|
||||
use tangled::{Peer, Reliability};
|
||||
use tokio::time;
|
||||
use tracing::info;
|
||||
use tracing::{info, warn};
|
||||
use unic_langid::LanguageIdentifier;
|
||||
|
||||
mod util;
|
||||
|
@ -1362,17 +1364,40 @@ pub struct Settings {
|
|||
audio: AudioSettings,
|
||||
}
|
||||
|
||||
fn settings_path() -> eyre::Result<PathBuf> {
|
||||
let base_path = std::env::current_exe()
|
||||
.map(|p| p.parent().unwrap().to_path_buf())
|
||||
.unwrap_or(".".into());
|
||||
let config_name = "proxy.ron";
|
||||
let next_to_exe_path = base_path.join(config_name);
|
||||
if next_to_exe_path.exists() {
|
||||
info!("Using 'next to exe' path to store settings");
|
||||
Ok(next_to_exe_path)
|
||||
} else {
|
||||
info!("Using 'system' path to store settings");
|
||||
let project_dirs = ProjectDirs::from("", "quant", "entangledworlds")
|
||||
.ok_or_eyre("Failed to retrieve ProjectDirs")?;
|
||||
fs::create_dir_all(project_dirs.config_dir())
|
||||
.wrap_err("Failed to create config directory")?;
|
||||
let config_path = project_dirs.config_dir().join(config_name);
|
||||
info!("Config path: {}", config_path.display());
|
||||
Ok(config_path)
|
||||
}
|
||||
}
|
||||
|
||||
fn settings_get() -> Settings {
|
||||
if let Ok(s) = std::env::current_exe() {
|
||||
let file = s.parent().unwrap().join("proxy.ron");
|
||||
if let Ok(mut file) = File::open(file) {
|
||||
if let Ok(settings_path) = settings_path() {
|
||||
// info!("Settings path: {}", settings_path.display());
|
||||
if let Ok(mut file) = File::open(settings_path) {
|
||||
let mut s = String::new();
|
||||
let _ = file.read_to_string(&mut s);
|
||||
ron::from_str::<Settings>(&s).unwrap_or_default()
|
||||
} else {
|
||||
info!("Failed to load settings file, returing default settings");
|
||||
Settings::default()
|
||||
}
|
||||
} else {
|
||||
warn!("Failed to get settings file location, returing default settings");
|
||||
Settings::default()
|
||||
}
|
||||
}
|
||||
|
@ -1383,16 +1408,15 @@ fn settings_set(
|
|||
modmanager: ModmanagerSettings,
|
||||
audio: AudioSettings,
|
||||
) {
|
||||
if let Ok(s) = std::env::current_exe() {
|
||||
if let Ok(settings_path) = settings_path() {
|
||||
let settings = Settings {
|
||||
app,
|
||||
color,
|
||||
modmanager,
|
||||
audio,
|
||||
};
|
||||
let file = s.parent().unwrap().join("proxy.ron");
|
||||
let settings = ron::to_string(&settings).unwrap();
|
||||
if let Ok(mut file) = File::create(file) {
|
||||
if let Ok(mut file) = File::create(settings_path) {
|
||||
file.write_all(settings.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue