mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
fix(process): absolute executable invoke
This commit is contained in:
@@ -70,7 +70,6 @@ pub fn fetch_user() -> Result<User, RemoteAccessError> {
|
|||||||
|
|
||||||
let endpoint = base_url.join("/api/v1/client/user")?;
|
let endpoint = base_url.join("/api/v1/client/user")?;
|
||||||
let header = generate_authorization_header();
|
let header = generate_authorization_header();
|
||||||
info!("authorization header: {}", header);
|
|
||||||
|
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
let response = client
|
let response = client
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ fn fetch_state(state: tauri::State<'_, Mutex<AppState>>) -> Result<AppState, Str
|
|||||||
fn setup(handle: AppHandle) -> AppState {
|
fn setup(handle: AppHandle) -> AppState {
|
||||||
let logfile = FileAppender::builder()
|
let logfile = FileAppender::builder()
|
||||||
.encoder(Box::new(PatternEncoder::new("{d} | {l} | {f} - {m}{n}")))
|
.encoder(Box::new(PatternEncoder::new("{d} | {l} | {f} - {m}{n}")))
|
||||||
|
.append(false)
|
||||||
.build(DATA_ROOT_DIR.lock().unwrap().join("./drop.log"))
|
.build(DATA_ROOT_DIR.lock().unwrap().join("./drop.log"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
io::Write,
|
io::{Stdout, Write},
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
process::{Child, Command},
|
process::{Child, Command},
|
||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
@@ -39,23 +39,18 @@ impl ProcessManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_command(&self, raw_command: String) -> (String, Vec<String>) {
|
fn process_command(&self, install_dir: &String, raw_command: String) -> (String, Vec<String>) {
|
||||||
let command_components = raw_command.split(" ").collect::<Vec<&str>>();
|
let command_components = raw_command.split(" ").collect::<Vec<&str>>();
|
||||||
let root = match self.current_platform {
|
let root = command_components[0].to_string();
|
||||||
Platform::Windows => command_components[0].to_string(),
|
|
||||||
Platform::Linux => {
|
let install_dir = Path::new(install_dir);
|
||||||
let mut root = command_components[0].to_string();
|
let absolute_exe = install_dir.join(root);
|
||||||
if !root.starts_with("./") {
|
|
||||||
root = format!("{}{}", "./", root);
|
|
||||||
}
|
|
||||||
root
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let args = command_components[1..]
|
let args = command_components[1..]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| v.to_string())
|
.map(|v| v.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
(root, args)
|
(absolute_exe.to_str().unwrap().to_owned(), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn valid_platform(&self, platform: &Platform) -> Result<bool, String> {
|
pub fn valid_platform(&self, platform: &Platform) -> Result<bool, String> {
|
||||||
@@ -95,14 +90,15 @@ impl ProcessManager {
|
|||||||
.get(version_name)
|
.get(version_name)
|
||||||
.ok_or("Invalid version name".to_owned())?;
|
.ok_or("Invalid version name".to_owned())?;
|
||||||
|
|
||||||
let (command, args) = self.process_command(game_version.launch_command.clone());
|
let (command, args) =
|
||||||
|
self.process_command(install_dir, game_version.launch_command.clone());
|
||||||
|
|
||||||
info!("launching process {} in {}", command, install_dir);
|
info!("launching process {} in {}", command, install_dir);
|
||||||
|
|
||||||
let current_time = chrono::offset::Local::now();
|
let current_time = chrono::offset::Local::now();
|
||||||
let mut log_file = OpenOptions::new()
|
let mut log_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.append(true)
|
|
||||||
.read(true)
|
.read(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(
|
.open(
|
||||||
@@ -111,18 +107,23 @@ impl ProcessManager {
|
|||||||
)
|
)
|
||||||
.map_err(|v| v.to_string())?;
|
.map_err(|v| v.to_string())?;
|
||||||
|
|
||||||
log_file.write(&Vec::new()).unwrap();
|
let mut error_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.read(true)
|
||||||
|
.create(true)
|
||||||
|
.open(
|
||||||
|
self.log_output_dir
|
||||||
|
.join(format!("{}-{}-error.log", game_id, current_time.timestamp())),
|
||||||
|
)
|
||||||
|
.map_err(|v| v.to_string())?;
|
||||||
|
|
||||||
writeln!(
|
info!("opened log file for {}", command);
|
||||||
log_file,
|
|
||||||
"Drop: launching {} with args {:?} in {}",
|
|
||||||
command, args, install_dir
|
|
||||||
)
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
let launch_process = Command::new(command)
|
let launch_process = Command::new(command)
|
||||||
.current_dir(install_dir)
|
.current_dir(install_dir)
|
||||||
.stdout(log_file)
|
.stdout(log_file)
|
||||||
|
.stderr(error_file)
|
||||||
.args(args)
|
.args(args)
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|v| v.to_string())?;
|
.map_err(|v| v.to_string())?;
|
||||||
|
|||||||
Reference in New Issue
Block a user