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

View File

@ -1,3 +1,3 @@
pub mod autostart;
pub mod cleanup;
pub mod commands;
pub mod commands;

View File

@ -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},

View File

@ -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);
}
}
}
}

View File

@ -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)]

View File

@ -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 {

View File

@ -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 {

View File

@ -2,4 +2,4 @@ pub mod commands;
pub mod download_manager;
pub mod download_manager_builder;
pub mod downloadable;
pub mod util;
pub mod util;

View File

@ -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;

View File

@ -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()

View File

@ -31,6 +31,8 @@ impl<const S: usize> RollingProgressWindow<S> {
/ 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));
}
}

View File

@ -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)
}
}
}

View File

@ -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;

View File

@ -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<AppState>>,
) -> 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 {
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<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)?)
}

View File

@ -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};

View File

@ -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)
}
}

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 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<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)> {
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()
}
}

View File

@ -24,4 +24,4 @@ pub struct DropDownloadContext {
pub checksum: String,
pub length: usize,
pub permissions: u32,
}
}

View File

@ -1,6 +1,6 @@
pub mod commands;
pub mod download_agent;
mod download_logic;
mod manifest;
mod drop_data;
pub mod validate;
mod manifest;
pub mod validate;

View File

@ -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},
};

View File

@ -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);
}
},
}
}
}

View File

@ -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<whoami::Platform> for Platform {
whoami::Platform::Windows => Platform::Windows,
whoami::Platform::Linux => Platform::Linux,
whoami::Platform::MacOS => Platform::MacOs,
_ => unimplemented!()
_ => unimplemented!(),
}
}
}

View File

@ -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)]

View File

@ -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;