- fix: launcher not parsing the launch command correctly
- add: explicit linux support for the launcher
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
// Set our logging level
|
||||
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 {
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user