Skip to content

Commit

Permalink
Installer now installs by default for less confusing behavior
Browse files Browse the repository at this point in the history
MolotovCherry committed Nov 11, 2024
1 parent a2d1783 commit 0302bee
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions crates/autostart-installer/src/main.rs
Original file line number Diff line number Diff line change
@@ -5,50 +5,48 @@ use std::{env, io, process::ExitCode};
use shared::popup::{display_popup, fatal_popup, MessageBoxIcon};
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};

const HELP: &str = r"autostart-installer
Installs bg3_autostart. Automatically patches bg3 when the game is launched, without needing to manually
run any tool. Installs registry entries at:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\bg3.exe
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\bg3_dx11.exe
Flags:
--install install the autostarter
--uninstall uninstall the autostarter
--help this message
";

fn main() -> ExitCode {
let Some(flag) = env::args().nth(1) else {
display_popup("Usage", HELP, MessageBoxIcon::Info);
return ExitCode::SUCCESS;
};

let is_install = flag == "--install";
let is_uninstall = flag == "--uninstall";

if is_install {
let install = || {
if let Err(e) = install() {
fatal_popup("install failed", format!("{e}"));
fatal_popup("install failed", e.to_string());
};

display_popup("Success", "bg3_autostart was successfully installed.\n\nEvery time you launch bg3, your game will be auto patched. If you want to stop this from happening, please uninstall the tool using the provided uninstall.bat. Also, do not move bg3_autostart.exe after you install. If you wish to move it, please first uninstall, move the tool, then reinstall.\n\nPlease also note that the registry entries point at the current bg3_autostart.exe location. If this file is in your windows user folder and another windows user tries to launch the game, they may not have access to the exe in your windows user folder (since it's another windows user's files). If multiple windows users play this game, you should instead place this exe at a location accessible by all windows users to avoid this problem. Also, if you delete the tools, make sure to uninstall first!", MessageBoxIcon::Info);
ExitCode::SUCCESS
} else if is_uninstall {
if let Err(e) = uninstall() {
fatal_popup("uninstall failed", format!("If the error is \"cannot find the file specified\", you can ignore it; it simply means there was nothing to uninstall\n\n{e}"));
};

display_popup(
"Success",
"bg3_autostart was successfully uninstalled.",
MessageBoxIcon::Info,
);
ExitCode::SUCCESS
};

if env::args().count() > 2 {
fatal_popup("Incorrect usage", "This installer only accepts 1 cli arg: --install or --uninstall (no args means by default it installs)");
}

if let Some(flag) = env::args().nth(1) {
match &*flag {
"--install" => return install(),

"--uninstall" => {
if let Err(e) = uninstall() {
fatal_popup("uninstall failed", format!("If the error is \"cannot find the file specified\", you can ignore it; it simply means there was nothing to uninstall\n\n{e}"));
};

display_popup(
"Success",
"bg3_autostart was successfully uninstalled.",
MessageBoxIcon::Info,
);
}

_ => {
fatal_popup("Incorrect usage", "This installer only accepts --install or --uninstall (no args means by default it installs)");
}
}
} else {
display_popup("Usage", HELP, MessageBoxIcon::Info);
ExitCode::SUCCESS
// no args; either it was a double click or cli execute with no args
// default action is to install
install();
}

ExitCode::SUCCESS
}

const HKLM: RegKey = RegKey::predef(HKEY_LOCAL_MACHINE);

0 comments on commit 0302bee

Please sign in to comment.