feat(install ui): ui to install games

This commit is contained in:
DecDuck
2024-12-06 22:16:50 +11:00
parent b5568429f5
commit 8670bca834
11 changed files with 436 additions and 25 deletions

View File

@ -172,7 +172,6 @@ impl GameDownloadAgent {
pub fn ensure_contexts(&self) -> Result<(), GameDownloadError> {
let context_lock = self.contexts.lock().unwrap();
info!("{:?} {}", context_lock, context_lock.is_empty());
if !context_lock.is_empty() {
return Ok(());
}
@ -209,7 +208,7 @@ impl GameDownloadAgent {
for (i, length) in chunk.lengths.iter().enumerate() {
contexts.push(DropDownloadContext {
file_name: raw_path.to_string(),
version: version.to_string(),
version: chunk.versionName.to_string(),
offset: running_offset,
index: i,
game_id: game_id.to_string(),

View File

@ -8,13 +8,14 @@ use crate::AppState;
pub fn download_game(
game_id: String,
game_version: String,
install_dir: usize,
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), String> {
state
.lock()
.unwrap()
.download_manager
.queue_game(game_id, game_version, 0)
.queue_game(game_id, game_version, install_dir)
.map_err(|_| "An error occurred while communicating with the download manager.".to_string())
}

View File

@ -3,7 +3,7 @@ use crate::db::DatabaseImpls;
use crate::downloads::manifest::DropDownloadContext;
use crate::remote::RemoteAccessError;
use crate::DB;
use log::info;
use log::{info, warn};
use md5::{Context, Digest};
use reqwest::blocking::Response;
@ -150,6 +150,13 @@ pub fn download_game_chunk(
.send()
.map_err(|e| GameDownloadError::Communication(e.into()))?;
if response.status() != 200 {
warn!("{}", response.text().unwrap());
return Err(GameDownloadError::Communication(
RemoteAccessError::InvalidCodeError(400),
));
}
let mut destination = DropWriter::new(ctx.path);
if ctx.offset != 0 {
@ -160,7 +167,9 @@ pub fn download_game_chunk(
let content_length = response.content_length();
if content_length.is_none() {
return Err(GameDownloadError::Communication(RemoteAccessError::InvalidResponse));
return Err(GameDownloadError::Communication(
RemoteAccessError::InvalidResponse,
));
}
let mut pipeline = DropDownloadPipeline::new(
@ -176,7 +185,9 @@ pub fn download_game_chunk(
return Ok(false);
};
let checksum = pipeline.finish().map_err(|e| GameDownloadError::IoError(e))?;
let checksum = pipeline
.finish()
.map_err(|e| GameDownloadError::IoError(e))?;
let res = hex::encode(checksum.0);
if res != ctx.checksum {

View File

@ -8,6 +8,7 @@ use std::{
};
use log::{error, info, warn};
use rustbreak::Database;
use tauri::{AppHandle, Emitter};
use crate::{db::DatabaseGameStatus, library::GameUpdateEvent, DB};
@ -247,6 +248,11 @@ impl DownloadManagerBuilder {
let mut lock = current_status.status.lock().unwrap();
*lock = GameDownloadStatus::Error;
self.set_status(DownloadManagerStatus::Error(error));
self.set_game_status(
self.current_game_interface.as_ref().unwrap().id.clone(),
DatabaseGameStatus::Remote,
);
}
fn manage_cancel_signal(&mut self, game_id: String) {
if let Some(current_flag) = &self.active_control_flag {

View File

@ -9,6 +9,7 @@ pub struct DropChunk {
pub ids: Vec<String>,
pub checksums: Vec<String>,
pub lengths: Vec<usize>,
pub versionName: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]