Ship a self-contained Windows GUI with game shortcuts and application icons
This commit is contained in:
1 parent
329a1ad4df
commit
3ea497d38a
16 files changed
+589
-58
No files matched your search
+40
@@ -1,3 +1,5 @@
|
||||
#![cfg_attr(windows, windows_subsystem = "windows")]
|
||||
|
||||
use crate::{app::App, args::Args};
|
||||
use clap::Parser;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -25,6 +27,9 @@ mod window;
|
||||
mod worker_pool;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
#[cfg(windows)]
|
||||
attach_parent_console();
|
||||
|
||||
profiling::register_thread!("Main Thread");
|
||||
env_logger::init();
|
||||
|
||||
@@ -48,6 +53,41 @@ fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reuse a terminal's console without opening one for Explorer or Start Menu launches.
|
||||
#[cfg(windows)]
|
||||
fn attach_parent_console() {
|
||||
use windows_sys::Win32::{
|
||||
Foundation::{GetHandleInformation, INVALID_HANDLE_VALUE},
|
||||
System::Console::{
|
||||
ATTACH_PARENT_PROCESS, AttachConsole, GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE,
|
||||
STD_OUTPUT_HANDLE, SetStdHandle,
|
||||
},
|
||||
};
|
||||
|
||||
let inherited = [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE].map(|stream| {
|
||||
// SAFETY: These calls only query process-owned handles; no ownership is transferred.
|
||||
let handle = unsafe { GetStdHandle(stream) };
|
||||
let mut flags = 0;
|
||||
let valid = !handle.is_null()
|
||||
&& handle != INVALID_HANDLE_VALUE
|
||||
&& unsafe { GetHandleInformation(handle, &mut flags) } != 0;
|
||||
(stream, handle, valid)
|
||||
});
|
||||
|
||||
// SAFETY: Called before logging, argument parsing, or application threads start.
|
||||
// Attaching can replace the standard handle table, so restore each valid inherited
|
||||
// handle independently, including when only stdout or stderr was redirected.
|
||||
unsafe {
|
||||
if AttachConsole(ATTACH_PARENT_PROCESS) != 0 {
|
||||
for (stream, handle, valid) in inherited {
|
||||
if valid {
|
||||
SetStdHandle(stream, handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Search for the Launch.lua file in nearby locations
|
||||
fn find_nearby_launch_script() -> Option<PathBuf> {
|
||||
let mut candidates = vec![Path::new("Launch.lua"), Path::new("src/Launch.lua")];
|
||||
|
||||
Reference in new issue
Block a user