From 0302beef1d08d0799121ef772dc6f439d3ec78a9 Mon Sep 17 00:00:00 2001 From: Cherry <13651622+MolotovCherry@users.noreply.github.com> Date: Mon, 11 Nov 2024 06:22:34 -0800 Subject: [PATCH] Installer now installs by default for less confusing behavior --- crates/autostart-installer/src/main.rs | 68 +++++++++++++------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/crates/autostart-installer/src/main.rs b/crates/autostart-installer/src/main.rs index cab37c0..8b9b3b7 100644 --- a/crates/autostart-installer/src/main.rs +++ b/crates/autostart-installer/src/main.rs @@ -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);