- fix: launcher not parsing the launch command correctly

- add: explicit linux support for the launcher
This commit is contained in:
2024-12-17 18:25:57 -05:00
parent 9c61b1b3f2
commit ee29fef634
2 changed files with 47 additions and 25 deletions

View File

@@ -5,7 +5,8 @@ use std::process::{exit, Command, Stdio};
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
use url::Url; 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(); let exe_dir_path = env::current_exe().unwrap().parent().unwrap().to_path_buf();
// Change the working directory // Change the working directory
@@ -15,12 +16,23 @@ pub(crate) fn launch_game(url: String) {
exit(1); 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 // Parse the URL
match Url::parse(&url) { match Url::parse(&url) {
Ok(parsed_url) => { Ok(parsed_url) => {
let params = parsed_url.query_pairs(); let params = parsed_url.query_pairs();
let game_executable = "./TRose.exe"; let mut command = create_command();
let mut command = Command::new(game_executable);
command.arg("@TRIGGER_SOFT@"); command.arg("@TRIGGER_SOFT@");
let mut is_direct = false; let mut is_direct = false;

View File

@@ -1,31 +1,19 @@
mod launcher; mod launcher;
use clap::{Parser, Subcommand};
use std::process::{Command}; use std::process::{Command};
use std::{io}; use std::{env, io};
use tracing::{debug, error, info, Level}; use tracing::{debug, error, info, Level};
use url::Url;
#[derive(Parser, Debug)] #[derive(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)]
enum Commands { enum Commands {
#[command(name = "launch")] Launch,
Launch { url: String },
#[command(name = "update")]
Update, Update,
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse(); let verbose = 0;
let verbose = match args.verbose { let verbose = match verbose {
0 => Level::INFO, 0 => Level::INFO,
1 => Level::DEBUG, 1 => Level::DEBUG,
_ => Level::TRACE, _ => Level::TRACE,
@@ -34,11 +22,33 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set our logging level // Set our logging level
tracing_subscriber::fmt().with_max_level(verbose).init(); tracing_subscriber::fmt().with_max_level(verbose).init();
let action = args.action; let args: Vec<String> = env::args().collect();
if args.len() < 2 {
error!("Usage: launcher <url>");
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 { match action {
Commands::Launch { url } => { Commands::Launch => {
debug!("launching with URL {}", url); debug!("launching with URL {}", uri);
launcher::launch_game(url); launcher::launch_game(uri.to_string());
} }
Commands::Update => { Commands::Update => {
error!("Update action not implemented"); error!("Update action not implemented");