mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 08:12:44 +10:00
Download fixes (#63)
* refactor: Rename StoredManifest to DropData Signed-off-by: quexeky <git@quexeky.dev> * fix: Downloads when resuming would truncate files which had not been finished Signed-off-by: quexeky <git@quexeky.dev> * chore: Didn't import debug macro Signed-off-by: quexeky <git@quexeky.dev> * fix: Download chunks with wrong indexes Migrated to using checksums as indexes instead Signed-off-by: quexeky <git@quexeky.dev> * feat: Resume download button Also added DBWrite and DBRead structs to make database management easier Signed-off-by: quexeky <git@quexeky.dev> * feat: Download resuming Signed-off-by: quexeky <git@quexeky.dev> * feat: Resume button and PartiallyInstalled status Signed-off-by: quexeky <git@quexeky.dev> * feat: Download validation Signed-off-by: quexeky <git@quexeky.dev> * chore: Ran cargo fix & cargo fmt Signed-off-by: quexeky <git@quexeky.dev> * fix: download validation, installs, etc * chore: version bump --------- Signed-off-by: quexeky <git@quexeky.dev> Co-authored-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
download_manager::{
|
||||
download_manager::DownloadManagerSignal, downloadable::Downloadable,
|
||||
}, error::download_manager_error::DownloadManagerError, AppState
|
||||
database::{db::borrow_db_checked, models::data::GameDownloadStatus},
|
||||
download_manager::{download_manager::DownloadManagerSignal, downloadable::Downloadable},
|
||||
error::download_manager_error::DownloadManagerError,
|
||||
AppState,
|
||||
};
|
||||
|
||||
use super::download_agent::GameDownloadAgent;
|
||||
@ -16,7 +20,7 @@ pub fn download_game(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
) -> Result<(), DownloadManagerError<DownloadManagerSignal>> {
|
||||
let sender = state.lock().unwrap().download_manager.get_sender();
|
||||
let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new(
|
||||
let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new_from_index(
|
||||
game_id,
|
||||
game_version,
|
||||
install_dir,
|
||||
@ -28,3 +32,39 @@ pub fn download_game(
|
||||
.download_manager
|
||||
.queue_download(game_download_agent)?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn resume_download(
|
||||
game_id: String,
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
) -> Result<(), DownloadManagerError<DownloadManagerSignal>> {
|
||||
let s = borrow_db_checked()
|
||||
.applications
|
||||
.game_statuses
|
||||
.get(&game_id)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let (version_name, install_dir) = match s {
|
||||
GameDownloadStatus::Remote {} => unreachable!(),
|
||||
GameDownloadStatus::SetupRequired { .. } => unreachable!(),
|
||||
GameDownloadStatus::Installed { .. } => unreachable!(),
|
||||
GameDownloadStatus::PartiallyInstalled {
|
||||
version_name,
|
||||
install_dir,
|
||||
} => (version_name, install_dir),
|
||||
};
|
||||
let sender = state.lock().unwrap().download_manager.get_sender();
|
||||
let parent_dir: PathBuf = install_dir.into();
|
||||
let game_download_agent = Arc::new(Box::new(GameDownloadAgent::new(
|
||||
game_id,
|
||||
version_name.clone(),
|
||||
parent_dir.parent().unwrap().to_path_buf(),
|
||||
sender,
|
||||
)) as Box<dyn Downloadable + Send + Sync>);
|
||||
Ok(state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.download_manager
|
||||
.queue_download(game_download_agent)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user