Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add rust stub
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 19, 2023
1 parent 10c4276 commit dba586e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ path = "src/update.rs"
name = "testapp"
path = "src/testapp.rs"

[[bin]]
name = "stub"
path = "src/stub.rs"

[profile.release]
opt-level = "z" # optimize for size
lto = true # link-time optimization
Expand Down
49 changes: 49 additions & 0 deletions src/Rust/src/stub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![allow(dead_code)]

mod util;

#[macro_use]
extern crate lazy_static;

#[macro_use]
extern crate log;

use std::{
os::windows::process::CommandExt,
process::{Command as Process, ExitCode},
};

fn main() -> ExitCode {
let my_path = std::env::current_exe().unwrap();
let my_name = my_path.file_name().unwrap().to_string_lossy();

let mut log_path = my_path.clone();
log_path.pop();
log_path.push("Clowd.Squirrel.log");

let _ = util::setup_logging(Some(&log_path), false, true, true);

let mut update_exe = my_path.clone();
update_exe.pop();
update_exe.push("Update.exe");

if !update_exe.exists() {
error!("Update.exe not found at {:?}", update_exe);
return ExitCode::FAILURE;
}

let mut args: Vec<String> = std::env::args().skip(1).collect();
args.insert(0, "start".to_owned());
args.insert(1, my_name.to_string());
args.insert(2, "--".to_owned());

info!("Stub {} about to start Update.exe ({}) with args: {:?}", my_name, update_exe.to_string_lossy(), args);

const CREATE_NO_WINDOW: u32 = 0x08000000;
if let Err(e) = Process::new(update_exe).args(args).creation_flags(CREATE_NO_WINDOW).spawn() {
error!("Stub failed to start Update.exe: {}", e);
return ExitCode::FAILURE;
}

ExitCode::SUCCESS
}

0 comments on commit dba586e

Please sign in to comment.