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 std::fs::{create_dir_all, File};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use urlencoding::encode;
|
||||
|
||||
@ -60,7 +60,7 @@ impl GameDownloadAgent {
|
||||
Box::new(download_logic::download_game_chunk),
|
||||
Arc::new(RelaxedCounter::new(0)),
|
||||
callback,
|
||||
0
|
||||
0,
|
||||
),
|
||||
contexts: Mutex::new(Vec::new()),
|
||||
}
|
||||
@ -121,9 +121,12 @@ impl GameDownloadAgent {
|
||||
}
|
||||
|
||||
let manifest_download = response.json::<DropManifest>().unwrap();
|
||||
let length = manifest_download.iter().map(|(_, chunk)| {
|
||||
let length = manifest_download
|
||||
.values()
|
||||
.map(|chunk| {
|
||||
return chunk.lengths.iter().sum::<usize>();
|
||||
}).sum::<usize>();
|
||||
})
|
||||
.sum::<usize>();
|
||||
self.progress.set_capacity(length);
|
||||
if let Ok(mut manifest) = self.manifest.lock() {
|
||||
*manifest = Some(manifest_download)
|
||||
@ -131,7 +134,6 @@ impl GameDownloadAgent {
|
||||
return Err(GameDownloadError::System(SystemError::MutexLockFailed));
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@ -110,11 +110,11 @@ pub async fn stop_specific_game_download(
|
||||
#[tauri::command]
|
||||
pub async fn get_game_download_progress(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
game_id: String
|
||||
game_id: String,
|
||||
) -> Result<f64, String> {
|
||||
let lock = state.lock().unwrap();
|
||||
let download_agent = lock.game_downloads.get(&game_id).unwrap();
|
||||
let progress = download_agent.progress.get_progress_percentage();
|
||||
info!("{}", progress);
|
||||
return Ok(progress)
|
||||
Ok(progress)
|
||||
}
|
||||
@ -10,7 +10,7 @@ use std::{
|
||||
io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write},
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
@ -20,7 +20,7 @@ pub struct DropFileWriter {
|
||||
file: File,
|
||||
hasher: Context,
|
||||
callback: Arc<AtomicBool>,
|
||||
progress: Arc<RelaxedCounter>
|
||||
progress: Arc<RelaxedCounter>,
|
||||
}
|
||||
impl DropFileWriter {
|
||||
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(),
|
||||
hasher: Context::new(),
|
||||
callback,
|
||||
progress
|
||||
progress,
|
||||
}
|
||||
}
|
||||
fn finish(mut self) -> io::Result<Digest> {
|
||||
@ -63,7 +63,11 @@ impl Seek for DropFileWriter {
|
||||
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) {
|
||||
info!("Callback stopped download at start");
|
||||
return;
|
||||
@ -111,7 +115,10 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc<AtomicBool>,
|
||||
}
|
||||
let file = match writer.into_inner() {
|
||||
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);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use atomic_counter::{AtomicCounter, RelaxedCounter};
|
||||
use log::info;
|
||||
use rayon::ThreadPoolBuilder;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub struct ProgressChecker<T>
|
||||
@ -11,7 +11,7 @@ where
|
||||
counter: Arc<RelaxedCounter>,
|
||||
f: Arc<Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>>,
|
||||
callback: Arc<AtomicBool>,
|
||||
capacity: Mutex<usize>
|
||||
capacity: Mutex<usize>,
|
||||
}
|
||||
|
||||
impl<T> ProgressChecker<T>
|
||||
@ -22,13 +22,13 @@ where
|
||||
f: Box<dyn Fn(T, Arc<AtomicBool>, Arc<RelaxedCounter>) + Send + Sync + 'static>,
|
||||
counter: Arc<RelaxedCounter>,
|
||||
callback: Arc<AtomicBool>,
|
||||
capacity: usize
|
||||
capacity: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
f: f.into(),
|
||||
counter,
|
||||
callback,
|
||||
capacity: capacity.into()
|
||||
capacity: capacity.into(),
|
||||
}
|
||||
}
|
||||
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 db::{DatabaseInterface, DATA_ROOT_DIR};
|
||||
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 http::{header::*, response::Builder as ResponseBuilder};
|
||||
|
||||
Reference in New Issue
Block a user