Skip to content

Commit

Permalink
Delete debugger value instead of entire key
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Nov 11, 2024
1 parent 967df94 commit 66520cc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
4 changes: 3 additions & 1 deletion assets-autostart/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Place bg3_autostart.exe and loader.dll wherever you want. Keep all these files t

Also, if you delete the tools, make sure to uninstall it!

The two registry entries added/removed are. You may also remove these manually if you wish.
The two registry entries added/removed are (below). To uninstall, delete the `debugger` value
from both keys, or delete the keys entirely. (If you delete the entire key, you may lose
some windows settings for that particular exe. It is still FINE if you delete the key however)
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

Expand Down
64 changes: 56 additions & 8 deletions crates/autostart-installer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::{env, io, process::ExitCode};

use shared::popup::{display_popup, fatal_popup, MessageBoxIcon};
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
use winreg::{
enums::{HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS},
RegKey,
};

fn main() -> ExitCode {
let install = || {
Expand All @@ -25,9 +28,7 @@ fn main() -> ExitCode {
"--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}"));
};
uninstall();

display_popup(
"Success",
Expand Down Expand Up @@ -79,9 +80,56 @@ fn install() -> io::Result<()> {
Ok(())
}

fn uninstall() -> io::Result<()> {
HKLM.delete_subkey_all(R_BG3)?;
HKLM.delete_subkey_all(R_BG3_DX11)?;
fn uninstall() {
let mut errors_bg3 = String::new();
let mut errors_bg3_dx11 = String::new();

Ok(())
let delete_from_key = |key, errors: &mut String| {
let key = HKLM.open_subkey_with_flags(key, KEY_ALL_ACCESS);
match key {
Ok(k) => match k.get_value::<String, _>("debugger") {
Ok(_) => {
if let Err(e) = k.delete_value("debugger") {
errors.push_str(&e.to_string());
}
}

Err(e) => errors.push_str(&e.to_string()),
},

Err(e) => errors.push_str(&e.to_string()),
}
};

delete_from_key(R_BG3, &mut errors_bg3);
delete_from_key(R_BG3_DX11, &mut errors_bg3_dx11);

let bg3_ok = errors_bg3.is_empty();
let bg3_dx11_ok = errors_bg3_dx11.is_empty();

if !bg3_ok || !bg3_dx11_ok {
let mut errors = String::new();

if !errors_bg3.is_empty() {
errors.push_str(&format!("\nErrors (bg3 key)\n{errors_bg3}\n"));
}

if !errors_bg3_dx11.is_empty() {
errors.push_str(&format!("\nErrors (bg3_dx11 key)\n{errors_bg3_dx11}\n"));
}

fatal_popup(
"uninstall failed",
format!(
r#"If the error is "cannot find the file specified", you can ignore it; it simply means there was nothing to uninstall.
If you'd like to try manually uninstalling, delete the `debugger` value from both:
(uninstalled: {bg3_ok}) HKLM\{R_BG3}
(uninstalled: {bg3_dx11_ok}) HKLM\{R_BG3_DX11}
If the `debugger` value is missing, it is already uninstalled on that key.
{errors}"#
),
);
}
}

0 comments on commit 66520cc

Please sign in to comment.