mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
chore: Remove unwraps from process_handlers
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -11,7 +11,8 @@ pub enum ProcessError {
|
|||||||
IOError(Error),
|
IOError(Error),
|
||||||
FormatError(String), // String errors supremacy
|
FormatError(String), // String errors supremacy
|
||||||
InvalidPlatform,
|
InvalidPlatform,
|
||||||
OpenerError(tauri_plugin_opener::Error)
|
OpenerError(tauri_plugin_opener::Error),
|
||||||
|
InvalidArguments(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ProcessError {
|
impl Display for ProcessError {
|
||||||
@ -23,8 +24,9 @@ impl Display for ProcessError {
|
|||||||
ProcessError::InvalidVersion => "Invalid game version",
|
ProcessError::InvalidVersion => "Invalid game version",
|
||||||
ProcessError::IOError(error) => &error.to_string(),
|
ProcessError::IOError(error) => &error.to_string(),
|
||||||
ProcessError::InvalidPlatform => "This game cannot be played on the current platform",
|
ProcessError::InvalidPlatform => "This game cannot be played on the current platform",
|
||||||
ProcessError::FormatError(e) => &format!("Failed to format template: {e}"),
|
ProcessError::FormatError(e) => &format!("Could not format template: {e}"),
|
||||||
ProcessError::OpenerError(error) => &format!("Failed to open directory: {error}"),
|
ProcessError::OpenerError(error) => &format!("Could not open directory: {error}"),
|
||||||
|
ProcessError::InvalidArguments(arguments) => &format!("Invalid arguments in command {arguments}"),
|
||||||
};
|
};
|
||||||
write!(f, "{s}")
|
write!(f, "{s}")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use log::{debug, info};
|
|||||||
use crate::{
|
use crate::{
|
||||||
AppState,
|
AppState,
|
||||||
database::models::data::{Database, DownloadableMetadata, GameVersion},
|
database::models::data::{Database, DownloadableMetadata, GameVersion},
|
||||||
|
error::process_error::ProcessError,
|
||||||
process::process_manager::{Platform, ProcessHandler},
|
process::process_manager::{Platform, ProcessHandler},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,8 +23,8 @@ impl ProcessHandler for NativeGameLauncher {
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
_game_version: &GameVersion,
|
_game_version: &GameVersion,
|
||||||
_current_dir: &str,
|
_current_dir: &str,
|
||||||
) -> String {
|
) -> Result<String, ProcessError> {
|
||||||
format!("\"{}\" {}", launch_command, args.join(" "))
|
Ok(format!("\"{}\" {}", launch_command, args.join(" ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_for_platform(&self, _db: &Database, _state: &AppState, _target: &Platform) -> bool {
|
fn valid_for_platform(&self, _db: &Database, _state: &AppState, _target: &Platform) -> bool {
|
||||||
@ -65,7 +66,7 @@ impl ProcessHandler for UMULauncher {
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
game_version: &GameVersion,
|
game_version: &GameVersion,
|
||||||
_current_dir: &str,
|
_current_dir: &str,
|
||||||
) -> String {
|
) -> Result<String, ProcessError> {
|
||||||
debug!("Game override: \"{:?}\"", &game_version.umu_id_override);
|
debug!("Game override: \"{:?}\"", &game_version.umu_id_override);
|
||||||
let game_id = match &game_version.umu_id_override {
|
let game_id = match &game_version.umu_id_override {
|
||||||
Some(game_override) => {
|
Some(game_override) => {
|
||||||
@ -77,12 +78,12 @@ impl ProcessHandler for UMULauncher {
|
|||||||
}
|
}
|
||||||
None => game_version.game_id.clone(),
|
None => game_version.game_id.clone(),
|
||||||
};
|
};
|
||||||
format!(
|
Ok(format!(
|
||||||
"GAMEID={game_id} {umu:?} \"{launch}\" {args}",
|
"GAMEID={game_id} {umu:?} \"{launch}\" {args}",
|
||||||
umu = UMU_LAUNCHER_EXECUTABLE.as_ref().unwrap(),
|
umu = UMU_LAUNCHER_EXECUTABLE.as_ref().expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
|
||||||
launch = launch_command,
|
launch = launch_command,
|
||||||
args = args.join(" ")
|
args = args.join(" ")
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_for_platform(&self, _db: &Database, state: &AppState, _target: &Platform) -> bool {
|
fn valid_for_platform(&self, _db: &Database, state: &AppState, _target: &Platform) -> bool {
|
||||||
@ -102,7 +103,7 @@ impl ProcessHandler for AsahiMuvmLauncher {
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
game_version: &GameVersion,
|
game_version: &GameVersion,
|
||||||
current_dir: &str,
|
current_dir: &str,
|
||||||
) -> String {
|
) -> Result<String, ProcessError> {
|
||||||
let umu_launcher = UMULauncher {};
|
let umu_launcher = UMULauncher {};
|
||||||
let umu_string = umu_launcher.create_launch_process(
|
let umu_string = umu_launcher.create_launch_process(
|
||||||
meta,
|
meta,
|
||||||
@ -110,15 +111,18 @@ impl ProcessHandler for AsahiMuvmLauncher {
|
|||||||
args,
|
args,
|
||||||
game_version,
|
game_version,
|
||||||
current_dir,
|
current_dir,
|
||||||
);
|
)?;
|
||||||
let mut args_cmd = umu_string
|
let mut args_cmd = umu_string
|
||||||
.split("umu-run")
|
.split("umu-run")
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.into_iter();
|
.into_iter();
|
||||||
let args = args_cmd.next().unwrap().trim();
|
let args = args_cmd
|
||||||
let cmd = format!("umu-run{}", args_cmd.next().unwrap());
|
.next()
|
||||||
|
.ok_or(ProcessError::InvalidArguments(umu_string.clone()))?
|
||||||
|
.trim();
|
||||||
|
let cmd = format!("umu-run{}", args_cmd.next().ok_or(ProcessError::InvalidArguments(umu_string.clone()))?);
|
||||||
|
|
||||||
format!("{args} muvm -- {cmd}")
|
Ok(format!("{args} muvm -- {cmd}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
|
|||||||
@ -331,7 +331,7 @@ impl ProcessManager<'_> {
|
|||||||
args.clone(),
|
args.clone(),
|
||||||
game_version,
|
game_version,
|
||||||
install_dir,
|
install_dir,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let format_args = DropFormatArgs::new(
|
let format_args = DropFormatArgs::new(
|
||||||
launch_string,
|
launch_string,
|
||||||
@ -468,7 +468,7 @@ pub trait ProcessHandler: Send + 'static {
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
game_version: &GameVersion,
|
game_version: &GameVersion,
|
||||||
current_dir: &str,
|
current_dir: &str,
|
||||||
) -> String;
|
) -> Result<String, ProcessError>;
|
||||||
|
|
||||||
fn valid_for_platform(&self, db: &Database, state: &AppState, target: &Platform) -> bool;
|
fn valid_for_platform(&self, db: &Database, state: &AppState, target: &Platform) -> bool;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,7 +134,7 @@ async fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), Re
|
|||||||
private: response_struct.private,
|
private: response_struct.private,
|
||||||
cert: response_struct.certificate,
|
cert: response_struct.certificate,
|
||||||
client_id: response_struct.id,
|
client_id: response_struct.id,
|
||||||
web_token: Some(web_token), // gets created later
|
web_token: Some(web_token),
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user