mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Use config folder (#110)
This commit is contained in:
@@ -3,3 +3,5 @@ auth_key.txt
|
|||||||
cache.json
|
cache.json
|
||||||
config.toml
|
config.toml
|
||||||
.thumbnails
|
.thumbnails
|
||||||
|
thumbnails
|
||||||
|
.flatpak-builder
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
use std::{
|
||||||
|
fs::create_dir_all,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
pub fn get_config_folder() -> PathBuf {
|
||||||
|
let config_home = std::env::var("XDG_CONFIG_HOME");
|
||||||
|
let home = std::env::var("HOME");
|
||||||
|
match (config_home, home) {
|
||||||
|
(Ok(p), _) => Path::new(&p).to_path_buf(),
|
||||||
|
(Err(_), Ok(home)) => Path::new(&home).join(".config").join("boilr").to_path_buf(),
|
||||||
|
_ => Path::new("").to_path_buf(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn get_config_folder() -> PathBuf {
|
||||||
|
let config_home = std::env::var("APPDATA");
|
||||||
|
match config_home {
|
||||||
|
Ok(p) => Path::new(&p).join("boilr").to_path_buf(),
|
||||||
|
Err(_) => Path::new("").to_path_buf(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_thumbnails_folder() -> PathBuf {
|
||||||
|
let thumbnails_path = get_config_folder().join("thumbnails");
|
||||||
|
let _ = create_dir_all(&thumbnails_path);
|
||||||
|
thumbnails_path.to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_config_file() -> PathBuf {
|
||||||
|
get_config_folder().join("config.toml").to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_cache_file() -> PathBuf {
|
||||||
|
get_config_folder().join("cache.json").to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
pub fn get_boilr_links_path() -> PathBuf {
|
||||||
|
get_config_folder().join("links").to_path_buf()
|
||||||
|
}
|
||||||
+10
@@ -1,10 +1,12 @@
|
|||||||
mod amazon;
|
mod amazon;
|
||||||
|
mod config;
|
||||||
mod egs;
|
mod egs;
|
||||||
mod gog;
|
mod gog;
|
||||||
mod heroic;
|
mod heroic;
|
||||||
mod itch;
|
mod itch;
|
||||||
mod legendary;
|
mod legendary;
|
||||||
mod lutris;
|
mod lutris;
|
||||||
|
mod migration;
|
||||||
mod origin;
|
mod origin;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod settings;
|
mod settings;
|
||||||
@@ -16,6 +18,9 @@ mod uplay;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
ensure_config_folder();
|
||||||
|
migration::migrate_config();
|
||||||
|
|
||||||
let mut args = std::env::args();
|
let mut args = std::env::args();
|
||||||
if args.len() > 1 && args.nth(1).unwrap_or_default() == "--no-ui" {
|
if args.len() > 1 && args.nth(1).unwrap_or_default() == "--no-ui" {
|
||||||
ui::run_sync();
|
ui::run_sync();
|
||||||
@@ -24,3 +29,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
ui::run_ui()
|
ui::run_ui()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensure_config_folder() {
|
||||||
|
let path = config::get_config_folder();
|
||||||
|
let _ = std::fs::create_dir_all(&path);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn migrate_config() {
|
||||||
|
let version = &crate::settings::Settings::new()
|
||||||
|
.map(|s| s.config_version)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let mut save_version = false;
|
||||||
|
if version.is_none() {
|
||||||
|
//Migration from 0 to 1
|
||||||
|
let old_path = &Path::new("config.toml");
|
||||||
|
if old_path.exists() {
|
||||||
|
println!("Migrating from configuration version 0 to version 1");
|
||||||
|
let new_path = crate::config::get_config_file();
|
||||||
|
println!("Your configuration file will be moved to {:?}", new_path);
|
||||||
|
let _ = std::fs::copy(old_path, new_path);
|
||||||
|
let _ = std::fs::remove_file(old_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let old_path = &Path::new(".thumbnails");
|
||||||
|
if old_path.exists() {
|
||||||
|
//thumbnails are just cache can be removed
|
||||||
|
let _ = std::fs::remove_dir_all(old_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let old_path = &Path::new("cache.json");
|
||||||
|
if old_path.exists() {
|
||||||
|
let new_path = crate::config::get_cache_file();
|
||||||
|
let _ = std::fs::copy(old_path, new_path);
|
||||||
|
let _ = std::fs::remove_file(old_path);
|
||||||
|
}
|
||||||
|
save_version = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if save_version {
|
||||||
|
if let Ok(mut settings) = crate::settings::Settings::new() {
|
||||||
|
settings.config_version = Some(1);
|
||||||
|
crate::ui::MyEguiApp::save_settings_to_file(&settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-4
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
amazon::AmazonSettings, egs::EpicGamesLauncherSettings, gog::GogSettings,
|
amazon::AmazonSettings, config::get_config_file, egs::EpicGamesLauncherSettings,
|
||||||
heroic::HeroicSettings, itch::ItchSettings, legendary::LegendarySettings,
|
gog::GogSettings, heroic::HeroicSettings, itch::ItchSettings, legendary::LegendarySettings,
|
||||||
lutris::settings::LutrisSettings, origin::OriginSettings, steam::SteamSettings,
|
lutris::settings::LutrisSettings, origin::OriginSettings, steam::SteamSettings,
|
||||||
steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
|
steamgriddb::SteamGridDbSettings, uplay::UplaySettings,
|
||||||
};
|
};
|
||||||
@@ -12,6 +12,7 @@ use std::env;
|
|||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
|
pub config_version: Option<usize>,
|
||||||
pub blacklisted_games: Vec<u32>,
|
pub blacklisted_games: Vec<u32>,
|
||||||
pub epic_games: EpicGamesLauncherSettings,
|
pub epic_games: EpicGamesLauncherSettings,
|
||||||
pub legendary: LegendarySettings,
|
pub legendary: LegendarySettings,
|
||||||
@@ -33,8 +34,11 @@ impl Settings {
|
|||||||
let default_str = include_str!("defaultconfig.toml");
|
let default_str = include_str!("defaultconfig.toml");
|
||||||
s.merge(File::from_str(default_str, config::FileFormat::Toml))?;
|
s.merge(File::from_str(default_str, config::FileFormat::Toml))?;
|
||||||
|
|
||||||
|
let config_file = get_config_file();
|
||||||
|
let config_file = config_file.to_string_lossy();
|
||||||
|
|
||||||
// Start off by merging in the "default" configuration file
|
// Start off by merging in the "default" configuration file
|
||||||
s.merge(File::with_name("config.toml").required(false))?;
|
s.merge(File::with_name(config_file.as_ref()).required(false))?;
|
||||||
|
|
||||||
// Add in the current environment file
|
// Add in the current environment file
|
||||||
// Default to 'development' env
|
// Default to 'development' env
|
||||||
@@ -48,7 +52,7 @@ impl Settings {
|
|||||||
|
|
||||||
// Add in settings from the environment (with a prefix of STEAMSYNC)
|
// Add in settings from the environment (with a prefix of STEAMSYNC)
|
||||||
// Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key
|
// Eg.. `STEAMSYNC_DEBUG=1 ./target/app` would set the `debug` key
|
||||||
s.merge(Environment::with_prefix("steamsync").separator("-"))?;
|
s.merge(Environment::with_prefix("boilr").separator("-"))?;
|
||||||
|
|
||||||
let mut result: Result<Self, ConfigError> = s.try_into();
|
let mut result: Result<Self, ConfigError> = s.try_into();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use std::{fs::File, io::Write, path::Path};
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
|
use crate::config::get_cache_file;
|
||||||
|
|
||||||
type SearchMap = DashMap<u32, (String, usize)>;
|
type SearchMap = DashMap<u32, (String, usize)>;
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ impl<'a> CachedSearch<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_search_map() -> SearchMap {
|
fn get_search_map() -> SearchMap {
|
||||||
let path = Path::new("cache.json");
|
let path = get_cache_file();
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
let string = std::fs::read_to_string(path).unwrap();
|
let string = std::fs::read_to_string(path).unwrap();
|
||||||
serde_json::from_str::<SearchMap>(&string).expect("Failed to parse cache.json")
|
serde_json::from_str::<SearchMap>(&string).expect("Failed to parse cache.json")
|
||||||
@@ -65,6 +67,7 @@ fn get_search_map() -> SearchMap {
|
|||||||
|
|
||||||
fn save_search_map(search_map: &SearchMap) {
|
fn save_search_map(search_map: &SearchMap) {
|
||||||
let string = serde_json::to_string(search_map).unwrap();
|
let string = serde_json::to_string(search_map).unwrap();
|
||||||
let mut file = File::create("cache.json").unwrap();
|
let path = get_cache_file();
|
||||||
|
let mut file = File::create(&path).unwrap();
|
||||||
file.write_all(string.as_bytes()).unwrap();
|
file.write_all(string.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
||||||
|
|
||||||
fn get_boilr_links_path() -> std::path::PathBuf {
|
use crate::config::get_boilr_links_path;
|
||||||
let home = std::env::var("HOME").expect("Expected a home variable to be defined");
|
|
||||||
let boilr_links_path = Path::new(&home).join(".boilr").join("links");
|
|
||||||
boilr_links_path
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned {
|
pub fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned {
|
||||||
let links_folder = get_boilr_links_path();
|
let links_folder = get_boilr_links_path();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::get_thumbnails_folder,
|
||||||
steam::{get_shortcuts_paths, SteamUsersInfo},
|
steam::{get_shortcuts_paths, SteamUsersInfo},
|
||||||
steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload},
|
steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload},
|
||||||
};
|
};
|
||||||
@@ -399,8 +400,6 @@ impl MyEguiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_image_type_selected(&mut self, image_type: ImageType) {
|
fn handle_image_type_selected(&mut self, image_type: ImageType) {
|
||||||
let _ = std::fs::create_dir_all(".thumbnails");
|
|
||||||
|
|
||||||
let state = &mut self.image_selected_state;
|
let state = &mut self.image_selected_state;
|
||||||
state.image_type_selected = Some(image_type);
|
state.image_type_selected = Some(image_type);
|
||||||
let (tx, rx) = watch::channel(FetcStatus::Fetching);
|
let (tx, rx) = watch::channel(FetcStatus::Fetching);
|
||||||
@@ -411,7 +410,7 @@ impl MyEguiApp {
|
|||||||
let auth_key = auth_key;
|
let auth_key = auth_key;
|
||||||
let image_type = image_type;
|
let image_type = image_type;
|
||||||
self.rt.spawn_blocking(move || {
|
self.rt.spawn_blocking(move || {
|
||||||
let thumbnails_folder = Path::new(".thumbnails");
|
let thumbnails_folder = get_thumbnails_folder();
|
||||||
let client = steamgriddb_api::Client::new(auth_key);
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
let query = get_query_type(false, &image_type);
|
let query = get_query_type(false, &image_type);
|
||||||
let search_res = block_on(client.get_images_for_id(grid_id, &query));
|
let search_res = block_on(client.get_images_for_id(grid_id, &query));
|
||||||
|
|||||||
@@ -127,8 +127,9 @@ impl MyEguiApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_settings_to_file(settings: &Settings) {
|
pub fn save_settings_to_file(settings: &Settings) {
|
||||||
let toml = toml::to_string(&settings).unwrap();
|
let toml = toml::to_string(&settings).unwrap();
|
||||||
std::fs::write("config.toml", toml).unwrap();
|
let config_path = crate::config::get_config_file();
|
||||||
|
std::fs::write(config_path, toml).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user