chore: Ran cargo fix & cargo fmt

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-07-04 14:36:43 +10:00
parent c38f1fbad3
commit a5082ee2f3
23 changed files with 104 additions and 95 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
pub mod autostart; pub mod autostart;
pub mod cleanup; pub mod cleanup;
pub mod commands; pub mod commands;
+3 -1
View File
@@ -6,7 +6,9 @@ use std::{
use serde_json::Value; 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::{ use super::{
db::{borrow_db_checked, DATA_ROOT_DIR}, db::{borrow_db_checked, DATA_ROOT_DIR},
+8 -6
View File
@@ -1,5 +1,9 @@
use std::{ 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; use chrono::Utc;
@@ -143,12 +147,11 @@ impl<'a> DerefMut for DBWrite<'a> {
} }
} }
impl<'a> Drop for DBWrite<'a> { impl<'a> Drop for DBWrite<'a> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ManuallyDrop::drop(&mut self.0); ManuallyDrop::drop(&mut self.0);
} }
match DB.save() { match DB.save() {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
@@ -159,7 +162,6 @@ impl<'a> Drop for DBWrite<'a> {
} }
} }
pub fn borrow_db_checked<'a>() -> DBRead<'a> { pub fn borrow_db_checked<'a>() -> DBRead<'a> {
match DB.borrow_data() { match DB.borrow_data() {
Ok(data) => DBRead(data), Ok(data) => DBRead(data),
Err(e) => { Err(e) => {
@@ -177,4 +179,4 @@ pub fn borrow_db_mut_checked<'a>() -> DBWrite<'a> {
panic!("database borrow mut failed with error {}", e); panic!("database borrow mut failed with error {}", e);
} }
} }
} }
+3 -11
View File
@@ -1,4 +1,4 @@
use crate::database::models::data::{Database, DatabaseCompatInfo}; use crate::database::models::data::Database;
pub mod data { pub mod data {
use std::path::PathBuf; use std::path::PathBuf;
@@ -20,8 +20,6 @@ pub mod data {
use std::{collections::HashMap, process::Command}; use std::{collections::HashMap, process::Command};
use serde_with::serde_as;
use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE; use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE;
pub mod v1 { pub mod v1 {
@@ -172,12 +170,10 @@ pub mod data {
} }
pub mod v2 { pub mod v2 {
use std::{collections::HashMap, path::PathBuf, process::Command}; use std::{collections::HashMap, path::PathBuf};
use serde_with::serde_as; use serde_with::serde_as;
use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE;
use super::*; use super::*;
#[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] #[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)]
@@ -285,11 +281,7 @@ pub mod data {
} }
} }
mod v3 { mod v3 {
use std::{collections::HashMap, path::PathBuf, process::Command}; use std::path::PathBuf;
use serde_with::serde_as;
use crate::process::process_manager::UMU_LAUNCHER_EXECUTABLE;
use super::*; use super::*;
#[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde)] #[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde)]
@@ -18,7 +18,8 @@ use crate::{
}; };
use super::{ use super::{
download_manager_builder::{CurrentProgressObject, DownloadAgent}, util::queue::Queue, download_manager_builder::{CurrentProgressObject, DownloadAgent},
util::queue::Queue,
}; };
pub enum DownloadManagerSignal { pub enum DownloadManagerSignal {
@@ -8,7 +8,8 @@ use crate::{
}; };
use super::{ 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 { pub trait Downloadable: Send + Sync {
+1 -1
View File
@@ -2,4 +2,4 @@ pub mod commands;
pub mod download_manager; pub mod download_manager;
pub mod download_manager_builder; pub mod download_manager_builder;
pub mod downloadable; pub mod downloadable;
pub mod util; pub mod util;
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod download_thread_control_flag;
pub mod progress_object; pub mod progress_object;
pub mod queue; pub mod queue;
pub mod rolling_progress_updates; pub mod rolling_progress_updates;
pub mod download_thread_control_flag;
@@ -12,9 +12,7 @@ use throttle_my_fn::throttle;
use crate::download_manager::download_manager::DownloadManagerSignal; use crate::download_manager::download_manager::DownloadManagerSignal;
use super::{ use super::rolling_progress_updates::RollingProgressWindow;
rolling_progress_updates::RollingProgressWindow,
};
#[derive(Clone)] #[derive(Clone)]
pub struct ProgressObject { pub struct ProgressObject {
@@ -91,7 +89,11 @@ impl ProgressObject {
self.set_size(size); self.set_size(size);
self.bytes_last_update.store(0, Ordering::Release); self.bytes_last_update.store(0, Ordering::Release);
self.rolling.reset(); 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 { pub fn get_max(&self) -> usize {
*self.max.lock().unwrap() *self.max.lock().unwrap()
@@ -31,6 +31,8 @@ impl<const S: usize> RollingProgressWindow<S> {
/ S / S
} }
pub fn reset(&self) { 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));
} }
} }
+2 -2
View File
@@ -6,7 +6,7 @@ use serde_with::SerializeDisplay;
pub enum BackupError { pub enum BackupError {
InvalidSystem, InvalidSystem,
NotFound, NotFound,
ParseError ParseError,
} }
impl Display for BackupError { impl Display for BackupError {
@@ -18,4 +18,4 @@ impl Display for BackupError {
}; };
write!(f, "{}", s) write!(f, "{}", s)
} }
} }
+2 -2
View File
@@ -1,8 +1,8 @@
pub mod application_download_error; pub mod application_download_error;
pub mod drop_server_error; pub mod backup_error;
pub mod download_manager_error; pub mod download_manager_error;
pub mod drop_server_error;
pub mod library_error; pub mod library_error;
pub mod process_error; pub mod process_error;
pub mod remote_access_error; pub mod remote_access_error;
pub mod setup_error; pub mod setup_error;
pub mod backup_error;
+28 -7
View File
@@ -1,7 +1,13 @@
use std::{path::PathBuf, sync::{Arc, Mutex}}; use std::{
path::PathBuf,
sync::{Arc, Mutex},
};
use crate::{ 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; use super::download_agent::GameDownloadAgent;
@@ -32,18 +38,33 @@ pub fn resume_download(
game_id: String, game_id: String,
state: tauri::State<'_, Mutex<AppState>>, state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), DownloadManagerError<DownloadManagerSignal>> { ) -> Result<(), DownloadManagerError<DownloadManagerSignal>> {
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 { let (version_name, install_dir) = match s {
GameDownloadStatus::Remote { } => unreachable!(), GameDownloadStatus::Remote {} => unreachable!(),
GameDownloadStatus::SetupRequired { .. } => unreachable!(), GameDownloadStatus::SetupRequired { .. } => unreachable!(),
GameDownloadStatus::Installed { .. } => 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 sender = state.lock().unwrap().download_manager.get_sender();
let parent_dir: PathBuf = install_dir.into(); let parent_dir: PathBuf = install_dir.into();
let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new( 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<dyn Downloadable + Send + Sync>); )) as Box<dyn Downloadable + Send + Sync>);
Ok(state.lock().unwrap().download_manager.queue_download(game_download_agent)?) Ok(state
.lock()
.unwrap()
.download_manager
.queue_download(game_download_agent)?)
} }
@@ -1,7 +1,7 @@
use crate::auth::generate_authorization_header; use crate::auth::generate_authorization_header;
use crate::database::db::{borrow_db_checked, borrow_db_mut_checked}; use crate::database::db::{borrow_db_checked, borrow_db_mut_checked};
use crate::database::models::data::{ use crate::database::models::data::{
ApplicationTransientStatus, DownloadType, DownloadableMetadata, GameDownloadStatus, ApplicationTransientStatus, DownloadType, DownloadableMetadata,
}; };
use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus}; use crate::download_manager::download_manager::{DownloadManagerSignal, DownloadStatus};
use crate::download_manager::downloadable::Downloadable; 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::error::remote_access_error::RemoteAccessError;
use crate::games::downloads::manifest::{DropDownloadContext, DropManifest}; use crate::games::downloads::manifest::{DropDownloadContext, DropManifest};
use crate::games::downloads::validate::game_validate_logic; use crate::games::downloads::validate::game_validate_logic;
use crate::games::library::{ use crate::games::library::{on_game_complete, on_game_incomplete, push_game_update};
on_game_complete, on_game_incomplete, push_game_update, GameUpdateEvent,
};
use crate::remote::requests::make_request; use crate::remote::requests::make_request;
use crate::DB;
use log::{debug, error, info}; use log::{debug, error, info};
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
use slice_deque::SliceDeque;
use std::collections::HashMap; 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::path::{Path, PathBuf};
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Instant; use std::time::Instant;
use tauri::{AppHandle, Emitter, Manager}; use tauri::{AppHandle, Emitter};
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use rustix::fs::{fallocate, FallocateFlags}; use rustix::fs::{fallocate, FallocateFlags};
@@ -4,23 +4,16 @@ use crate::download_manager::util::download_thread_control_flag::{
use crate::download_manager::util::progress_object::ProgressHandle; use crate::download_manager::util::progress_object::ProgressHandle;
use crate::error::application_download_error::ApplicationDownloadError; use crate::error::application_download_error::ApplicationDownloadError;
use crate::error::remote_access_error::RemoteAccessError; use crate::error::remote_access_error::RemoteAccessError;
use crate::games::downloads::drop_data::DropData; use crate::games::downloads::manifest::DropDownloadContext;
use crate::games::downloads::manifest::{DropDownloadContext, DropManifest};
use crate::remote::auth::generate_authorization_header;
use crate::remote::requests::make_request;
use log::{debug, warn}; use log::{debug, warn};
use md5::{Context, Digest}; use md5::{Context, Digest};
use native_model::Decode;
use reqwest::blocking::{RequestBuilder, Response}; use reqwest::blocking::{RequestBuilder, Response};
use reqwest::Client;
use std::fs::{set_permissions, Permissions}; use std::fs::{set_permissions, Permissions};
use std::io::{copy, ErrorKind, Read}; use std::io::{ErrorKind, Read};
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::thread::sleep;
use std::time::Duration;
use std::{ use std::{
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::{self, BufWriter, Seek, SeekFrom, Write}, io::{self, BufWriter, Seek, SeekFrom, Write},
@@ -206,4 +199,4 @@ pub fn download_game_chunk(
); );
Ok(true) Ok(true)
} }
+17 -6
View File
@@ -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 log::{debug, error, info, warn};
use native_model::{Decode, Encode}; use native_model::{Decode, Encode};
@@ -7,7 +11,6 @@ pub type DropData = v1::DropData;
static DROP_DATA_PATH: &str = ".dropdata"; static DROP_DATA_PATH: &str = ".dropdata";
pub mod v1 { pub mod v1 {
use std::{path::PathBuf, sync::Mutex}; use std::{path::PathBuf, sync::Mutex};
@@ -41,8 +44,8 @@ impl DropData {
Ok(file) => file, Ok(file) => file,
Err(_) => { Err(_) => {
debug!("Generating new dropdata for game {}", game_id); 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(); let mut s = Vec::new();
@@ -85,10 +88,18 @@ impl DropData {
*self.contexts.lock().unwrap() = completed_contexts.to_owned(); *self.contexts.lock().unwrap() = completed_contexts.to_owned();
} }
pub fn get_completed_contexts(&self) -> Vec<String> { pub fn get_completed_contexts(&self) -> Vec<String> {
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)> { 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() self.contexts.lock().unwrap().clone()
} }
} }
+1 -1
View File
@@ -24,4 +24,4 @@ pub struct DropDownloadContext {
pub checksum: String, pub checksum: String,
pub length: usize, pub length: usize,
pub permissions: u32, pub permissions: u32,
} }
+2 -2
View File
@@ -1,6 +1,6 @@
pub mod commands; pub mod commands;
pub mod download_agent; pub mod download_agent;
mod download_logic; mod download_logic;
mod manifest;
mod drop_data; mod drop_data;
pub mod validate; mod manifest;
pub mod validate;
+2 -11
View File
@@ -1,33 +1,24 @@
use std::{ use std::{
fs::File, fs::File,
io::{self, BufWriter, Read, Seek, SeekFrom, Write}, io::{self, BufWriter, Read, Seek, SeekFrom, Write},
path::{Path, PathBuf},
sync::{mpsc::Sender, Arc}, sync::{mpsc::Sender, Arc},
}; };
use log::{debug, error, info}; use log::{debug, error, info};
use md5::Context; use md5::Context;
use native_model::Decode;
use rayon::ThreadPoolBuilder; use rayon::ThreadPoolBuilder;
use crate::{ use crate::{
database::db::borrow_db_checked, database::db::borrow_db_checked,
download_manager::{ download_manager::{
download_manager::DownloadManagerSignal, download_manager::DownloadManagerSignal,
downloadable::Downloadable,
util::{ util::{
download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag}, download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag},
progress_object::{ProgressHandle, ProgressObject}, progress_object::{ProgressHandle, ProgressObject},
}, },
}, },
error::{ error::application_download_error::ApplicationDownloadError,
application_download_error::ApplicationDownloadError, games::downloads::{drop_data::DropData, manifest::DropDownloadContext},
remote_access_error::RemoteAccessError,
},
games::downloads::{
drop_data::DropData,
manifest::{DropDownloadContext, DropManifest},
},
remote::{auth::generate_authorization_header, requests::make_request}, remote::{auth::generate_authorization_header, requests::make_request},
}; };
+3 -3
View File
@@ -8,11 +8,11 @@ mod process;
mod remote; mod remote;
use crate::{database::db::DatabaseImpls, games::downloads::commands::resume_download}; use crate::{database::db::DatabaseImpls, games::downloads::commands::resume_download};
use client::commands::fetch_state;
use client::{ use client::{
autostart::{get_autostart_enabled, sync_autostart_on_startup, toggle_autostart}, autostart::{get_autostart_enabled, sync_autostart_on_startup, toggle_autostart},
cleanup::{cleanup_and_exit, quit}, cleanup::{cleanup_and_exit, quit},
}; };
use client::commands::fetch_state;
use database::commands::{ use database::commands::{
add_download_dir, delete_download_dir, fetch_download_dir_stats, fetch_settings, add_download_dir, delete_download_dir, fetch_download_dir_stats, fetch_settings,
fetch_system_data, update_settings, fetch_system_data, update_settings,
@@ -156,7 +156,7 @@ fn setup(handle: AppHandle) -> AppState<'static> {
for (game_id, status) in statuses.into_iter() { for (game_id, status) in statuses.into_iter() {
match status { match status {
GameDownloadStatus::Remote {} => {} GameDownloadStatus::Remote {} => {}
GameDownloadStatus::PartiallyInstalled { .. } => {}, GameDownloadStatus::PartiallyInstalled { .. } => {}
GameDownloadStatus::SetupRequired { GameDownloadStatus::SetupRequired {
version_name: _, version_name: _,
install_dir, install_dir,
@@ -174,7 +174,7 @@ fn setup(handle: AppHandle) -> AppState<'static> {
if !install_dir_path.exists() { if !install_dir_path.exists() {
missing_games.push(game_id); missing_games.push(game_id);
} }
}, }
} }
} }
+7 -8
View File
@@ -193,8 +193,9 @@ impl ProcessManager<'_> {
version_name, version_name,
install_dir, install_dir,
} => (version_name, install_dir), } => (version_name, install_dir),
GameDownloadStatus::PartiallyInstalled { GameDownloadStatus::PartiallyInstalled {
version_name, install_dir version_name,
install_dir,
} => (version_name, install_dir), } => (version_name, install_dir),
_ => return Err(ProcessError::NotDownloaded), _ => return Err(ProcessError::NotDownloaded),
}; };
@@ -251,9 +252,9 @@ impl ProcessManager<'_> {
version_name: _, version_name: _,
install_dir: _, install_dir: _,
} => (&game_version.setup_command, &game_version.setup_args), } => (&game_version.setup_command, &game_version.setup_args),
GameDownloadStatus::PartiallyInstalled { GameDownloadStatus::PartiallyInstalled {
version_name, version_name,
install_dir install_dir,
} => unreachable!("Game registered as 'Partially Installed'"), } => unreachable!("Game registered as 'Partially Installed'"),
GameDownloadStatus::Remote {} => unreachable!("Game registered as 'Remote'"), GameDownloadStatus::Remote {} => unreachable!("Game registered as 'Remote'"),
}; };
@@ -353,8 +354,6 @@ impl Platform {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub const HOST: Platform = Self::Linux; pub const HOST: Platform = Self::Linux;
pub fn is_case_sensitive(&self) -> bool { pub fn is_case_sensitive(&self) -> bool {
match self { match self {
Self::Windows | Self::MacOs => false, Self::Windows | Self::MacOs => false,
@@ -380,7 +379,7 @@ impl From<whoami::Platform> for Platform {
whoami::Platform::Windows => Platform::Windows, whoami::Platform::Windows => Platform::Windows,
whoami::Platform::Linux => Platform::Linux, whoami::Platform::Linux => Platform::Linux,
whoami::Platform::MacOS => Platform::MacOs, whoami::Platform::MacOS => Platform::MacOs,
_ => unimplemented!() _ => unimplemented!(),
} }
} }
} }
+2 -3
View File
@@ -5,9 +5,8 @@ use serde::Deserialize;
use url::Url; use url::Url;
use crate::{ use crate::{
database::db::{borrow_db_mut_checked}, database::db::borrow_db_mut_checked, error::remote_access_error::RemoteAccessError, AppState,
error::remote_access_error::RemoteAccessError, AppStatus,
AppState, AppStatus,
}; };
#[derive(Deserialize)] #[derive(Deserialize)]
+1 -4
View File
@@ -1,9 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use http::{ use http::{uri::PathAndQuery, Request, Response, StatusCode, Uri};
uri::PathAndQuery,
Request, Response, StatusCode, Uri,
};
use reqwest::blocking::Client; use reqwest::blocking::Client;
use tauri::UriSchemeResponder; use tauri::UriSchemeResponder;