Skip to content

Commit

Permalink
forward access denied error users to more info
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jun 28, 2018
1 parent 371711d commit ebfa808
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ slog-async = "2.2.0"
slog-term = "2.3.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "^0.3.3", features = ["winuser", "libloaderapi", "commctrl", "processthreadsapi", "tlhelp32", "handleapi", "psapi", "errhandlingapi", "winbase"] }
winapi = { version = "^0.3.3", features = ["winuser", "libloaderapi", "commctrl", "processthreadsapi", "tlhelp32", "handleapi", "psapi", "errhandlingapi", "winbase", "shellapi"] }

[profile.release]
lto = true
Expand Down
20 changes: 18 additions & 2 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,30 @@ pub fn event_loop() {
}

pub fn message_box(text: &str, caption: &str) -> i32 {
use winapi::um::winuser::{MessageBoxW, MB_ICONERROR};
use winapi::um::winuser::{MessageBoxW, MB_ICONERROR, MB_SYSTEMMODAL};

unsafe {
MessageBoxW(
ptr::null_mut(),
to_utf16(text).as_ptr(),
to_utf16(caption).as_ptr(),
MB_ICONERROR,
MB_ICONERROR | MB_SYSTEMMODAL,
)
}
}

pub fn open_url(url: &str) {
use winapi::um::shellapi::ShellExecuteW;
use winapi::um::winuser::SW_SHOWNORMAL;

unsafe {
ShellExecuteW(
ptr::null_mut(),
to_utf16("open").as_ptr(),
to_utf16(url).as_ptr(),
ptr::null_mut(),
ptr::null_mut(),
SW_SHOWNORMAL,
);
}
}
42 changes: 30 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,32 @@ fn _main(log: &slog::Logger, args: &Vec<String>) -> Result<(), Box<error::Error>
update(log, &code_path, "_", silent == "true")
}

fn handle_error(err: Box<error::Error>, log_path: &str) {
let err_description = err.to_string();

let mut msgs = Vec::new();

msgs.push("Failed to install VS Code update. Please download and reinstall VS Code.");

msgs.push("Please attach the following log file to a new issue on GitHub:");
msgs.push(log_path);

let access_is_denied = err_description.to_lowercase().contains("access is denied");

if access_is_denied {
msgs.push("You might want to try the new Windows User Setup available from version 1.25. You will be redirected to a link which provides more information:");
msgs.push("https://aka.ms/vscode-update-access-denied");
}

let msg = msgs.join("\n\n");

gui::message_box(&msg, "VS Code");

if access_is_denied {
gui::open_url("https://aka.ms/vscode-update-access-denied");
}
}

fn __main(args: &Vec<String>) -> i32 {
let mut log_path = env::temp_dir();
log_path.push(format!("vscode-inno-updater.log"));
Expand All @@ -347,18 +373,7 @@ fn __main(args: &Vec<String>) -> i32 {
}
Err(err) => {
error!(log, "{}", err);

let msg = format!(
"Failed to install VS Code update. Please download and reinstall VS Code.
Please attach the following log file to a new issue on GitHub:
{}",
log_path.to_str().unwrap()
);

gui::message_box(&msg, "VS Code");

handle_error(err, log_path.to_str().unwrap());
1
}
}
Expand Down Expand Up @@ -402,6 +417,9 @@ fn main() {
});

gui::event_loop();
} else if args.len() == 3 && args[1] == "--error" {
let err = Box::new(io::Error::new(io::ErrorKind::Other, args[2].to_string()));
handle_error(err, "log_path");
} else {
let args: Vec<String> = args.into_iter().filter(|a| !a.starts_with("--")).collect();

Expand Down

0 comments on commit ebfa808

Please sign in to comment.