-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve the state of things on Windows
- Loading branch information
Showing
3 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::path::Path; | ||
Check warning on line 1 in crates/rattler_menuinst/src/windows/create_shortcut.rs GitHub Actions / Format, Lint and Test the Python bindings
|
||
use windows::{ | ||
core::*, | ||
Win32::System::Com::*, | ||
Win32::System::Com::StructuredStorage::*, | ||
Win32::UI::Shell::*, | ||
Win32::UI::Shell::PropertiesSystem::*, | ||
}; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
enum CreateShortcutFail { | ||
#[error("Failed to create shortcut: {0}")] | ||
WindowsError(#[from] windows::core::Error), | ||
|
||
#[error("Failed to initialize COM")] | ||
CoInitializeFail, | ||
} | ||
|
||
/// Create a shortcut at the specified path. | ||
pub(crate) fn create_shortcut( | ||
path: &Path, | ||
description: &str, | ||
filename: &Path, | ||
arguments: Option<&str>, | ||
workdir: Option<&Path>, | ||
iconpath: Option<&Path>, | ||
iconindex: i32, | ||
app_id: Option<&str>, | ||
) -> std::result::Result<(), CreateShortcutFail> { | ||
unsafe { | ||
if !CoInitialize(None).is_ok() { | ||
return Err(CreateShortcutFail::CoInitializeFail); | ||
} | ||
|
||
let shell_link: IShellLinkW = CoCreateInstance(&ShellLink, None, CLSCTX_INPROC_SERVER)?; | ||
let persist_file: IPersistFile = shell_link.cast()?; | ||
|
||
shell_link.SetPath(&HSTRING::from(path))?; | ||
shell_link.SetDescription(&HSTRING::from(description))?; | ||
|
||
if let Some(args) = arguments { | ||
shell_link.SetArguments(&HSTRING::from(args))?; | ||
} | ||
|
||
if let Some(icon) = iconpath { | ||
shell_link.SetIconLocation(&HSTRING::from(icon), iconindex)?; | ||
} | ||
|
||
if let Some(dir) = workdir { | ||
shell_link.SetWorkingDirectory(&HSTRING::from(dir))?; | ||
} | ||
|
||
if let Some(id) = app_id { | ||
let property_store: IPropertyStore = shell_link.cast()?; | ||
let mut prop_variant = PROPVARIANT::default(); | ||
// PropVariantInit(&mut prop_variant); | ||
// SetPropStringValue(PCWSTR(PWSTR::from_raw(to_wide_string(id).as_mut_ptr())), &mut prop_variant)?; | ||
// property_store.SetValue(&PROPERTYKEY_AppUserModel_ID, &prop_variant)?; | ||
property_store.Commit()?; | ||
PropVariantClear(&mut prop_variant)?; | ||
} | ||
|
||
persist_file.Save(&HSTRING::from(filename), true)?; | ||
|
||
CoUninitialize(); | ||
Ok(()) | ||
Check warning on line 66 in crates/rattler_menuinst/src/windows/create_shortcut.rs GitHub Actions / Format, Lint and Test the Python bindings
|
||
} | ||
} |