diff --git a/src-tauri/src/error/remote_access_error.rs b/src-tauri/src/error/remote_access_error.rs index 6717c6e..6f12508 100644 --- a/src-tauri/src/error/remote_access_error.rs +++ b/src-tauri/src/error/remote_access_error.rs @@ -18,6 +18,7 @@ pub enum RemoteAccessError { HandshakeFailed(String), GameNotFound(String), InvalidResponse(DropServerError), + UnparseableResponse(String), ManifestDownloadFailed(StatusCode, String), OutOfSync, Cache(cacache::Error), @@ -48,7 +49,8 @@ impl Display for RemoteAccessError { RemoteAccessError::InvalidEndpoint => write!(f, "invalid drop endpoint"), RemoteAccessError::HandshakeFailed(message) => write!(f, "failed to complete handshake: {message}"), RemoteAccessError::GameNotFound(id) => write!(f, "could not find game on server: {id}"), - RemoteAccessError::InvalidResponse(error) => write!(f, "server returned an invalid response: {} {}", error.status_code, error.status_message), + RemoteAccessError::InvalidResponse(error) => write!(f, "server returned an invalid response: {}, {}", error.status_code, error.status_message), + RemoteAccessError::UnparseableResponse(error) => write!(f, "server returned an invalid response: {}", error), RemoteAccessError::ManifestDownloadFailed(status, response) => write!( f, "failed to download game manifest: {status} {response}" diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs index 1bbd85a..7a452cb 100644 --- a/src-tauri/src/games/downloads/download_agent.rs +++ b/src-tauri/src/games/downloads/download_agent.rs @@ -313,18 +313,9 @@ impl GameDownloadAgent { match download_game_chunk(context, &self.control_flag, progress_handle, request) { Ok(true) => { - debug!( - "Finished context #{} with checksum {}", - index, context.checksum - ); completed_indexes.push(context.checksum.clone()); } - Ok(false) => { - debug!( - "Didn't finish context #{} with checksum {}", - index, context.checksum - ); - } + Ok(false) => {} Err(e) => { error!("{e}"); sender.send(DownloadManagerSignal::Error(e)).unwrap(); @@ -350,10 +341,7 @@ impl GameDownloadAgent { .map(|x| { ( x.checksum.clone(), - context_map_lock - .get(&x.checksum) - .cloned() - .unwrap_or(false), + context_map_lock.get(&x.checksum).cloned().unwrap_or(false), ) }) .collect::>(); diff --git a/src-tauri/src/games/downloads/download_logic.rs b/src-tauri/src/games/downloads/download_logic.rs index 69473e0..55ea715 100644 --- a/src-tauri/src/games/downloads/download_logic.rs +++ b/src-tauri/src/games/downloads/download_logic.rs @@ -1,12 +1,14 @@ +use crate::client; use crate::download_manager::util::download_thread_control_flag::{ DownloadThreadControl, DownloadThreadControlFlag, }; use crate::download_manager::util::progress_object::ProgressHandle; use crate::error::application_download_error::ApplicationDownloadError; +use crate::error::drop_server_error::DropServerError; use crate::error::remote_access_error::RemoteAccessError; use crate::games::downloads::manifest::DropDownloadContext; use crate::remote::auth::generate_authorization_header; -use log::{debug, warn}; +use log::{debug, info, warn}; use md5::{Context, Digest}; use reqwest::blocking::{RequestBuilder, Response}; @@ -40,11 +42,9 @@ impl DropWriter { // Write automatically pushes to file and hasher impl Write for DropWriter { fn write(&mut self, buf: &[u8]) -> io::Result { - self.hasher.write_all(buf).map_err(|e| { - io::Error::other( - format!("Unable to write to hasher: {e}"), - ) - })?; + self.hasher + .write_all(buf) + .map_err(|e| io::Error::other(format!("Unable to write to hasher: {e}")))?; self.destination.write(buf) } @@ -134,17 +134,11 @@ pub fn download_game_chunk( progress: ProgressHandle, request: RequestBuilder, ) -> Result { - debug!( - "Starting download chunk {}, {}, {} #{}", - ctx.file_name, ctx.index, ctx.offset, ctx.checksum - ); // If we're paused if control_flag.get() == DownloadThreadControlFlag::Stop { progress.set(0); return Ok(false); } - let request = request.header("Authorization", generate_authorization_header()); - let response = request .header("Authorization", generate_authorization_header()) .send() @@ -152,9 +146,14 @@ pub fn download_game_chunk( if response.status() != 200 { debug!("chunk request got status code: {}", response.status()); - let err = response.json().unwrap(); + let raw_res = response.text().unwrap(); + if let Some(err) = serde_json::from_str::(&raw_res).ok() { + return Err(ApplicationDownloadError::Communication( + RemoteAccessError::InvalidResponse(err), + )); + }; return Err(ApplicationDownloadError::Communication( - RemoteAccessError::InvalidResponse(err), + RemoteAccessError::UnparseableResponse(raw_res), )); }