Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce DLL dependencies for "oculus-allow-dev-sideloaded.exe" and add logging for external scripts #735

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ npm-debug.log.*
*.scss.d.ts

# externals
externals/**/target/*
externals/**/target/**
Binary file modified assets/scripts/oculus-allow-dev-sideloaded.exe
Binary file not shown.
Binary file modified assets/scripts/start_beat_saber_admin.exe
Binary file not shown.
224 changes: 224 additions & 0 deletions externals/bs-admin-start/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions externals/bs-admin-start/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ version = "0.1.0"
edition = "2021"
build = "build.rs"

[dependencies]
simplelog = { version = "0.12.2", default-features = false }
log = "0.4.24"

[build-dependencies]
winres = "0.1.12"

[profile.release]
codegen-units = 1
lto = true
opt-level = "z"
panic = "abort"

[package.metadata.winres]
FileDescription = "Start Beat Saber as Admin"
Expand Down
2 changes: 2 additions & 0 deletions externals/bs-admin-start/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.77.0"
40 changes: 35 additions & 5 deletions externals/bs-admin-start/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@

use std::{process::Command, path::Path};
use std::env::current_exe;
use std::fs::File;
use std::path::PathBuf;
use log::{error, info, LevelFilter};
use simplelog::{CombinedLogger, Config, WriteLogger};

const EXECUTABLE_NAME: &str = "Beat Saber.exe";
const AUTORIZED_ARGS: [&str; 8] = [
Expand All @@ -14,18 +19,37 @@ const AUTORIZED_ARGS: [&str; 8] = [
];

fn main() {

let default_log_file_path = current_exe().unwrap().with_file_name("bs-admin-start.log");
let args: Vec<String> = std::env::args().collect();

let log_file_path: PathBuf = if let Some(pos) = args.iter().position(|arg| arg == "--log-path") {
if let Some(log_path) = args.get(pos + 1) {
PathBuf::from(log_path)
} else {
default_log_file_path
}
} else {
default_log_file_path
};

CombinedLogger::init(
vec![
WriteLogger::new(LevelFilter::Info, Config::default(), File::create(log_file_path).unwrap()),
]
).unwrap();


let args: Vec<String> = std::env::args().collect();

let executable_path = Path::new(&args[1]);

if executable_path.file_name().unwrap() != EXECUTABLE_NAME {
eprintln!("Executable path is not Beat Saber.exe.");
return;
return error!("Executable path is not Beat Saber.exe.");
}

if !executable_path.exists() || !executable_path.is_file() {
eprintln!("Executable path is not valid.");
return;
return error!("Executable path is not valid.");
}

let mut command = Command::new(executable_path);
Expand All @@ -43,5 +67,11 @@ fn main() {

command.env("SteamAppId", "620980");

let _ = command.spawn();
let res = command.spawn();

if let Err(e) = res {
return error!("Failed to start Beat Saber ({}): {}", executable_path.display(), e);
}

info!("Beat Saber started ({})", executable_path.display());
}
Loading
Loading