mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 16:22:43 +10:00
refactor(downloads): ran cargo clippy & cargo fmt
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -132,9 +132,10 @@ impl GameDownloadAgent {
|
|||||||
return chunk.lengths.iter().sum::<usize>();
|
return chunk.lengths.iter().sum::<usize>();
|
||||||
})
|
})
|
||||||
.sum::<usize>();
|
.sum::<usize>();
|
||||||
let chunk_count = manifest_download.iter().map(|(_, chunk)| {
|
let chunk_count = manifest_download
|
||||||
chunk.lengths.len()
|
.values()
|
||||||
}).sum();
|
.map(|chunk| chunk.lengths.len())
|
||||||
|
.sum();
|
||||||
self.progress = ProgressObject::new(length.try_into().unwrap(), chunk_count);
|
self.progress = ProgressObject::new(length.try_into().unwrap(), chunk_count);
|
||||||
|
|
||||||
if let Ok(mut manifest) = self.manifest.lock() {
|
if let Ok(mut manifest) = self.manifest.lock() {
|
||||||
|
|||||||
@ -75,13 +75,13 @@ impl DropDownloadPipeline<Response, File> {
|
|||||||
progress: Arc<AtomicUsize>,
|
progress: Arc<AtomicUsize>,
|
||||||
size: usize,
|
size: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
return Self {
|
Self {
|
||||||
source,
|
source,
|
||||||
destination,
|
destination,
|
||||||
control_flag,
|
control_flag,
|
||||||
progress,
|
progress,
|
||||||
size,
|
size,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy(&mut self) -> Result<bool, io::Error> {
|
fn copy(&mut self) -> Result<bool, io::Error> {
|
||||||
@ -99,10 +99,8 @@ impl DropDownloadPipeline<Response, File> {
|
|||||||
current_size += bytes_read;
|
current_size += bytes_read;
|
||||||
|
|
||||||
buf_writer.write_all(©_buf[0..bytes_read])?;
|
buf_writer.write_all(©_buf[0..bytes_read])?;
|
||||||
self.progress.fetch_add(
|
self.progress
|
||||||
bytes_read.try_into().unwrap(),
|
.fetch_add(bytes_read, std::sync::atomic::Ordering::Relaxed);
|
||||||
std::sync::atomic::Ordering::Relaxed,
|
|
||||||
);
|
|
||||||
|
|
||||||
if current_size == self.size {
|
if current_size == self.size {
|
||||||
break;
|
break;
|
||||||
@ -114,7 +112,7 @@ impl DropDownloadPipeline<Response, File> {
|
|||||||
|
|
||||||
fn finish(self) -> Result<Digest, io::Error> {
|
fn finish(self) -> Result<Digest, io::Error> {
|
||||||
let checksum = self.destination.finish()?;
|
let checksum = self.destination.finish()?;
|
||||||
return Ok(checksum);
|
Ok(checksum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,5 +185,5 @@ pub fn download_game_chunk(
|
|||||||
return Err(GameDownloadError::ChecksumError);
|
return Err(GameDownloadError::ChecksumError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(true);
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ impl From<bool> for DownloadThreadControlFlag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DownloadThreadControl {
|
pub struct DownloadThreadControl {
|
||||||
inner: Arc<AtomicBool>,
|
inner: Arc<AtomicBool>,
|
||||||
|
|||||||
@ -3,4 +3,4 @@ pub mod download_commands;
|
|||||||
mod download_logic;
|
mod download_logic;
|
||||||
mod download_thread_control_flag;
|
mod download_thread_control_flag;
|
||||||
mod manifest;
|
mod manifest;
|
||||||
mod progress_object;
|
mod progress_object;
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use std::sync::{atomic::{AtomicUsize, Ordering}, Arc};
|
use std::sync::{
|
||||||
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ProgressObject {
|
pub struct ProgressObject {
|
||||||
@ -8,16 +11,17 @@ pub struct ProgressObject {
|
|||||||
|
|
||||||
impl ProgressObject {
|
impl ProgressObject {
|
||||||
pub fn new(max: usize, length: usize) -> Self {
|
pub fn new(max: usize, length: usize) -> Self {
|
||||||
let arr = (0..length).map(|_| { Arc::new(AtomicUsize::new(0)) }).collect();
|
let arr = (0..length).map(|_| Arc::new(AtomicUsize::new(0))).collect();
|
||||||
Self {
|
Self {
|
||||||
max,
|
max,
|
||||||
progress_instances: Arc::new(arr)
|
progress_instances: Arc::new(arr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn sum(&self) -> usize {
|
pub fn sum(&self) -> usize {
|
||||||
self.progress_instances.iter().map(|instance| {
|
self.progress_instances
|
||||||
instance.load(Ordering::Relaxed)
|
.iter()
|
||||||
}).sum()
|
.map(|instance| instance.load(Ordering::Relaxed))
|
||||||
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_progress(&self) -> f64 {
|
pub fn get_progress(&self) -> f64 {
|
||||||
@ -26,4 +30,4 @@ impl ProgressObject {
|
|||||||
pub fn get(&self, index: usize) -> Arc<AtomicUsize> {
|
pub fn get(&self, index: usize) -> Arc<AtomicUsize> {
|
||||||
self.progress_instances[index].clone()
|
self.progress_instances[index].clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user