install command update
- check if launch option is properly set - more documentation - improve code efficiency
This commit is contained in:
parent
0bc20d8224
commit
37cd9ae7c0
2 changed files with 103 additions and 10 deletions
|
@ -2,6 +2,9 @@ use tauri::Window;
|
|||
|
||||
use super::InstallResult;
|
||||
use crate::commands::install::{emit, InstallSteps};
|
||||
use crate::util;
|
||||
|
||||
use std::fs;
|
||||
|
||||
pub async fn unix_launch_option_setup(window: &Window) -> Result<(), InstallResult> {
|
||||
// skip if the OS is not linux or macOS
|
||||
|
@ -19,7 +22,73 @@ pub async fn unix_launch_option_setup(window: &Window) -> Result<(), InstallResu
|
|||
}
|
||||
};
|
||||
|
||||
if is_already_set() {
|
||||
println!("Steam launch option is already set. Skipping.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("Prompt user to launch option");
|
||||
emit(&window, InstallSteps::LaunchOption);
|
||||
return Err(InstallResult::SetLaunchOption); // stop install
|
||||
return Err(InstallResult::SetLaunchOption); // stop install function
|
||||
}
|
||||
|
||||
fn is_already_set() -> bool {
|
||||
//
|
||||
// get localconfig.vdf path
|
||||
//
|
||||
|
||||
let localconfig_path = match get_localconfig_path() {
|
||||
Some(localconfig_path) => localconfig_path,
|
||||
|
||||
None => {
|
||||
println!("Failed to locate localconfig.vdf");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// check if launch option is set
|
||||
//
|
||||
|
||||
match fs::read_to_string(localconfig_path) {
|
||||
Ok(content) => {
|
||||
return content.contains("./run_bepinex.sh %command%");
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
println!("Failed to read localconfig.vdf: {:#?}", err);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn get_localconfig_path() -> Option<String> {
|
||||
match util::get_default_steam_path() {
|
||||
// using forward slash because this part of the code is only reachable in linux and macOS
|
||||
Some(steam_path) => {
|
||||
// get steam user ID
|
||||
|
||||
let paths = std::fs::read_dir(format!("{}/userdata", steam_path)).unwrap();
|
||||
let mut user_path: &str = "";
|
||||
let mut _user_path_buf: std::path::PathBuf;
|
||||
|
||||
let mut count = 0;
|
||||
for path in paths {
|
||||
count += 1;
|
||||
|
||||
_user_path_buf = path.unwrap().path();
|
||||
user_path = _user_path_buf.to_str().unwrap();
|
||||
}
|
||||
|
||||
if count > 1 {
|
||||
// todo: choose steam user ID when there's multiple
|
||||
println!("Failed to get steam user");
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(format!("{}/config/localconfig.vdf", user_path));
|
||||
}
|
||||
|
||||
None => return None,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,15 +43,35 @@ struct InstallPayload(i64);
|
|||
|
||||
/// automated version of the [manual installation](https://github.com/War-Brokers-Mods/WBM#installation).
|
||||
///
|
||||
/// This function returns if it requires a user input and is called again with the user feedback as its arguments.
|
||||
/// This function exits if it requires a user input and is called again with the user feedback as its arguments.
|
||||
///
|
||||
/// ## Installation procedure
|
||||
///
|
||||
/// This function exits at the end of each step.
|
||||
///
|
||||
/// 1. BepInEx installation
|
||||
/// 2. Steam launch option setup (only on Linux and MacOS)
|
||||
/// 3. Launch game for plugins folder generation
|
||||
/// 4. Mod installation
|
||||
///
|
||||
/// Some part of the function are unnecessary executed each time the function is called,
|
||||
/// but the time loss is negligible and it's a sacrifice worth for code readability.
|
||||
///
|
||||
/// ## Arguments
|
||||
///
|
||||
/// All arguments are empty by default.
|
||||
/// All arguments except `windows` are empty by default.
|
||||
///
|
||||
/// * `window` - standard tauri argument. See [docs](https://tauri.studio/docs/guides/command#accessing-the-window-in-commands) for more info.
|
||||
/// * `game_path` - absolute path to the game folder/directory.
|
||||
/// * `is_launch_option_set` - whether if the steam launch option for the game is set or not.
|
||||
/// * `was_game_launched` - whether if the game was launched once after installing BepInEx to generate the plugins folder.
|
||||
#[tauri::command]
|
||||
pub async fn install(window: Window, game_path: String) -> i64 {
|
||||
pub async fn install(
|
||||
window: Window,
|
||||
game_path: String,
|
||||
is_launch_option_set: bool,
|
||||
was_game_launched: bool,
|
||||
) -> i64 {
|
||||
println!("install command called");
|
||||
|
||||
//
|
||||
|
@ -90,18 +110,22 @@ pub async fn install(window: Window, game_path: String) -> i64 {
|
|||
// Install BepInEx
|
||||
//
|
||||
|
||||
match install_bepinex::install_bepinex(&window, game_path).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => return err as i64,
|
||||
if !is_launch_option_set {
|
||||
match install_bepinex::install_bepinex(&window, game_path).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => return err as i64,
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Setup steam launch option if OS is linux or macOS
|
||||
//
|
||||
|
||||
match launch_options::unix_launch_option_setup(&window).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => return err as i64,
|
||||
if !was_game_launched {
|
||||
match launch_options::unix_launch_option_setup(&window).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => return err as i64,
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue