diff --git a/src-tauri/src/client/mod.rs b/src-tauri/src/client/mod.rs index 6462889..48b6821 100644 --- a/src-tauri/src/client/mod.rs +++ b/src-tauri/src/client/mod.rs @@ -1,3 +1,3 @@ pub mod autostart; pub mod cleanup; -pub mod commands; \ No newline at end of file +pub mod commands; diff --git a/src-tauri/src/database/commands.rs b/src-tauri/src/database/commands.rs index a83fd17..1ebbb79 100644 --- a/src-tauri/src/database/commands.rs +++ b/src-tauri/src/database/commands.rs @@ -6,7 +6,9 @@ use std::{ use serde_json::Value; -use crate::{database::db::borrow_db_mut_checked, error::download_manager_error::DownloadManagerError}; +use crate::{ + database::db::borrow_db_mut_checked, error::download_manager_error::DownloadManagerError, +}; use super::{ db::{borrow_db_checked, DATA_ROOT_DIR}, diff --git a/src-tauri/src/database/db.rs b/src-tauri/src/database/db.rs index 8148346..b3d9475 100644 --- a/src-tauri/src/database/db.rs +++ b/src-tauri/src/database/db.rs @@ -1,5 +1,9 @@ use std::{ - fs::{self, create_dir_all}, mem::{replace, ManuallyDrop}, ops::{Deref, DerefMut}, path::PathBuf, sync::{LazyLock, Mutex, RwLockReadGuard, RwLockWriteGuard} + fs::{self, create_dir_all}, + mem::ManuallyDrop, + ops::{Deref, DerefMut}, + path::PathBuf, + sync::{LazyLock, Mutex, RwLockReadGuard, RwLockWriteGuard}, }; use chrono::Utc; @@ -143,12 +147,11 @@ impl<'a> DerefMut for DBWrite<'a> { } } impl<'a> Drop for DBWrite<'a> { - fn drop(&mut self) { - + fn drop(&mut self) { unsafe { ManuallyDrop::drop(&mut self.0); } - + match DB.save() { Ok(_) => {} Err(e) => { @@ -159,7 +162,6 @@ impl<'a> Drop for DBWrite<'a> { } } pub fn borrow_db_checked<'a>() -> DBRead<'a> { - match DB.borrow_data() { Ok(data) => DBRead(data), Err(e) => { @@ -177,4 +179,4 @@ pub fn borrow_db_mut_checked<'a>() -> DBWrite<'a> { panic!("database borrow mut failed with error {}", e); } } -} \ No newline at end of file +} diff --git a/src-tauri/src/database/models.rs b/src-tauri/src/database/models.rs index 99192a5..a0e88a8 100644 --- a/src-tauri/src/database/models.rs +++ b/src-tauri/src/database/models.rs @@ -1,4 +1,4 @@ -use crate::database::models::data::{Database, DatabaseCompatInfo}; +use crate::database::models::data::Database; pub mod data { use std::path::PathBuf; @@ -20,8 +20,6 @@ pub mod data { use std::{collections::HashMap, process::Command}; - use serde_with::serde_as; - use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE; pub mod v1 { @@ -172,12 +170,10 @@ pub mod data { } pub mod v2 { - use std::{collections::HashMap, path::PathBuf, process::Command}; + use std::{collections::HashMap, path::PathBuf}; use serde_with::serde_as; - use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE; - use super::*; #[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] @@ -285,11 +281,7 @@ pub mod data { } } mod v3 { - use std::{collections::HashMap, path::PathBuf, process::Command}; - - use serde_with::serde_as; - - use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE; + use std::path::PathBuf; use super::*; #[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde)] diff --git a/src-tauri/src/download_manager/download_manager.rs b/src-tauri/src/download_manager/download_manager.rs index 9b7d209..2f1c21b 100644 --- a/src-tauri/src/download_manager/download_manager.rs +++ b/src-tauri/src/download_manager/download_manager.rs @@ -18,7 +18,8 @@ use crate::{ }; use super::{ - download_manager_builder::{CurrentProgressObject, DownloadAgent}, util::queue::Queue, + download_manager_builder::{CurrentProgressObject, DownloadAgent}, + util::queue::Queue, }; pub enum DownloadManagerSignal { diff --git a/src-tauri/src/download_manager/downloadable.rs b/src-tauri/src/download_manager/downloadable.rs index 7a6fe4e..4a66669 100644 --- a/src-tauri/src/download_manager/downloadable.rs +++ b/src-tauri/src/download_manager/downloadable.rs @@ -8,7 +8,8 @@ use crate::{ }; use super::{ - download_manager::DownloadStatus, util::{download_thread_control_flag::DownloadThreadControl, progress_object::ProgressObject}, + download_manager::DownloadStatus, + util::{download_thread_control_flag::DownloadThreadControl, progress_object::ProgressObject}, }; pub trait Downloadable: Send + Sync { diff --git a/src-tauri/src/download_manager/mod.rs b/src-tauri/src/download_manager/mod.rs index c7ae9d0..1895798 100644 --- a/src-tauri/src/download_manager/mod.rs +++ b/src-tauri/src/download_manager/mod.rs @@ -2,4 +2,4 @@ pub mod commands; pub mod download_manager; pub mod download_manager_builder; pub mod downloadable; -pub mod util; \ No newline at end of file +pub mod util; diff --git a/src-tauri/src/download_manager/util/mod.rs b/src-tauri/src/download_manager/util/mod.rs index 9463f1e..5476d22 100644 --- a/src-tauri/src/download_manager/util/mod.rs +++ b/src-tauri/src/download_manager/util/mod.rs @@ -1,4 +1,4 @@ +pub mod download_thread_control_flag; pub mod progress_object; pub mod queue; pub mod rolling_progress_updates; -pub mod download_thread_control_flag; \ No newline at end of file diff --git a/src-tauri/src/download_manager/util/progress_object.rs b/src-tauri/src/download_manager/util/progress_object.rs index 74552b8..e7eef2a 100644 --- a/src-tauri/src/download_manager/util/progress_object.rs +++ b/src-tauri/src/download_manager/util/progress_object.rs @@ -12,9 +12,7 @@ use throttle_my_fn::throttle; use crate::download_manager::download_manager::DownloadManagerSignal; -use super::{ - rolling_progress_updates::RollingProgressWindow, -}; +use super::rolling_progress_updates::RollingProgressWindow; #[derive(Clone)] pub struct ProgressObject { @@ -91,7 +89,11 @@ impl ProgressObject { self.set_size(size); self.bytes_last_update.store(0, Ordering::Release); self.rolling.reset(); - self.progress_instances.lock().unwrap().iter().for_each(|x| x.store(0, Ordering::Release)); + self.progress_instances + .lock() + .unwrap() + .iter() + .for_each(|x| x.store(0, Ordering::Release)); } pub fn get_max(&self) -> usize { *self.max.lock().unwrap() diff --git a/src-tauri/src/download_manager/util/rolling_progress_updates.rs b/src-tauri/src/download_manager/util/rolling_progress_updates.rs index 3b5f8e5..39ee041 100644 --- a/src-tauri/src/download_manager/util/rolling_progress_updates.rs +++ b/src-tauri/src/download_manager/util/rolling_progress_updates.rs @@ -31,6 +31,8 @@ impl RollingProgressWindow { / S } pub fn reset(&self) { - self.window.iter().for_each(|x| x.store(0, Ordering::Release)); + self.window + .iter() + .for_each(|x| x.store(0, Ordering::Release)); } } diff --git a/src-tauri/src/error/backup_error.rs b/src-tauri/src/error/backup_error.rs index 17a76c5..1adfafe 100644 --- a/src-tauri/src/error/backup_error.rs +++ b/src-tauri/src/error/backup_error.rs @@ -6,7 +6,7 @@ use serde_with::SerializeDisplay; pub enum BackupError { InvalidSystem, NotFound, - ParseError + ParseError, } impl Display for BackupError { @@ -18,4 +18,4 @@ impl Display for BackupError { }; write!(f, "{}", s) } -} \ No newline at end of file +} diff --git a/src-tauri/src/error/mod.rs b/src-tauri/src/error/mod.rs index 734e537..4053efd 100644 --- a/src-tauri/src/error/mod.rs +++ b/src-tauri/src/error/mod.rs @@ -1,8 +1,8 @@ pub mod application_download_error; -pub mod drop_server_error; +pub mod backup_error; pub mod download_manager_error; +pub mod drop_server_error; pub mod library_error; pub mod process_error; pub mod remote_access_error; pub mod setup_error; -pub mod backup_error; \ No newline at end of file diff --git a/src-tauri/src/games/downloads/commands.rs b/src-tauri/src/games/downloads/commands.rs index 7b84232..7d1118c 100644 --- a/src-tauri/src/games/downloads/commands.rs +++ b/src-tauri/src/games/downloads/commands.rs @@ -1,7 +1,13 @@ -use std::{path::PathBuf, sync::{Arc, Mutex}}; +use std::{ + path::PathBuf, + sync::{Arc, Mutex}, +}; use crate::{ - database::{db::borrow_db_checked, models::data::GameDownloadStatus}, download_manager::{download_manager::DownloadManagerSignal, downloadable::Downloadable}, error::download_manager_error::DownloadManagerError, AppState + database::{db::borrow_db_checked, models::data::GameDownloadStatus}, + download_manager::{download_manager::DownloadManagerSignal, downloadable::Downloadable}, + error::download_manager_error::DownloadManagerError, + AppState, }; use super::download_agent::GameDownloadAgent; @@ -32,18 +38,33 @@ pub fn resume_download( game_id: String, state: tauri::State<'_, Mutex>, ) -> Result<(), DownloadManagerError> { - let s = borrow_db_checked().applications.game_statuses.get(&game_id).unwrap().clone(); + let s = borrow_db_checked() + .applications + .game_statuses + .get(&game_id) + .unwrap() + .clone(); let (version_name, install_dir) = match s { - GameDownloadStatus::Remote { } => unreachable!(), + GameDownloadStatus::Remote {} => unreachable!(), GameDownloadStatus::SetupRequired { .. } => unreachable!(), GameDownloadStatus::Installed { .. } => unreachable!(), - GameDownloadStatus::PartiallyInstalled { version_name, install_dir } => (version_name, install_dir), + GameDownloadStatus::PartiallyInstalled { + version_name, + install_dir, + } => (version_name, install_dir), }; let sender = state.lock().unwrap().download_manager.get_sender(); let parent_dir: PathBuf = install_dir.into(); let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new( - game_id, version_name.clone(), parent_dir.parent().unwrap().to_path_buf(), sender + game_id, + version_name.clone(), + parent_dir.parent().unwrap().to_path_buf(), + sender, )) as Box); - Ok(state.lock().unwrap().download_manager.queue_download(game_download_agent)?) + Ok(state + .lock() + .unwrap() + .download_manager + .queue_download(game_download_agent)?) } diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs index be262df..beca4cc 100644 --- a/src-tauri/src/games/downloads/download_agent.rs +++ b/src-tauri/src/games/downloads/download_agent.rs @@ -1,7 +1,7 @@ use crate::auth::generate_authorization_header; use crate::database::db::{borrow_db_checked, borrow_db_mut_checked}; use crate::database::models::data::{ - ApplicationTransientStatus, DownloadType, DownloadableMetadata, GameDownloadStatus, + ApplicationTransientStatus, DownloadType, DownloadableMetadata, }; use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus}; use crate::download_manager::downloadable::Downloadable; @@ -13,21 +13,17 @@ use crate::error::application_download_error::ApplicationDownloadError; use crate::error::remote_access_error::RemoteAccessError; use crate::games::downloads::manifest::{DropDownloadContext, DropManifest}; use crate::games::downloads::validate::game_validate_logic; -use crate::games::library::{ - on_game_complete, on_game_incomplete, push_game_update, GameUpdateEvent, -}; +use crate::games::library::{on_game_complete, on_game_incomplete, push_game_update}; use crate::remote::requests::make_request; -use crate::DB; use log::{debug, error, info}; use rayon::ThreadPoolBuilder; -use slice_deque::SliceDeque; use std::collections::HashMap; -use std::fs::{create_dir_all, File, OpenOptions}; +use std::fs::{create_dir_all, OpenOptions}; use std::path::{Path, PathBuf}; use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex}; use std::time::Instant; -use tauri::{AppHandle, Emitter, Manager}; +use tauri::{AppHandle, Emitter}; #[cfg(target_os = "linux")] use rustix::fs::{fallocate, FallocateFlags}; diff --git a/src-tauri/src/games/downloads/download_logic.rs b/src-tauri/src/games/downloads/download_logic.rs index 575020a..59b5d99 100644 --- a/src-tauri/src/games/downloads/download_logic.rs +++ b/src-tauri/src/games/downloads/download_logic.rs @@ -4,23 +4,16 @@ use crate::download_manager::util::download_thread_control_flag::{ use crate::download_manager::util::progress_object::ProgressHandle; use crate::error::application_download_error::ApplicationDownloadError; use crate::error::remote_access_error::RemoteAccessError; -use crate::games::downloads::drop_data::DropData; -use crate::games::downloads::manifest::{DropDownloadContext, DropManifest}; -use crate::remote::auth::generate_authorization_header; -use crate::remote::requests::make_request; +use crate::games::downloads::manifest::DropDownloadContext; use log::{debug, warn}; use md5::{Context, Digest}; -use native_model::Decode; use reqwest::blocking::{RequestBuilder, Response}; -use reqwest::Client; use std::fs::{set_permissions, Permissions}; -use std::io::{copy, ErrorKind, Read}; +use std::io::{ErrorKind, Read}; use std::os::unix::fs::MetadataExt; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; -use std::thread::sleep; -use std::time::Duration; use std::{ fs::{File, OpenOptions}, io::{self, BufWriter, Seek, SeekFrom, Write}, @@ -206,4 +199,4 @@ pub fn download_game_chunk( ); Ok(true) -} \ No newline at end of file +} diff --git a/src-tauri/src/games/downloads/drop_data.rs b/src-tauri/src/games/downloads/drop_data.rs index 4120c3d..4ec61a9 100644 --- a/src-tauri/src/games/downloads/drop_data.rs +++ b/src-tauri/src/games/downloads/drop_data.rs @@ -1,4 +1,8 @@ -use std::{fs::File, io::{Read, Write}, path::PathBuf}; +use std::{ + fs::File, + io::{Read, Write}, + path::PathBuf, +}; use log::{debug, error, info, warn}; use native_model::{Decode, Encode}; @@ -7,7 +11,6 @@ pub type DropData = v1::DropData; static DROP_DATA_PATH: &str = ".dropdata"; - pub mod v1 { use std::{path::PathBuf, sync::Mutex}; @@ -41,8 +44,8 @@ impl DropData { Ok(file) => file, Err(_) => { debug!("Generating new dropdata for game {}", game_id); - return DropData::new(game_id, game_version, base_path) - }, + return DropData::new(game_id, game_version, base_path); + } }; let mut s = Vec::new(); @@ -85,10 +88,18 @@ impl DropData { *self.contexts.lock().unwrap() = completed_contexts.to_owned(); } pub fn get_completed_contexts(&self) -> Vec { - self.contexts.lock().unwrap().iter().filter_map(|x| { if x.1 { Some(x.0.clone()) } else { None } }).collect() + self.contexts + .lock() + .unwrap() + .iter() + .filter_map(|x| if x.1 { Some(x.0.clone()) } else { None }) + .collect() } pub fn get_contexts(&self) -> Vec<(String, bool)> { - info!("Any contexts which are complete? {}", self.contexts.lock().unwrap().iter().any(|x| x.1)); + info!( + "Any contexts which are complete? {}", + self.contexts.lock().unwrap().iter().any(|x| x.1) + ); self.contexts.lock().unwrap().clone() } } diff --git a/src-tauri/src/games/downloads/manifest.rs b/src-tauri/src/games/downloads/manifest.rs index 5923d6f..7c5b3a9 100644 --- a/src-tauri/src/games/downloads/manifest.rs +++ b/src-tauri/src/games/downloads/manifest.rs @@ -24,4 +24,4 @@ pub struct DropDownloadContext { pub checksum: String, pub length: usize, pub permissions: u32, -} \ No newline at end of file +} diff --git a/src-tauri/src/games/downloads/mod.rs b/src-tauri/src/games/downloads/mod.rs index 60cc90a..5854c55 100644 --- a/src-tauri/src/games/downloads/mod.rs +++ b/src-tauri/src/games/downloads/mod.rs @@ -1,6 +1,6 @@ pub mod commands; pub mod download_agent; mod download_logic; -mod manifest; mod drop_data; -pub mod validate; \ No newline at end of file +mod manifest; +pub mod validate; diff --git a/src-tauri/src/games/downloads/validate.rs b/src-tauri/src/games/downloads/validate.rs index c298987..60efbce 100644 --- a/src-tauri/src/games/downloads/validate.rs +++ b/src-tauri/src/games/downloads/validate.rs @@ -1,33 +1,24 @@ use std::{ fs::File, io::{self, BufWriter, Read, Seek, SeekFrom, Write}, - path::{Path, PathBuf}, sync::{mpsc::Sender, Arc}, }; use log::{debug, error, info}; use md5::Context; -use native_model::Decode; use rayon::ThreadPoolBuilder; use crate::{ database::db::borrow_db_checked, download_manager::{ download_manager::DownloadManagerSignal, - downloadable::Downloadable, util::{ download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag}, progress_object::{ProgressHandle, ProgressObject}, }, }, - error::{ - application_download_error::ApplicationDownloadError, - remote_access_error::RemoteAccessError, - }, - games::downloads::{ - drop_data::DropData, - manifest::{DropDownloadContext, DropManifest}, - }, + error::application_download_error::ApplicationDownloadError, + games::downloads::{drop_data::DropData, manifest::DropDownloadContext}, remote::{auth::generate_authorization_header, requests::make_request}, }; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5462f01..9e57608 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -8,11 +8,11 @@ mod process; mod remote; use crate::{database::db::DatabaseImpls, games::downloads::commands::resume_download}; +use client::commands::fetch_state; use client::{ autostart::{get_autostart_enabled, sync_autostart_on_startup, toggle_autostart}, cleanup::{cleanup_and_exit, quit}, }; -use client::commands::fetch_state; use database::commands::{ add_download_dir, delete_download_dir, fetch_download_dir_stats, fetch_settings, fetch_system_data, update_settings, @@ -156,7 +156,7 @@ fn setup(handle: AppHandle) -> AppState<'static> { for (game_id, status) in statuses.into_iter() { match status { GameDownloadStatus::Remote {} => {} - GameDownloadStatus::PartiallyInstalled { .. } => {}, + GameDownloadStatus::PartiallyInstalled { .. } => {} GameDownloadStatus::SetupRequired { version_name: _, install_dir, @@ -174,7 +174,7 @@ fn setup(handle: AppHandle) -> AppState<'static> { if !install_dir_path.exists() { missing_games.push(game_id); } - }, + } } } diff --git a/src-tauri/src/process/process_manager.rs b/src-tauri/src/process/process_manager.rs index 5646a06..9ae843a 100644 --- a/src-tauri/src/process/process_manager.rs +++ b/src-tauri/src/process/process_manager.rs @@ -193,8 +193,9 @@ impl ProcessManager<'_> { version_name, install_dir, } => (version_name, install_dir), - GameDownloadStatus::PartiallyInstalled { - version_name, install_dir + GameDownloadStatus::PartiallyInstalled { + version_name, + install_dir, } => (version_name, install_dir), _ => return Err(ProcessError::NotDownloaded), }; @@ -251,9 +252,9 @@ impl ProcessManager<'_> { version_name: _, install_dir: _, } => (&game_version.setup_command, &game_version.setup_args), - GameDownloadStatus::PartiallyInstalled { - version_name, - install_dir + GameDownloadStatus::PartiallyInstalled { + version_name, + install_dir, } => unreachable!("Game registered as 'Partially Installed'"), GameDownloadStatus::Remote {} => unreachable!("Game registered as 'Remote'"), }; @@ -353,8 +354,6 @@ impl Platform { #[cfg(target_os = "linux")] pub const HOST: Platform = Self::Linux; - - pub fn is_case_sensitive(&self) -> bool { match self { Self::Windows | Self::MacOs => false, @@ -380,7 +379,7 @@ impl From for Platform { whoami::Platform::Windows => Platform::Windows, whoami::Platform::Linux => Platform::Linux, whoami::Platform::MacOS => Platform::MacOs, - _ => unimplemented!() + _ => unimplemented!(), } } } diff --git a/src-tauri/src/remote/remote.rs b/src-tauri/src/remote/remote.rs index cf340a9..888ec44 100644 --- a/src-tauri/src/remote/remote.rs +++ b/src-tauri/src/remote/remote.rs @@ -5,9 +5,8 @@ use serde::Deserialize; use url::Url; use crate::{ - database::db::{borrow_db_mut_checked}, - error::remote_access_error::RemoteAccessError, - AppState, AppStatus, + database::db::borrow_db_mut_checked, error::remote_access_error::RemoteAccessError, AppState, + AppStatus, }; #[derive(Deserialize)] diff --git a/src-tauri/src/remote/server_proto.rs b/src-tauri/src/remote/server_proto.rs index 00c215b..4bd7a5d 100644 --- a/src-tauri/src/remote/server_proto.rs +++ b/src-tauri/src/remote/server_proto.rs @@ -1,9 +1,6 @@ use std::str::FromStr; -use http::{ - uri::PathAndQuery, - Request, Response, StatusCode, Uri, -}; +use http::{uri::PathAndQuery, Request, Response, StatusCode, Uri}; use reqwest::blocking::Client; use tauri::UriSchemeResponder;