From ee29fef6349f5591191a2dcd8691c42c6d2a58afd3f1c93cad7dc46a47c04c11 Mon Sep 17 00:00:00 2001 From: raven <7156279+RavenX8@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:25:57 -0500 Subject: [PATCH] - fix: launcher not parsing the launch command correctly - add: explicit linux support for the launcher --- launcher/src/launcher.rs | 18 +++++++++++--- launcher/src/main.rs | 54 ++++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/launcher/src/launcher.rs b/launcher/src/launcher.rs index 6e94d73..4c23862 100644 --- a/launcher/src/launcher.rs +++ b/launcher/src/launcher.rs @@ -5,7 +5,8 @@ use std::process::{exit, Command, Stdio}; use tracing::{debug, error, info, warn}; use url::Url; -pub(crate) fn launch_game(url: String) { +#[cfg(target_os = "windows")] +fn create_command() -> Command { let exe_dir_path = env::current_exe().unwrap().parent().unwrap().to_path_buf(); // Change the working directory @@ -14,13 +15,24 @@ pub(crate) fn launch_game(url: String) { wait_for_keypress(); exit(1); } + + let mut command = Command::new("./TRose.exe"); + command +} +#[cfg(target_os = "linux")] +fn create_command() -> Command { + let mut command = Command::new("bottles-cli"); + command.arg("run").arg("-p").arg("TRose").arg("-b").arg("OsIRose v3").arg("--"); + command +} + +pub(crate) fn launch_game(url: String) { // Parse the URL match Url::parse(&url) { Ok(parsed_url) => { let params = parsed_url.query_pairs(); - let game_executable = "./TRose.exe"; - let mut command = Command::new(game_executable); + let mut command = create_command(); command.arg("@TRIGGER_SOFT@"); let mut is_direct = false; diff --git a/launcher/src/main.rs b/launcher/src/main.rs index eecb041..4c4a9ab 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1,31 +1,19 @@ mod launcher; -use clap::{Parser, Subcommand}; use std::process::{Command}; -use std::{io}; +use std::{env, io}; use tracing::{debug, error, info, Level}; +use url::Url; -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] -struct Args { - #[command(subcommand)] - action: Commands, - - #[arg(short, long, action = clap::ArgAction::Count)] - verbose: u8, -} - -#[derive(Subcommand, Debug)] +#[derive(Debug)] enum Commands { - #[command(name = "launch")] - Launch { url: String }, - #[command(name = "update")] + Launch, Update, } fn main() -> Result<(), Box> { - let args = Args::parse(); - let verbose = match args.verbose { + let verbose = 0; + let verbose = match verbose { 0 => Level::INFO, 1 => Level::DEBUG, _ => Level::TRACE, @@ -34,11 +22,33 @@ fn main() -> Result<(), Box> { // Set our logging level tracing_subscriber::fmt().with_max_level(verbose).init(); - let action = args.action; + let args: Vec = env::args().collect(); + if args.len() < 2 { + error!("Usage: launcher "); + return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "url"))? + } + + let uri = &args[1]; + let url = Url::parse(uri)?; + + let method = if let Some(host) = url.host_str() { + host + } else if !url.path().is_empty() { + url.path().trim_matches('/') + } else { + return Err("Method not specified in URL".into()); + }; + + let action = match method { + "launch" => Commands::Launch, + "update" => Commands::Update, + other => return Err(format!("Unknown method: {}", other).into()), + }; + match action { - Commands::Launch { url } => { - debug!("launching with URL {}", url); - launcher::launch_game(url); + Commands::Launch => { + debug!("launching with URL {}", uri); + launcher::launch_game(uri.to_string()); } Commands::Update => { error!("Update action not implemented");