mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 16:22:43 +10:00
refactor(downloads): Scoping changes and removing qualifications
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -95,11 +95,12 @@ pub async fn stop_specific_game_download(
|
|||||||
game_id: String,
|
game_id: String,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
info!("called stop_specific_game_download");
|
info!("called stop_specific_game_download");
|
||||||
|
let callback = {
|
||||||
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();
|
||||||
|
download_agent.callback.clone()
|
||||||
|
};
|
||||||
|
|
||||||
let callback = download_agent.callback.clone();
|
|
||||||
drop(lock);
|
|
||||||
|
|
||||||
info!("Stopping callback");
|
info!("Stopping callback");
|
||||||
callback.store(true, Ordering::Release);
|
callback.store(true, Ordering::Release);
|
||||||
@ -118,3 +119,19 @@ pub async fn get_game_download_progress(
|
|||||||
info!("{}", progress);
|
info!("{}", progress);
|
||||||
Ok(progress)
|
Ok(progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#[tauri::command]
|
||||||
|
async fn resume_game_download(
|
||||||
|
state: tauri::State<'_, Mutex<AppState>>,
|
||||||
|
game_id: String,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
|
||||||
|
let download = {
|
||||||
|
let lock = state.lock().unwrap();
|
||||||
|
lock.game_downloads.get(&game_id).unwrap().clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
*/
|
||||||
@ -38,7 +38,7 @@ impl DropFileWriter {
|
|||||||
}
|
}
|
||||||
// TODO: Implement error handling
|
// TODO: Implement error handling
|
||||||
impl Write for DropFileWriter {
|
impl Write for DropFileWriter {
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||||
if self.callback.load(Ordering::Acquire) {
|
if self.callback.load(Ordering::Acquire) {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
ErrorKind::ConnectionAborted,
|
ErrorKind::ConnectionAborted,
|
||||||
@ -53,13 +53,13 @@ impl Write for DropFileWriter {
|
|||||||
self.file.write(buf)
|
self.file.write(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&mut self) -> std::io::Result<()> {
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
self.hasher.flush()?;
|
self.hasher.flush()?;
|
||||||
self.file.flush()
|
self.file.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Seek for DropFileWriter {
|
impl Seek for DropFileWriter {
|
||||||
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
|
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||||
self.file.seek(pos)
|
self.file.seek(pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,18 +101,19 @@ pub fn download_game_chunk(
|
|||||||
.expect("Failed to seek to file offset");
|
.expect("Failed to seek to file offset");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing everything to disk directly is probably slightly faster because it balances out the writes,
|
// Writing everything to disk directly is probably slightly faster in terms of disk
|
||||||
// but this is better than the performance loss from constantly reading the callbacks
|
// speed because it balances out the writes, but this is better than the performance
|
||||||
|
// loss from constantly reading the callbacks
|
||||||
|
|
||||||
let mut writer = BufWriter::with_capacity(1024 * 1024, file);
|
let mut writer = BufWriter::with_capacity(1024 * 1024, file);
|
||||||
|
|
||||||
//copy_to_drop_file_writer(&mut response, &mut file);
|
|
||||||
match io::copy(&mut response, &mut writer) {
|
match io::copy(&mut response, &mut writer) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("Copy errored with error {}", e)
|
info!("Copy errored with error {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
writer.flush().unwrap();
|
||||||
let file = match writer.into_inner() {
|
let file = match writer.into_inner() {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -129,5 +130,4 @@ pub fn download_game_chunk(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stream.flush().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user