mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 00:02:41 +10:00
Ran cargo clippy and cargo fmt
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -10,7 +10,7 @@ use rustix::fs::{fallocate, FallocateFlags};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs::{create_dir_all, File};
|
use std::fs::{create_dir_all, File};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use urlencoding::encode;
|
use urlencoding::encode;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ impl GameDownloadAgent {
|
|||||||
Box::new(download_logic::download_game_chunk),
|
Box::new(download_logic::download_game_chunk),
|
||||||
Arc::new(RelaxedCounter::new(0)),
|
Arc::new(RelaxedCounter::new(0)),
|
||||||
callback,
|
callback,
|
||||||
0
|
0,
|
||||||
),
|
),
|
||||||
contexts: Mutex::new(Vec::new()),
|
contexts: Mutex::new(Vec::new()),
|
||||||
}
|
}
|
||||||
@ -121,16 +121,18 @@ impl GameDownloadAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let manifest_download = response.json::<DropManifest>().unwrap();
|
let manifest_download = response.json::<DropManifest>().unwrap();
|
||||||
let length = manifest_download.iter().map(|(_, chunk)| {
|
let length = manifest_download
|
||||||
return chunk.lengths.iter().sum::<usize>();
|
.values()
|
||||||
}).sum::<usize>();
|
.map(|chunk| {
|
||||||
|
return chunk.lengths.iter().sum::<usize>();
|
||||||
|
})
|
||||||
|
.sum::<usize>();
|
||||||
self.progress.set_capacity(length);
|
self.progress.set_capacity(length);
|
||||||
if let Ok(mut manifest) = self.manifest.lock() {
|
if let Ok(mut manifest) = self.manifest.lock() {
|
||||||
*manifest = Some(manifest_download)
|
*manifest = Some(manifest_download)
|
||||||
} else {
|
} else {
|
||||||
return Err(GameDownloadError::System(SystemError::MutexLockFailed));
|
return Err(GameDownloadError::System(SystemError::MutexLockFailed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,11 +110,11 @@ pub async fn stop_specific_game_download(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_game_download_progress(
|
pub async fn get_game_download_progress(
|
||||||
state: tauri::State<'_, Mutex<AppState>>,
|
state: tauri::State<'_, Mutex<AppState>>,
|
||||||
game_id: String
|
game_id: String,
|
||||||
) -> Result<f64, String> {
|
) -> Result<f64, String> {
|
||||||
let lock = state.lock().unwrap();
|
let lock = state.lock().unwrap();
|
||||||
let download_agent = lock.game_downloads.get(&game_id).unwrap();
|
let download_agent = lock.game_downloads.get(&game_id).unwrap();
|
||||||
let progress = download_agent.progress.get_progress_percentage();
|
let progress = download_agent.progress.get_progress_percentage();
|
||||||
info!("{}", progress);
|
info!("{}", progress);
|
||||||
return Ok(progress)
|
Ok(progress)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use std::{
|
|||||||
io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write},
|
io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -20,7 +20,7 @@ pub struct DropFileWriter {
|
|||||||
file: File,
|
file: File,
|
||||||
hasher: Context,
|
hasher: Context,
|
||||||
callback: Arc<AtomicBool>,
|
callback: Arc<AtomicBool>,
|
||||||
progress: Arc<RelaxedCounter>
|
progress: Arc<RelaxedCounter>,
|
||||||
}
|
}
|
||||||
impl DropFileWriter {
|
impl DropFileWriter {
|
||||||
fn new(path: PathBuf, callback: Arc<AtomicBool>, progress: Arc<RelaxedCounter>) -> Self {
|
fn new(path: PathBuf, callback: Arc<AtomicBool>, progress: Arc<RelaxedCounter>) -> Self {
|
||||||
@ -28,7 +28,7 @@ impl DropFileWriter {
|
|||||||
file: OpenOptions::new().write(true).open(path).unwrap(),
|
file: OpenOptions::new().write(true).open(path).unwrap(),
|
||||||
hasher: Context::new(),
|
hasher: Context::new(),
|
||||||
callback,
|
callback,
|
||||||
progress
|
progress,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn finish(mut self) -> io::Result<Digest> {
|
fn finish(mut self) -> io::Result<Digest> {
|
||||||
@ -63,7 +63,11 @@ impl Seek for DropFileWriter {
|
|||||||
self.file.seek(pos)
|
self.file.seek(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc<AtomicBool>, progress: Arc<RelaxedCounter>) {
|
pub fn download_game_chunk(
|
||||||
|
ctx: DropDownloadContext,
|
||||||
|
callback: Arc<AtomicBool>,
|
||||||
|
progress: Arc<RelaxedCounter>,
|
||||||
|
) {
|
||||||
if callback.load(Ordering::Acquire) {
|
if callback.load(Ordering::Acquire) {
|
||||||
info!("Callback stopped download at start");
|
info!("Callback stopped download at start");
|
||||||
return;
|
return;
|
||||||
@ -111,7 +115,10 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc<AtomicBool>,
|
|||||||
}
|
}
|
||||||
let file = match writer.into_inner() {
|
let file = match writer.into_inner() {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(_) => {error!("Failed to acquire writer from BufWriter"); return; }
|
Err(_) => {
|
||||||
|
error!("Failed to acquire writer from BufWriter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = hex::encode(file.finish().unwrap().0);
|
let res = hex::encode(file.finish().unwrap().0);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use atomic_counter::{AtomicCounter, RelaxedCounter};
|
use atomic_counter::{AtomicCounter, RelaxedCounter};
|
||||||
use log::info;
|
use log::info;
|
||||||
use rayon::ThreadPoolBuilder;
|
use rayon::ThreadPoolBuilder;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
pub struct ProgressChecker<T>
|
pub struct ProgressChecker<T>
|
||||||
@ -11,7 +11,7 @@ where
|
|||||||
counter: Arc<RelaxedCounter>,
|
counter: Arc<RelaxedCounter>,
|
||||||
f: Arc<Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>>,
|
f: Arc<Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>>,
|
||||||
callback: Arc<AtomicBool>,
|
callback: Arc<AtomicBool>,
|
||||||
capacity: Mutex<usize>
|
capacity: Mutex<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ProgressChecker<T>
|
impl<T> ProgressChecker<T>
|
||||||
@ -22,13 +22,13 @@ where
|
|||||||
f: Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>,
|
f: Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>,
|
||||||
counter: Arc<RelaxedCounter>,
|
counter: Arc<RelaxedCounter>,
|
||||||
callback: Arc<AtomicBool>,
|
callback: Arc<AtomicBool>,
|
||||||
capacity: usize
|
capacity: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
f: f.into(),
|
f: f.into(),
|
||||||
counter,
|
counter,
|
||||||
callback,
|
callback,
|
||||||
capacity: capacity.into()
|
capacity: capacity.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn run_contexts_sequentially(&self, contexts: Vec<T>) {
|
pub fn run_contexts_sequentially(&self, contexts: Vec<T>) {
|
||||||
|
|||||||
@ -11,7 +11,8 @@ use crate::downloads::download_agent::GameDownloadAgent;
|
|||||||
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
||||||
use db::{DatabaseInterface, DATA_ROOT_DIR};
|
use db::{DatabaseInterface, DATA_ROOT_DIR};
|
||||||
use downloads::download_commands::{
|
use downloads::download_commands::{
|
||||||
get_game_download_progress, queue_game_download, start_game_downloads, stop_specific_game_download
|
get_game_download_progress, queue_game_download, start_game_downloads,
|
||||||
|
stop_specific_game_download,
|
||||||
};
|
};
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use http::{header::*, response::Builder as ResponseBuilder};
|
use http::{header::*, response::Builder as ResponseBuilder};
|
||||||
|
|||||||
Reference in New Issue
Block a user