chore(tool manager): Added ToolDownloadAgent

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-12-31 13:18:00 +11:00
parent 78149bbb3c
commit a2e63aa2c8
6 changed files with 31 additions and 35 deletions

View File

@ -5,7 +5,6 @@ use super::{
};
pub trait Downloadable: Send + Sync {
fn get_progress_object(&self) -> Arc<ProgressObject>;
fn version(&self) -> String;
fn id(&self) -> String;
fn download(&mut self) -> Result<(), ApplicationDownloadError>;

View File

@ -296,10 +296,6 @@ impl GameDownloadAgent {
}
impl Downloadable for GameDownloadAgent {
fn get_progress_object(&self) -> Arc<ProgressObject> {
self.progress.clone()
}
fn id(&self) -> String {
self.id.clone()
}

View File

@ -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<PathBuf>;
}

View File

@ -1,4 +1,3 @@
mod external_component;
mod prefix;
mod registry;
mod tool;

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use super::external_component::ExternalComponent;
use crate::download_manager::downloadable::Downloadable;
pub struct Registry<T: ExternalComponent> {
pub struct Registry<T: Downloadable> {
tools: HashMap<String, T>
}

View File

@ -1,26 +1,36 @@
use std::path::PathBuf;
use std::sync::Arc;
use super::external_component::ExternalComponent;
use crate::download_manager::{download_thread_control_flag::DownloadThreadControl, downloadable::Downloadable, progress_object::ProgressObject};
pub struct Tool {
name: String,
pub struct ToolDownloadAgent {
id: String,
version: String,
location: Option<PathBuf>,
location: String,
control_flag: DownloadThreadControl,
progress: Arc<ProgressObject>,
}
impl ExternalComponent for Tool {
fn download(&mut self) {
impl Downloadable for ToolDownloadAgent {
fn id(&self) -> String {
self.id.clone()
}
fn progress(&self) -> Arc<ProgressObject> {
self.progress.clone()
}
fn control_flag(&self) -> DownloadThreadControl {
self.control_flag.clone()
}
fn install_dir(&self) -> String {
self.location.clone()
}
fn version(&self) -> String {
self.version.clone()
}
fn download(&mut self) -> Result<(), crate::download_manager::application_download_error::ApplicationDownloadError> {
todo!()
}
fn version(&self) -> &String {
&self.version
}
fn is_installed(&self) -> bool {
self.location.is_some()
}
fn location(&self) -> &Option<PathBuf> {
&self.location
}
}