diff --git a/desktop/src-tauri/src/database/db.rs b/desktop/src-tauri/src/database/db.rs index 06a77f0a..b92de3d3 100644 --- a/desktop/src-tauri/src/database/db.rs +++ b/desktop/src-tauri/src/database/db.rs @@ -57,13 +57,23 @@ pub enum ApplicationTransientStatus { #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct GameVersion { - pub version_index: usize, + pub game_id: String, pub version_name: String, + + pub platform: Platform, + pub launch_command: String, pub launch_args: Vec, + pub setup_command: String, pub setup_args: Vec, - pub platform: Platform, + + pub only_setup: bool, + + pub version_index: usize, + pub delta: bool, + + pub umu_id_override: Option, } #[serde_as] diff --git a/desktop/src-tauri/src/games/commands.rs b/desktop/src-tauri/src/games/commands.rs index f0e3f5d8..8f1d6524 100644 --- a/desktop/src-tauri/src/games/commands.rs +++ b/desktop/src-tauri/src/games/commands.rs @@ -3,15 +3,13 @@ use std::sync::Mutex; use tauri::AppHandle; use crate::{ - error::{library_error::LibraryError, remote_access_error::RemoteAccessError}, - games::library::{get_current_meta, uninstall_game_logic}, - AppState, + database::db::GameVersion, error::{library_error::LibraryError, remote_access_error::RemoteAccessError}, games::library::{get_current_meta, uninstall_game_logic}, AppState }; use super::{ library::{ fetch_game_logic, fetch_game_verion_options_logic, fetch_library_logic, FetchGameStruct, - Game, GameVersionOption, + Game, }, state::{GameStatusManager, GameStatusWithTransient}, }; @@ -50,6 +48,6 @@ pub fn uninstall_game(game_id: String, app_handle: AppHandle) -> Result<(), Libr pub fn fetch_game_verion_options( game_id: String, state: tauri::State<'_, Mutex>, -) -> Result, RemoteAccessError> { +) -> Result, RemoteAccessError> { fetch_game_verion_options_logic(game_id, state) } diff --git a/desktop/src-tauri/src/games/library.rs b/desktop/src-tauri/src/games/library.rs index bf0575fc..b2f2fe25 100644 --- a/desktop/src-tauri/src/games/library.rs +++ b/desktop/src-tauri/src/games/library.rs @@ -6,18 +6,16 @@ use log::{debug, error, warn}; use serde::{Deserialize, Serialize}; use tauri::Emitter; use tauri::{AppHandle, Manager}; -use urlencoding::encode; use crate::database::db::{borrow_db_checked, borrow_db_mut_checked, save_db, GameVersion}; -use crate::database::db::{ApplicationTransientStatus, DatabaseImpls, GameDownloadStatus}; +use crate::database::db::{ApplicationTransientStatus, GameDownloadStatus}; use crate::download_manager::download_manager::DownloadStatus; use crate::download_manager::downloadable_metadata::DownloadableMetadata; use crate::error::remote_access_error::RemoteAccessError; use crate::games::state::{GameStatusManager, GameStatusWithTransient}; -use crate::process::process_manager::Platform; use crate::remote::auth::generate_authorization_header; use crate::remote::requests::make_request; -use crate::{AppState, DB}; +use crate::AppState; #[derive(serde::Serialize)] pub struct FetchGameStruct { @@ -68,30 +66,6 @@ pub struct StatsUpdateEvent { pub time: usize, } -// Game version with some fields missing and size information -#[derive(serde::Deserialize, serde::Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GameVersionOption { - game_id: String, - version_name: String, - - platform: Platform, - - launch_command: String, - launch_args: Vec, - - setup_command: String, - setup_args: Vec, - - only_setup: bool, - - version_index: usize, - delta: bool, - - umu_id_override: Option, - // total_size: usize, -} - pub fn fetch_library_logic(app: AppHandle) -> Result, RemoteAccessError> { let header = generate_authorization_header(); @@ -187,7 +161,7 @@ pub fn fetch_game_logic( pub fn fetch_game_verion_options_logic( game_id: String, state: tauri::State<'_, Mutex>, -) -> Result, RemoteAccessError> { +) -> Result, RemoteAccessError> { let client = reqwest::blocking::Client::new(); let response = make_request( @@ -204,11 +178,11 @@ pub fn fetch_game_verion_options_logic( return Err(RemoteAccessError::InvalidResponse(err)); } - let data: Vec = response.json()?; + let data: Vec = response.json()?; let state_lock = state.lock().unwrap(); let process_manager_lock = state_lock.process_manager.lock().unwrap(); - let data: Vec = data + let data: Vec = data .into_iter() .filter(|v| process_manager_lock.valid_platform(&v.platform).unwrap()) .collect(); diff --git a/desktop/src-tauri/src/process/process_manager.rs b/desktop/src-tauri/src/process/process_manager.rs index 420405bc..28686446 100644 --- a/desktop/src-tauri/src/process/process_manager.rs +++ b/desktop/src-tauri/src/process/process_manager.rs @@ -16,7 +16,7 @@ use umu_wrapper_lib::command_builder::UmuCommandBuilder; use crate::{ database::db::{ - borrow_db_mut_checked, ApplicationTransientStatus, GameDownloadStatus, DATA_ROOT_DIR, + borrow_db_mut_checked, ApplicationTransientStatus, GameDownloadStatus, GameVersion, DATA_ROOT_DIR }, download_manager::downloadable_metadata::{DownloadType, DownloadableMetadata}, error::process_error::ProcessError, @@ -66,10 +66,6 @@ impl ProcessManager<'_> { } } - // There's no easy way to distinguish between an executable name with - // spaces and it's arguments. - // I think if we just join the install_dir to whatever the user provides us, we'll be alright - // In future, we should have a separate field for executable name and it's arguments fn process_command(&self, install_dir: &String, command: Vec) -> (PathBuf, Vec) { let root = &command[0]; @@ -194,11 +190,7 @@ impl ProcessManager<'_> { GameDownloadStatus::Installed { version_name, install_dir, -<<<<<<< Updated upstream - } => Some((version_name, install_dir)), -======= } => (version_name, install_dir), ->>>>>>> Stashed changes GameDownloadStatus::SetupRequired { version_name, install_dir, @@ -222,18 +214,19 @@ impl ProcessManager<'_> { version_name: _, install_dir: _, } => { - command.extend_one(game_version.launch_command); - command.extend(game_version.launch_args); + command.extend([game_version.launch_command.clone()]); + command.extend(game_version.launch_args.clone()); }, GameDownloadStatus::SetupRequired { version_name: _, install_dir: _, } => { - command.extend_one(game_version.setup_command); - command.extend(game_version.setup_args); + command.extend([game_version.setup_command.clone()]); + command.extend(game_version.setup_args.clone()); }, _ => panic!("unreachable code"), }; + info!("Command: {:?}", &command); let (command, args) = self.process_command(install_dir, command); @@ -283,8 +276,7 @@ impl ProcessManager<'_> { let launch_process = game_launcher .launch_process( &meta, - command.to_str().unwrap().to_owned(), - args, + game_version, target_current_dir, log_file, error_file, @@ -339,8 +331,7 @@ pub trait ProcessHandler: Send + 'static { fn launch_process( &self, meta: &DownloadableMetadata, - command: String, - args: Vec, + game_version: &GameVersion, current_dir: &str, log_file: File, error_file: File, @@ -352,17 +343,16 @@ impl ProcessHandler for NativeGameLauncher { fn launch_process( &self, _meta: &DownloadableMetadata, - command: String, - args: Vec, + game_version: &GameVersion, current_dir: &str, log_file: File, error_file: File, ) -> Result { - Command::new(command) + Command::new(game_version.launch_command.clone()) .current_dir(current_dir) .stdout(log_file) .stderr(error_file) - .args(args) + .args(game_version.launch_args.clone()) .spawn() } } @@ -373,15 +363,14 @@ impl ProcessHandler for UMULauncher { fn launch_process( &self, _meta: &DownloadableMetadata, - command: String, - args: Vec, + game_version: &GameVersion, _current_dir: &str, _log_file: File, _error_file: File, ) -> Result { - UmuCommandBuilder::new(UMU_LAUNCHER_EXECUTABLE, command) - .game_id(String::from("0")) - .launch_args(args) + UmuCommandBuilder::new(UMU_LAUNCHER_EXECUTABLE, game_version.launch_command.clone()) + .game_id(String::from(game_version.umu_id_override.clone().unwrap_or(game_version.game_id.clone()))) + .launch_args(game_version.launch_args.clone()) .build() .spawn() }