1
0
Fork 0

updated steam launch option related logic

This commit is contained in:
Kim, Jimin 2022-02-01 21:41:49 +09:00
parent ac787b4dbc
commit a5097c3301
5 changed files with 85 additions and 14 deletions

View file

@ -2,9 +2,17 @@ use super::InstallErr;
use crate::util;
use std::fs;
use std::os::unix::prelude::PermissionsExt;
use std::path::Path;
pub async fn unix_launch_option_setup() -> Result<(), InstallErr> {
pub async fn unix_launch_option_setup(
window: &tauri::Window,
game_path: &str,
) -> Result<(), InstallErr> {
//
// skip if the OS is not linux or macOS
//
match std::env::consts::OS {
"linux" | "macos" => {
println!();
@ -19,15 +27,63 @@ pub async fn unix_launch_option_setup() -> Result<(), InstallErr> {
}
};
// todo: make run_bepinex.sh executable
// todo: send launch option string to frontend
//
// Skip if launch option is already set
//
if is_already_set() {
println!("Steam launch option is already set. Skipping.");
return Ok(());
}
//
// make run_bepinex.sh executable
//
let run_bepinex_sh_path = Path::new(game_path).join("run_bepinex.sh");
let run_bepinex_sh_path_str = run_bepinex_sh_path.to_str().unwrap();
let perms = fs::metadata(&run_bepinex_sh_path);
if perms.is_err() {
println!("Failed to make {} executable", run_bepinex_sh_path_str);
return Err(InstallErr::LaunchOptionNotSet);
}
let mut perms = perms.unwrap().permissions();
perms.set_mode(0o755); // rwxr-xr-x
match fs::set_permissions("path", perms) {
Err(_) => {
println!("Failed to make {} executable", run_bepinex_sh_path_str);
}
_ => {}
};
//
// build launch option string
//
let launch_option_str = match std::env::consts::OS {
"linux" => String::from("./run_bepinex.sh %command%"),
"macos" => format!("\"{}\" %command%", run_bepinex_sh_path_str),
_ => {
return Err(InstallErr::UnsupportedOS);
}
};
//
// send launch option string to frontend
//
match window.emit("launch-option-string", launch_option_str) {
Err(_) => {
println!("Failed to send launch option data to the frontend");
return Err(InstallErr::FailedToSendLaunchOption);
}
_ => {}
};
println!("Steam launch option is either not set or invalid.");
println!("Prompting to set launch option.");
return Err(InstallErr::LaunchOptionNotSet);
@ -54,13 +110,10 @@ fn is_already_set() -> bool {
match fs::read_to_string(localconfig_path) {
Ok(_content) => {
// todo: improve logic
// 1. find line only containing "750470"
// 2. find next closest line only containing "}"
// 3. check if section contains "run_bepinex.sh"
// run_bepinex.sh
// %command%
// 750470
// 3. check if section has line containing both "run_bepinex.sh" and "%command%"
return true;
}

View file

@ -22,7 +22,7 @@ use types::InstallErr;
///
/// * `game_path` - absolute path to the game folder/directory.
#[tauri::command]
pub async fn install(game_path: String) -> Result<(), InstallErr> {
pub async fn install(window: tauri::Window, game_path: String) -> Result<(), InstallErr> {
println!("install command called");
//
@ -88,7 +88,7 @@ pub async fn install(game_path: String) -> Result<(), InstallErr> {
// Set steam launch option if OS is linux or macOS
//
match launch_options::unix_launch_option_setup().await {
match launch_options::unix_launch_option_setup(&window, game_path).await {
Ok(_) => {}
Err(err) => return Err(err),
}

View file

@ -11,6 +11,7 @@ pub enum InstallErr {
WBMDirectoryCreationFailed,
WBMUnzipFailed,
LaunchOptionNotSet,
FailedToSendLaunchOption,
}
impl serde::Serialize for InstallErr {

View file

@ -3,8 +3,11 @@
import { InstallErr } from "./types"
import { install, selectGamePathAndRun } from "./logic"
import { listen } from "@tauri-apps/api/event"
let lastInstallErr: InstallErr = undefined
let wasInstallSuccessful: boolean = false
let launhOptionString: string = "loading..."
store.lastInstallErr.subscribe((value) => {
lastInstallErr = value
@ -13,10 +16,18 @@
store.wasInstallSuccessful.subscribe((value) => {
wasInstallSuccessful = value
})
listen<string>("launch-option-string", ({ payload }) => {
launhOptionString = payload
})
</script>
<div class="install">
{#if lastInstallErr == InstallErr.UnsupportedOS}
{#if wasInstallSuccessful}
Install Success!
<br />
You may now close the installer.
{:else if lastInstallErr == InstallErr.UnsupportedOS}
Operating System not supported.
<br />
WBM Installer is only available in Windows, Mac, and Linux.
@ -46,8 +57,11 @@
{:else if lastInstallErr == InstallErr.WBMUnzipFailed}
Failed to unzip WBM :(
{:else if lastInstallErr == InstallErr.LaunchOptionNotSet}
<!-- todo: implement -->
Copy and paste the following text to ...
<!-- todo: implement click to copy -->
Copy and paste the following text to steam launch option (click to copy): "<code
>
{launhOptionString}
</code>"
<img alt="where to find property settings" src="/img/properties.png" />
@ -58,6 +72,8 @@
>
Done! Continue!
</button>
{:else if lastInstallErr == InstallErr.FailedToSendLaunchOption}
Failed to receive steam launch option data :(
{/if}
</div>
<!-- Handle lastInstallErr change -->

View file

@ -11,6 +11,7 @@ export enum InstallErr {
WBMDirectoryCreationFailed,
WBMUnzipFailed,
LaunchOptionNotSet,
FailedToSendLaunchOption,
}
/**