From ece79e4306969f4ba33ab7d6df03c2e789dd2826 Mon Sep 17 00:00:00 2001 From: quexeky Date: Tue, 31 Dec 2024 12:53:31 +1100 Subject: [PATCH] refactor(download manager): Moved manifest and stored_manifest to download_manager Signed-off-by: quexeky --- .../download_logic.rs | 3 +- .../manifest.rs | 0 desktop/src-tauri/src/download_manager/mod.rs | 5 ++- .../stored_manifest.rs | 0 .../src-tauri/src/downloads/download_agent.rs | 18 ++++----- desktop/src-tauri/src/downloads/mod.rs | 3 -- .../src-tauri/src/tools/external_component.rs | 8 ---- desktop/src-tauri/src/tools/mod.rs | 1 - desktop/src-tauri/src/tools/registry.rs | 5 ++- desktop/src-tauri/src/tools/tool.rs | 40 +++++++++++++------ 10 files changed, 46 insertions(+), 37 deletions(-) rename desktop/src-tauri/src/{downloads => download_manager}/download_logic.rs (99%) rename desktop/src-tauri/src/{downloads => download_manager}/manifest.rs (100%) rename desktop/src-tauri/src/{downloads => download_manager}/stored_manifest.rs (100%) delete mode 100644 desktop/src-tauri/src/tools/external_component.rs diff --git a/desktop/src-tauri/src/downloads/download_logic.rs b/desktop/src-tauri/src/download_manager/download_logic.rs similarity index 99% rename from desktop/src-tauri/src/downloads/download_logic.rs rename to desktop/src-tauri/src/download_manager/download_logic.rs index de0f6159..43622347 100644 --- a/desktop/src-tauri/src/downloads/download_logic.rs +++ b/desktop/src-tauri/src/download_manager/download_logic.rs @@ -3,7 +3,6 @@ use crate::db::DatabaseImpls; use crate::download_manager::application_download_error::ApplicationDownloadError; use crate::download_manager::download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag}; use crate::download_manager::progress_object::ProgressHandle; -use crate::downloads::manifest::DropDownloadContext; use crate::remote::RemoteAccessError; use crate::DB; use http::StatusCode; @@ -22,6 +21,8 @@ use std::{ }; use urlencoding::encode; +use super::manifest::DropDownloadContext; + pub struct DropWriter { hasher: Context, destination: W, diff --git a/desktop/src-tauri/src/downloads/manifest.rs b/desktop/src-tauri/src/download_manager/manifest.rs similarity index 100% rename from desktop/src-tauri/src/downloads/manifest.rs rename to desktop/src-tauri/src/download_manager/manifest.rs diff --git a/desktop/src-tauri/src/download_manager/mod.rs b/desktop/src-tauri/src/download_manager/mod.rs index 66e7d9d3..0eb77882 100644 --- a/desktop/src-tauri/src/download_manager/mod.rs +++ b/desktop/src-tauri/src/download_manager/mod.rs @@ -4,4 +4,7 @@ pub mod progress_object; pub mod queue; pub mod download_thread_control_flag; pub mod downloadable; -pub mod application_download_error; \ No newline at end of file +pub mod application_download_error; +pub mod download_logic; +pub mod manifest; +pub mod stored_manifest; \ No newline at end of file diff --git a/desktop/src-tauri/src/downloads/stored_manifest.rs b/desktop/src-tauri/src/download_manager/stored_manifest.rs similarity index 100% rename from desktop/src-tauri/src/downloads/stored_manifest.rs rename to desktop/src-tauri/src/download_manager/stored_manifest.rs diff --git a/desktop/src-tauri/src/downloads/download_agent.rs b/desktop/src-tauri/src/downloads/download_agent.rs index df0b3cac..3c38b4e5 100644 --- a/desktop/src-tauri/src/downloads/download_agent.rs +++ b/desktop/src-tauri/src/downloads/download_agent.rs @@ -1,11 +1,13 @@ use crate::auth::generate_authorization_header; use crate::db::DatabaseImpls; use crate::download_manager::application_download_error::ApplicationDownloadError; +use crate::download_manager::download_logic::download_game_chunk; use crate::download_manager::download_manager::DownloadManagerSignal; use crate::download_manager::download_thread_control_flag::{DownloadThreadControl, DownloadThreadControlFlag}; use crate::download_manager::downloadable::Downloadable; +use crate::download_manager::manifest::{DropDownloadContext, DropManifest}; use crate::download_manager::progress_object::{ProgressHandle, ProgressObject}; -use crate::downloads::manifest::{DropDownloadContext, DropManifest}; +use crate::download_manager::stored_manifest::StoredManifest; use crate::remote::RemoteAccessError; use crate::DB; use log::{debug, error, info}; @@ -21,19 +23,17 @@ use urlencoding::encode; #[cfg(target_os = "linux")] use rustix::fs::{fallocate, FallocateFlags}; -use super::download_logic::download_game_chunk; -use super::stored_manifest::StoredManifest; pub struct GameDownloadAgent { - pub id: String, - pub version: String, - pub control_flag: DownloadThreadControl, + id: String, + version: String, + control_flag: DownloadThreadControl, contexts: Vec, completed_contexts: VecDeque, - pub manifest: Mutex>, - pub progress: Arc, + manifest: Mutex>, + progress: Arc, sender: Sender, - pub stored_manifest: StoredManifest, + stored_manifest: StoredManifest, } diff --git a/desktop/src-tauri/src/downloads/mod.rs b/desktop/src-tauri/src/downloads/mod.rs index 8709ca6b..5948b1bb 100644 --- a/desktop/src-tauri/src/downloads/mod.rs +++ b/desktop/src-tauri/src/downloads/mod.rs @@ -1,5 +1,2 @@ pub mod download_agent; pub mod download_commands; -mod download_logic; -mod manifest; -mod stored_manifest; diff --git a/desktop/src-tauri/src/tools/external_component.rs b/desktop/src-tauri/src/tools/external_component.rs deleted file mode 100644 index 2aec4b7c..00000000 --- a/desktop/src-tauri/src/tools/external_component.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::path::PathBuf; - -pub trait ExternalComponent { - fn download(&mut self); - fn version(&self) -> &String; - fn is_installed(&self) -> bool; - fn location(&self) -> &Option; -} \ No newline at end of file diff --git a/desktop/src-tauri/src/tools/mod.rs b/desktop/src-tauri/src/tools/mod.rs index 6b8f4133..960f1321 100644 --- a/desktop/src-tauri/src/tools/mod.rs +++ b/desktop/src-tauri/src/tools/mod.rs @@ -1,4 +1,3 @@ -mod external_component; mod prefix; mod registry; mod tool; \ No newline at end of file diff --git a/desktop/src-tauri/src/tools/registry.rs b/desktop/src-tauri/src/tools/registry.rs index c1b000fb..182c90f4 100644 --- a/desktop/src-tauri/src/tools/registry.rs +++ b/desktop/src-tauri/src/tools/registry.rs @@ -1,7 +1,8 @@ use std::collections::HashMap; -use super::external_component::ExternalComponent; +use crate::download_manager::downloadable::Downloadable; -pub struct Registry { + +pub struct Registry { tools: HashMap } diff --git a/desktop/src-tauri/src/tools/tool.rs b/desktop/src-tauri/src/tools/tool.rs index 6fab0251..0fb60110 100644 --- a/desktop/src-tauri/src/tools/tool.rs +++ b/desktop/src-tauri/src/tools/tool.rs @@ -1,26 +1,42 @@ -use std::path::PathBuf; +use std::{path::PathBuf, sync::Arc}; -use super::external_component::ExternalComponent; +use rustix::path::Arg; -pub struct Tool { - name: String, +use crate::download_manager::{download_thread_control_flag::DownloadThreadControl, downloadable::Downloadable, progress_object::ProgressObject}; + +pub struct ToolDownloader { + id: String, version: String, location: Option, + progress: Arc, + control_flag: DownloadThreadControl } -impl ExternalComponent for Tool { - fn download(&mut self) { +impl Downloadable for ToolDownloader { + fn get_progress_object(&self) -> std::sync::Arc { todo!() } - fn version(&self) -> &String { - &self.version + fn version(&self) -> String { + self.version.clone() } - fn is_installed(&self) -> bool { - self.location.is_some() + fn id(&self) -> String { + self.id.clone() } - fn location(&self) -> &Option { - &self.location + fn download(&mut self) -> Result<(), crate::download_manager::application_download_error::ApplicationDownloadError> { + todo!() + } + + fn progress(&self) -> Arc { + self.progress.clone() + } + + fn control_flag(&self) -> DownloadThreadControl { + self.control_flag.clone() + } + + fn install_dir(&self) -> String { + self.location.clone().unwrap().to_string_lossy().to_string() } } \ No newline at end of file