diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index 62c0829..af76da8 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -2,7 +2,7 @@ use std::{ collections::HashMap, fs::{self, create_dir_all}, path::PathBuf, - sync::LazyLock, + sync::{LazyLock, Mutex, RwLock}, }; use directories::BaseDirs; @@ -10,6 +10,8 @@ use rustbreak::{deser::Bincode, PathDatabase}; use serde::{Deserialize, Serialize}; use url::Url; +use crate::DB; + #[derive(serde::Serialize, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DatabaseAuth { @@ -42,8 +44,8 @@ pub struct Database { pub base_url: String, pub games: DatabaseGames, } -pub static DATA_ROOT_DIR: LazyLock = - LazyLock::new(|| BaseDirs::new().unwrap().data_dir().join("drop")); +pub static DATA_ROOT_DIR: LazyLock> = + LazyLock::new(|| Mutex::new(BaseDirs::new().unwrap().data_dir().join("drop"))); pub type DatabaseInterface = rustbreak::Database; @@ -55,10 +57,11 @@ pub trait DatabaseImpls { } impl DatabaseImpls for DatabaseInterface { fn set_up_database() -> DatabaseInterface { - let db_path = DATA_ROOT_DIR.join("drop.db"); - let games_base_dir = DATA_ROOT_DIR.join("games"); + let data_root_dir = DATA_ROOT_DIR.lock().unwrap(); + let db_path = data_root_dir.join("drop.db"); + let games_base_dir = data_root_dir.join("games"); - create_dir_all(DATA_ROOT_DIR.clone()).unwrap(); + create_dir_all(data_root_dir.clone()).unwrap(); create_dir_all(games_base_dir.clone()).unwrap(); let default = Database { @@ -87,3 +90,8 @@ impl DatabaseImpls for DatabaseInterface { Url::parse(&handle.base_url).unwrap() } } + +fn change_root_directory>(new_dir: T) { + let mut lock = DATA_ROOT_DIR.lock().unwrap(); + *lock = new_dir.into(); +} \ No newline at end of file diff --git a/src-tauri/src/downloads/download_agent.rs b/src-tauri/src/downloads/download_agent.rs index 59cf04b..e861dcd 100644 --- a/src-tauri/src/downloads/download_agent.rs +++ b/src-tauri/src/downloads/download_agent.rs @@ -151,7 +151,7 @@ impl GameDownloadAgent { game_id: String, ) -> Result<(), GameDownloadError> { let mut contexts = Vec::new(); - let base_path = DATA_ROOT_DIR.join("games").join(game_id.clone()).clone(); + let base_path = DATA_ROOT_DIR.lock().unwrap().join("games").join(game_id.clone()).clone(); create_dir_all(base_path.clone()).unwrap(); info!("Generating contexts"); for (raw_path, chunk) in manifest { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e8a9c2c..24a8837 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -146,7 +146,7 @@ pub fn run() { .min_inner_size(900.0, 900.0) .inner_size(1536.0, 864.0) .decorations(false) - .data_directory(DATA_ROOT_DIR.join(".webview")) + .data_directory(DATA_ROOT_DIR.lock().unwrap().join(".webview")) .build() .unwrap();