Removed gxhash and ran cargo fmt

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-01 07:51:56 +11:00
parent 86363327a3
commit bd39f1fd72
15 changed files with 129 additions and 104 deletions

View File

@ -1,4 +1,7 @@
use std::{sync::{atomic::Ordering, Arc, Mutex}, thread};
use std::{
sync::{atomic::Ordering, Arc, Mutex},
thread,
};
use log::info;
@ -13,7 +16,10 @@ pub async fn queue_game_download(
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), GameDownloadError> {
info!("Queuing Game Download");
let download_agent = Arc::new(GameDownloadAgent::new(game_id.clone(), game_version.clone()));
let download_agent = Arc::new(GameDownloadAgent::new(
game_id.clone(),
game_version.clone(),
));
download_agent.queue().await?;
let mut queue = state.lock().unwrap();
@ -30,30 +36,28 @@ pub async fn start_game_downloads(
let lock = state.lock().unwrap();
let mut game_downloads = lock.game_downloads.clone();
drop(lock);
thread::spawn(move || {
loop {
let mut current_id = String::new();
let mut download_agent = None;
{
for (id, agent) in &game_downloads {
if agent.get_state() == GameDownloadState::Queued {
download_agent = Some(agent.clone());
current_id = id.clone();
info!("Got queued game to download");
break;
}
thread::spawn(move || loop {
let mut current_id = String::new();
let mut download_agent = None;
{
for (id, agent) in &game_downloads {
if agent.get_state() == GameDownloadState::Queued {
download_agent = Some(agent.clone());
current_id = id.clone();
info!("Got queued game to download");
break;
}
if download_agent.is_none() {
info!("No more games left to download");
return;
}
};
info!("Downloading game");
{
start_game_download(max_threads, download_agent.unwrap()).unwrap();
game_downloads.remove_entry(&current_id);
}
}
if download_agent.is_none() {
info!("No more games left to download");
return;
}
};
info!("Downloading game");
{
start_game_download(max_threads, download_agent.unwrap()).unwrap();
game_downloads.remove_entry(&current_id);
}
});
info!("Spawned download");
Ok(())
@ -61,11 +65,10 @@ pub async fn start_game_downloads(
pub fn start_game_download(
max_threads: usize,
download_agent: Arc<GameDownloadAgent>
download_agent: Arc<GameDownloadAgent>,
) -> Result<(), GameDownloadError> {
info!("Triggered Game Download");
download_agent.ensure_manifest_exists()?;
let local_manifest = {
@ -73,7 +76,13 @@ pub fn start_game_download(
(*manifest).clone().unwrap()
};
download_agent.generate_job_contexts(&local_manifest, download_agent.version.clone(), download_agent.id.clone()).unwrap();
download_agent
.generate_job_contexts(
&local_manifest,
download_agent.version.clone(),
download_agent.id.clone(),
)
.unwrap();
download_agent.begin_download(max_threads).unwrap();
@ -81,7 +90,10 @@ pub fn start_game_download(
}
#[tauri::command]
pub async fn stop_specific_game_download(state: tauri::State<'_, Mutex<AppState>>, game_id: String) -> Result<(), String> {
pub async fn stop_specific_game_download(
state: tauri::State<'_, Mutex<AppState>>,
game_id: String,
) -> Result<(), String> {
info!("called stop_specific_game_download");
let lock = state.lock().unwrap();
let download_agent = lock.game_downloads.get(&game_id).unwrap();
@ -93,4 +105,4 @@ pub async fn stop_specific_game_download(state: tauri::State<'_, Mutex<AppState>
callback.store(true, Ordering::Release);
Ok(())
}
}