diff --git a/Cargo.lock b/Cargo.lock index 9acec53..28a7fb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -821,6 +821,7 @@ version = "0.1.0" dependencies = [ "database", "dirs 6.0.0", + "drop-consts", "log", "regex", "rustix 1.1.2", @@ -1091,6 +1092,7 @@ version = "0.1.0" dependencies = [ "chrono", "dirs 6.0.0", + "drop-consts", "log", "native_model", "rustbreak", @@ -1376,6 +1378,7 @@ dependencies = [ "deranged 0.4.0", "dirs 6.0.0", "download_manager", + "drop-consts", "droplet-rs", "dynfmt", "filetime", @@ -1438,6 +1441,13 @@ dependencies = [ "zstd", ] +[[package]] +name = "drop-consts" +version = "0.1.0" +dependencies = [ + "dirs 6.0.0", +] + [[package]] name = "droplet-rs" version = "0.7.3" @@ -1865,6 +1875,7 @@ dependencies = [ "boxcar", "database", "download_manager", + "drop-consts", "hex 0.4.3", "log", "md5 0.8.0", @@ -4281,6 +4292,7 @@ dependencies = [ "chrono", "client", "database", + "drop-consts", "dynfmt", "games", "log", @@ -4640,6 +4652,7 @@ dependencies = [ "chrono", "client", "database", + "drop-consts", "droplet-rs", "gethostname", "hex 0.4.3", diff --git a/Cargo.toml b/Cargo.toml index 0159adc..c3c5011 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ "utils", "cloud_saves", "download_manager", - "games", + "games", "drop-consts", ] resolver = "3" diff --git a/client/src/compat.rs b/client/src/compat.rs index 0bd04b6..5906152 100644 --- a/client/src/compat.rs +++ b/client/src/compat.rs @@ -1,15 +1,12 @@ use std::{ - ffi::OsStr, - path::PathBuf, - process::{Command, Stdio}, - sync::LazyLock, + cell::LazyCell, ffi::OsStr, path::PathBuf, process::{Command, Stdio} }; use log::info; -pub static COMPAT_INFO: LazyLock> = LazyLock::new(create_new_compat_info); +pub const COMPAT_INFO: LazyCell> = LazyCell::new(create_new_compat_info); -pub static UMU_LAUNCHER_EXECUTABLE: LazyLock> = LazyLock::new(|| { +pub const UMU_LAUNCHER_EXECUTABLE: LazyCell> = LazyCell::new(|| { let x = get_umu_executable(); info!("{:?}", &x); x diff --git a/cloud_saves/Cargo.toml b/cloud_saves/Cargo.toml index 806d1b0..f7e98b6 100644 --- a/cloud_saves/Cargo.toml +++ b/cloud_saves/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] database = { version = "0.1.0", path = "../database" } dirs = "6.0.0" +drop-consts = { version = "0.1.0", path = "../drop-consts" } log = "0.4.28" regex = "1.11.3" rustix = "1.1.2" diff --git a/cloud_saves/src/backup_manager.rs b/cloud_saves/src/backup_manager.rs index db8e9f2..83209ed 100644 --- a/cloud_saves/src/backup_manager.rs +++ b/cloud_saves/src/backup_manager.rs @@ -2,7 +2,8 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr}; #[cfg(target_os = "linux")] use database::platform::Platform; -use database::{GameVersion, db::DATA_ROOT_DIR}; +use database::GameVersion; +use drop_consts::DATA_ROOT_DIR; use log::warn; use crate::error::BackupError; diff --git a/database/Cargo.toml b/database/Cargo.toml index 9fbb499..fe0c1ab 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] chrono = "0.4.42" dirs = "6.0.0" +drop-consts = { version = "0.1.0", path = "../drop-consts" } log = "0.4.28" native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"} rustbreak = "2.0.0" diff --git a/database/src/db.rs b/database/src/db.rs index 313eb80..a537ed5 100644 --- a/database/src/db.rs +++ b/database/src/db.rs @@ -1,6 +1,5 @@ use std::{ - path::PathBuf, - sync::{Arc, LazyLock}, + sync::LazyLock, }; use rustbreak::{DeSerError, DeSerializer}; @@ -10,19 +9,6 @@ use crate::interface::{DatabaseImpls, DatabaseInterface}; pub static DB: LazyLock = LazyLock::new(DatabaseInterface::set_up_database); -#[cfg(not(debug_assertions))] -static DATA_ROOT_PREFIX: &str = "drop"; -#[cfg(debug_assertions)] -static DATA_ROOT_PREFIX: &str = "drop-debug"; - -pub static DATA_ROOT_DIR: LazyLock> = LazyLock::new(|| { - Arc::new( - dirs::data_dir() - .expect("Failed to get data dir") - .join(DATA_ROOT_PREFIX), - ) -}); - // Custom JSON serializer to support everything we need #[derive(Debug, Default, Clone)] pub struct DropDatabaseSerializer; @@ -39,7 +25,7 @@ impl DeSerializer s.read_to_end(&mut buf) .map_err(|e| rustbreak::error::DeSerError::Other(e.into()))?; let (val, _version) = - native_model::decode(buf).map_err(|e| DeSerError::Internal(e.to_string()))?; + native_model::decode(buf).map_err(|e| rustbreak::error::DeSerError::Internal(e.to_string()))?; Ok(val) } } diff --git a/database/src/interface.rs b/database/src/interface.rs index 969c93d..8ffa8ee 100644 --- a/database/src/interface.rs +++ b/database/src/interface.rs @@ -7,12 +7,13 @@ use std::{ }; use chrono::Utc; +use drop_consts::DATA_ROOT_DIR; use log::{debug, error, info, warn}; use rustbreak::{PathDatabase, RustbreakError}; use url::Url; use crate::{ - db::{DATA_ROOT_DIR, DB, DropDatabaseSerializer}, + db::{DB, DropDatabaseSerializer}, models::data::Database, }; diff --git a/drop-consts/Cargo.toml b/drop-consts/Cargo.toml new file mode 100644 index 0000000..3485b2c --- /dev/null +++ b/drop-consts/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "drop-consts" +version = "0.1.0" +edition = "2024" + +[dependencies] +dirs = "6.0.0" diff --git a/drop-consts/src/lib.rs b/drop-consts/src/lib.rs new file mode 100644 index 0000000..41856ab --- /dev/null +++ b/drop-consts/src/lib.rs @@ -0,0 +1,23 @@ +use std::{cell::LazyCell, path::PathBuf}; + +#[cfg(not(debug_assertions))] +pub const DATA_ROOT_PREFIX: &str = "drop"; +#[cfg(debug_assertions)] +pub const DATA_ROOT_PREFIX: &str = "drop-debug"; + +pub const DATA_ROOT_DIR: LazyCell = LazyCell::new(|| { + dirs::data_dir() + .expect("Failed to get data dir") + .join(DATA_ROOT_PREFIX) +}); + +pub const DROP_DATA_PATH: &str = ".dropdata"; + +// Downloads +pub const MAX_PACKET_LENGTH: usize = 4096 * 4; +pub const BUMP_SIZE: usize = 4096 * 16; + +pub const RETRY_COUNT: usize = 3; + +pub const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000; +pub const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1; diff --git a/games/Cargo.toml b/games/Cargo.toml index c50507b..86a5dad 100644 --- a/games/Cargo.toml +++ b/games/Cargo.toml @@ -24,3 +24,4 @@ throttle_my_fn = "0.2.6" utils = { version = "0.1.0", path = "../utils" } native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"} serde_json = "1.0.145" +drop-consts = { version = "0.1.0", path = "../drop-consts" } diff --git a/games/src/downloads/download_agent.rs b/games/src/downloads/download_agent.rs index 1d54ca0..e6da73a 100644 --- a/games/src/downloads/download_agent.rs +++ b/games/src/downloads/download_agent.rs @@ -9,6 +9,7 @@ use download_manager::util::download_thread_control_flag::{ DownloadThreadControl, DownloadThreadControlFlag, }; use download_manager::util::progress_object::{ProgressHandle, ProgressObject}; +use drop_consts::{MAX_FILES_PER_BUCKET, RETRY_COUNT, TARGET_BUCKET_SIZE}; use log::{debug, error, info, warn}; use rayon::ThreadPoolBuilder; use remote::auth::generate_authorization_header; @@ -39,11 +40,6 @@ use crate::state::GameStatusManager; use super::download_logic::download_game_bucket; use super::drop_data::DropData; -static RETRY_COUNT: usize = 3; - -const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000; -const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1; - pub struct GameDownloadAgent { pub id: String, pub version: String, diff --git a/games/src/downloads/download_logic.rs b/games/src/downloads/download_logic.rs index 2b40ac7..3d394ae 100644 --- a/games/src/downloads/download_logic.rs +++ b/games/src/downloads/download_logic.rs @@ -15,6 +15,7 @@ use download_manager::util::download_thread_control_flag::{ DownloadThreadControl, DownloadThreadControlFlag, }; use download_manager::util::progress_object::ProgressHandle; +use drop_consts::{BUMP_SIZE, MAX_PACKET_LENGTH}; use log::{debug, info, warn}; use md5::{Context, Digest}; use remote::auth::generate_authorization_header; @@ -25,9 +26,6 @@ use reqwest::blocking::Response; use crate::downloads::manifest::{ChunkBody, DownloadBucket, DownloadContext, DownloadDrop}; -static MAX_PACKET_LENGTH: usize = 4096 * 4; -static BUMP_SIZE: usize = 4096 * 16; - pub struct DropWriter { hasher: Context, destination: BufWriter, diff --git a/games/src/downloads/drop_data.rs b/games/src/downloads/drop_data.rs index 0c952cf..1e8ebc2 100644 --- a/games/src/downloads/drop_data.rs +++ b/games/src/downloads/drop_data.rs @@ -5,14 +5,13 @@ use std::{ path::{Path, PathBuf}, }; +use drop_consts::DROP_DATA_PATH; use log::error; use native_model::{Decode, Encode}; use utils::lock; pub type DropData = v1::DropData; -pub static DROP_DATA_PATH: &str = ".dropdata"; - pub mod v1 { use std::{collections::HashMap, path::PathBuf, sync::Mutex}; diff --git a/games/src/scan.rs b/games/src/scan.rs index 4a711fc..4b8f1cb 100644 --- a/games/src/scan.rs +++ b/games/src/scan.rs @@ -1,10 +1,11 @@ use std::fs; use database::{DownloadType, DownloadableMetadata, borrow_db_mut_checked}; +use drop_consts::DROP_DATA_PATH; use log::warn; use crate::{ - downloads::drop_data::{DROP_DATA_PATH, DropData}, + downloads::drop_data::DropData, library::set_partially_installed_db, }; diff --git a/process/Cargo.toml b/process/Cargo.toml index d3d67a1..3b052fe 100644 --- a/process/Cargo.toml +++ b/process/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" chrono = "0.4.42" client = { version = "0.1.0", path = "../client" } database = { version = "0.1.0", path = "../database" } +drop-consts = { version = "0.1.0", path = "../drop-consts" } dynfmt = "0.1.5" games = { version = "0.1.0", path = "../games" } log = "0.4.28" diff --git a/process/src/process_manager.rs b/process/src/process_manager.rs index 6fce4fe..461fa03 100644 --- a/process/src/process_manager.rs +++ b/process/src/process_manager.rs @@ -12,8 +12,9 @@ use std::{ use database::{ ApplicationTransientStatus, Database, DownloadType, DownloadableMetadata, GameDownloadStatus, - GameVersion, borrow_db_checked, borrow_db_mut_checked, db::DATA_ROOT_DIR, platform::Platform, + GameVersion, borrow_db_checked, borrow_db_mut_checked, platform::Platform, }; +use drop_consts::DATA_ROOT_DIR; use dynfmt::Format; use dynfmt::SimpleCurlyFormat; use games::{library::push_game_update, state::GameStatusManager}; diff --git a/remote/Cargo.toml b/remote/Cargo.toml index f352359..6c2e20d 100644 --- a/remote/Cargo.toml +++ b/remote/Cargo.toml @@ -8,6 +8,7 @@ bitcode = "0.6.7" chrono = "0.4.42" client = { version = "0.1.0", path = "../client" } database = { version = "0.1.0", path = "../database" } +drop-consts = { version = "0.1.0", path = "../drop-consts" } droplet-rs = "0.7.3" gethostname = "1.0.2" hex = "0.4.3" diff --git a/remote/src/utils.rs b/remote/src/utils.rs index 6ca4e0b..e6a3077 100644 --- a/remote/src/utils.rs +++ b/remote/src/utils.rs @@ -1,10 +1,8 @@ use std::{ - fs::{self, File}, - io::Read, - sync::LazyLock, + cell::LazyCell, fs::{self, File}, io::Read }; -use database::db::DATA_ROOT_DIR; +use drop_consts::DATA_ROOT_DIR; use log::{debug, info, warn}; use reqwest::Certificate; use serde::Deserialize; @@ -19,10 +17,10 @@ impl DropHealthcheck { &self.app_name } } -static DROP_CERT_BUNDLE: LazyLock> = LazyLock::new(fetch_certificates); -pub static DROP_CLIENT_SYNC: LazyLock = LazyLock::new(get_client_sync); -pub static DROP_CLIENT_ASYNC: LazyLock = LazyLock::new(get_client_async); -pub static DROP_CLIENT_WS_CLIENT: LazyLock = LazyLock::new(get_client_ws); +const DROP_CERT_BUNDLE: LazyCell> = LazyCell::new(fetch_certificates); +pub const DROP_CLIENT_SYNC: LazyCell = LazyCell::new(get_client_sync); +pub const DROP_CLIENT_ASYNC: LazyCell = LazyCell::new(get_client_async); +pub const DROP_CLIENT_WS_CLIENT: LazyCell = LazyCell::new(get_client_ws); fn fetch_certificates() -> Vec { let certificate_dir = DATA_ROOT_DIR.join("certificates"); diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7a1fcbf..3465af0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -87,6 +87,7 @@ remote = { version = "0.1.0", path = "../remote" } utils = { path = "../utils" } games = { version = "0.1.0", path = "../games" } download_manager = { version = "0.1.0", path = "../download_manager" } +drop-consts = { version = "0.1.0", path = "../drop-consts" } [dependencies.dynfmt] version = "0.1.5" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3230973..75f6d4f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -14,6 +14,7 @@ use std::{ use ::client::{app_status::AppStatus, autostart::sync_autostart_on_startup, user::User}; use ::download_manager::DownloadManagerWrapper; +use drop_consts::DATA_ROOT_DIR; use ::games::{library::Game, scan::scan_install_dirs}; use ::process::ProcessManagerWrapper; use ::remote::{ @@ -26,7 +27,7 @@ use ::remote::{ utils::DROP_CLIENT_ASYNC, }; use database::{ - DB, GameDownloadStatus, borrow_db_checked, borrow_db_mut_checked, db::DATA_ROOT_DIR, + DB, GameDownloadStatus, borrow_db_checked, borrow_db_mut_checked, interface::DatabaseImpls, }; use log::{LevelFilter, debug, info, warn}; diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs index 9faeab2..e7ee473 100644 --- a/src-tauri/src/settings.rs +++ b/src-tauri/src/settings.rs @@ -5,9 +5,10 @@ use std::{ }; use database::{ - Settings, borrow_db_checked, borrow_db_mut_checked, db::DATA_ROOT_DIR, debug::SystemData, + Settings, borrow_db_checked, borrow_db_mut_checked, debug::SystemData, }; use download_manager::error::DownloadManagerError; +use drop_consts::DATA_ROOT_DIR; use games::scan::scan_install_dirs; use log::error; use serde_json::Value;