Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Shortcut failing to create, duplicate com guard
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 22, 2023
1 parent 2d27e4d commit a072ee6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Rust/src/platform/windows/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ fn _resolve_lnk(link_path: &str) -> Result<(String, String)> {
let flags_with_timeout = co::SLR::ANY_MATCH | co::SLR::NO_UI | unsafe { co::SLR::from_raw(1 << 16) };
if let Err(e) = me.Resolve(&w::HWND::NULL, flags_with_timeout) {
// this happens if the target path is missing and the link is broken
error!("Failed to resolve link: {:?}", e);
warn!("Failed to resolve link {} ({:?})", link_path, e);
}
let path = me.GetPath(None, co::SLGP::UNCPRIORITY)?;
let workdir = me.GetWorkingDirectory()?;
Ok((path, workdir))
}

pub fn remove_all_for_root_dir<P: AsRef<Path>>(root_dir: P) -> Result<()> {
pub fn remove_all_shortcuts_for_root_dir<P: AsRef<Path>>(root_dir: P) -> Result<()> {
let _comguard = w::CoInitializeEx(co::COINIT::APARTMENTTHREADED)?;
let root_dir = root_dir.as_ref();
info!("Searching for shortcuts containing root: '{}'", root_dir.to_string_lossy());
Expand Down Expand Up @@ -108,7 +108,7 @@ fn shortcut_full_integration_test() {
assert_eq!(target_out, target);
assert_eq!(work_out, work);

remove_all_for_root_dir(root).unwrap();
remove_all_shortcuts_for_root_dir(root).unwrap();
assert!(!link_location.exists());
}

Expand Down
5 changes: 3 additions & 2 deletions src/Rust/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,11 @@ fn install_app(pkg: &bundle::BundleInfo, root_path: &PathBuf, tx: &std::sync::mp
}

info!("Creating start menu shortcut...");
let _comguard = w::CoInitializeEx(co::COINIT::APARTMENTTHREADED)?;
let startmenu = w::SHGetKnownFolderPath(&co::KNOWNFOLDERID::StartMenu, co::KF::DONT_UNEXPAND, None)?;
let lnk_path = Path::new(&startmenu).join("Programs").join(format!("{}.lnk", &app.title));
platform::create_lnk(&lnk_path.to_string_lossy(), &main_exe_path, &current_path)?;
if let Err(e) = platform::create_lnk(&lnk_path.to_string_lossy(), &main_exe_path, &current_path) {
warn!("Failed to create start menu shortcut: {}", e);
}

info!("Starting process install hook: \"{}\" --squirrel-install {}", main_exe_path, &app.version);
let args = vec!["--squirrel-install", &app.version];
Expand Down
10 changes: 5 additions & 5 deletions src/Rust/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ fn uninstall(_matches: &ArgMatches, log_file: &PathBuf) -> Result<()> {
// in case the uninstall hook left running processes
let _ = platform::kill_processes_in_directory(&root_path);

if let Err(e) = platform::remove_all_shortcuts_for_root_dir(&root_path) {
error!("Unable to remove shortcuts ({}).", e);
// finished_with_errors = true;
}

info!("Removing directory '{}'", root_path.to_string_lossy());
if let Err(e) = util::retry_io(|| remove_dir_all::remove_dir_containing_current_executable()) {
error!("Unable to remove directory, some files may be in use ({}).", e);
finished_with_errors = true;
}

if let Err(e) = platform::remove_all_for_root_dir(&root_path) {
error!("Unable to remove shortcuts ({}).", e);
// finished_with_errors = true;
}

if let Err(e) = app.remove_uninstall_entry() {
error!("Unable to remove uninstall registry entry ({}).", e);
// finished_with_errors = true;
Expand Down

0 comments on commit a072ee6

Please sign in to comment.