feat(game): game uninstalling & partial compat

This commit is contained in:
DecDuck
2024-12-26 11:59:26 +11:00
parent 9ea2aa4997
commit dd7f5675d8
26 changed files with 469 additions and 96 deletions

View File

@ -0,0 +1,51 @@
use std::{
fs::create_dir_all,
path::PathBuf,
sync::atomic::{AtomicBool, Ordering},
};
use crate::db::DATA_ROOT_DIR;
pub struct CompatibilityManager {
compat_tools_path: PathBuf,
prefixes_path: PathBuf,
created_paths: AtomicBool,
}
/*
This gets built into both the Windows & Linux client, but
we only need it in the Linux client. Therefore, it should
do nothing but take a little bit of memory if we're on
Windows.
*/
impl CompatibilityManager {
pub fn new() -> Self {
let root_dir_lock = DATA_ROOT_DIR.lock().unwrap();
let compat_tools_path = root_dir_lock.join("compatibility_tools");
let prefixes_path = root_dir_lock.join("prefixes");
drop(root_dir_lock);
Self {
compat_tools_path,
prefixes_path,
created_paths: AtomicBool::new(false),
}
}
fn ensure_paths_exist(&self) -> Result<(), String> {
if self.created_paths.fetch_and(true, Ordering::Relaxed) {
return Ok(());
}
if !self.compat_tools_path.exists() {
create_dir_all(self.compat_tools_path.clone()).map_err(|e| e.to_string())?;
}
if !self.prefixes_path.exists() {
create_dir_all(self.prefixes_path.clone()).map_err(|e| e.to_string())?;
}
self.created_paths.store(true, Ordering::Relaxed);
Ok(())
}
}

View File

@ -1,2 +1,3 @@
pub mod compat;
pub mod process_commands;
pub mod process_manager;
pub mod process_commands;

View File

@ -3,7 +3,10 @@ use std::sync::Mutex;
use crate::AppState;
#[tauri::command]
pub fn launch_game(game_id: String, state: tauri::State<'_, Mutex<AppState>>) -> Result<(), String> {
pub fn launch_game(
game_id: String,
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), String> {
let state_lock = state.lock().unwrap();
let mut process_manager_lock = state_lock.process_manager.lock().unwrap();

View File

@ -46,6 +46,12 @@ impl ProcessManager<'_> {
(Platform::Linux, Platform::Linux),
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
),
/*
(
(Platform::Linux, Platform::Windows),
&UMULauncher {} as &(dyn ProcessHandler + Sync + Send + 'static)
)
*/
]),
}
}
@ -66,12 +72,6 @@ impl ProcessManager<'_> {
pub fn valid_platform(&self, platform: &Platform) -> Result<bool, String> {
let current = &self.current_platform;
info!("{:?}", self.game_launchers.keys());
info!(
"{:?} {}",
(current.clone(), platform.clone()),
(Platform::Linux, Platform::Linux) == (Platform::Linux, Platform::Linux)
);
Ok(self
.game_launchers
.contains_key(&(current.clone(), platform.clone())))
@ -201,3 +201,19 @@ impl ProcessHandler for NativeGameLauncher {
.map_err(|v| v.to_string())
}
}
struct UMULauncher;
impl ProcessHandler for UMULauncher {
fn launch_game(
&self,
game_id: &String,
version_name: &String,
command: String,
args: Vec<String>,
install_dir: &String,
log_file: File,
error_file: File,
) -> Result<Child, String> {
todo!()
}
}