mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-15 17:21:19 +10:00
feat(game): game uninstalling & partial compat
This commit is contained in:
51
src-tauri/src/process/compat.rs
Normal file
51
src-tauri/src/process/compat.rs
Normal 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(())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,2 +1,3 @@
|
||||
pub mod compat;
|
||||
pub mod process_commands;
|
||||
pub mod process_manager;
|
||||
pub mod process_commands;
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user