[chore] add checks and args whitelist for launching BS as admin

This commit is contained in:
MathieuG-P
2024-01-25 21:44:58 +01:00
parent 263061e7ce
commit 4fc5a87c13
2 changed files with 33 additions and 3 deletions
Binary file not shown.
+33 -3
View File
@@ -1,13 +1,43 @@
use std::{process::Command, path::Path};
const EXECUTABLE_NAME: &str = "Beat Saber.exe";
const AUTORIZED_ARGS: [&str; 8] = [
"fpfc",
"-vrmode",
"oculus",
"--verbose",
"--no-yeet",
"--disable-autoupdate",
"--combine-logs",
"editor"
];
fn main() {
let args: Vec<String> = std::env::args().collect();
let mut command = Command::new(args.get(1).unwrap());
command.current_dir(Path::new(args.get(1).unwrap()).parent().unwrap());
let executable_path = Path::new(&args[1]);
for arg in args.iter().skip(1) {
if executable_path.file_name().unwrap() != EXECUTABLE_NAME {
eprintln!("Executable path is not Beat Saber.exe.");
return;
}
if !executable_path.exists() || !executable_path.is_file() {
eprintln!("Executable path is not valid.");
return;
}
let mut command = Command::new(executable_path);
if let Some(parent_dir) = executable_path.parent() {
command.current_dir(parent_dir);
}
for arg in args.iter().skip(2) {
if !AUTORIZED_ARGS.contains(&arg.as_str()) {
continue;
}
command.arg(arg);
}