Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update windows crate to 0.51 #245

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/windwos-0.51.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": "patch"
---

Update `windows` crate version to `0.51`
60 changes: 18 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ freedesktop_entry_parser = "1.3"
libc = "0.2"

[target."cfg(windows)".dependencies.windows]
version = "0.39"
version = "0.51"
features = [
"Win32_Foundation",
"Win32_Security",
Expand Down
2 changes: 1 addition & 1 deletion src/os/windows/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn check() -> Result<Info, Error> {
} else {
(condition_mask, type_mask)
};
if unsafe { VerifyVersionInfoW(&mut osvi as *mut _, type_mask, condition_mask) }.as_bool() {
if unsafe { VerifyVersionInfoW(&mut osvi as *mut _, type_mask, condition_mask) }.is_ok() {
return Ok(Info {
name: name.to_string(),
version: format!("{}.{}", major, minor),
Expand Down
11 changes: 5 additions & 6 deletions src/os/windows/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use std::{
use windows::{
core::{self, PCWSTR},
Win32::{
Foundation::{CloseHandle, ERROR_PRIVILEGE_NOT_HELD, HANDLE},
Foundation::{CloseHandle, ERROR_PRIVILEGE_NOT_HELD, GENERIC_READ, HANDLE},
Storage::FileSystem::{
CreateFileW, FILE_ACCESS_FLAGS, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_DELETE_ON_CLOSE,
CreateFileW, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_DELETE_ON_CLOSE,
FILE_FLAG_OPEN_REPARSE_POINT, FILE_SHARE_READ, OPEN_EXISTING,
},
System::SystemServices::GENERIC_READ,
},
};

Expand Down Expand Up @@ -107,15 +106,15 @@ fn delete_symlink(filename: &Path) -> Result<(), core::Error> {
if let Ok(handle) = unsafe {
CreateFileW(
PCWSTR::from_raw(filename.as_ptr()),
FILE_ACCESS_FLAGS(GENERIC_READ),
GENERIC_READ.0,
FILE_SHARE_READ,
std::ptr::null(),
None,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_DELETE_ON_CLOSE,
HANDLE(0),
)
} {
unsafe { CloseHandle(handle) };
unsafe { CloseHandle(handle)? };
Ok(())
} else {
Err(core::Error::from_win32())
Expand Down
33 changes: 16 additions & 17 deletions src/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use std::{
};
use thiserror::Error;
use windows::{
core::{self, HSTRING, PCWSTR, PWSTR},
w,
core::{self, w, PCWSTR, PWSTR},
Win32::{
Foundation::{ERROR_NO_ASSOCIATION, ERROR_SUCCESS, MAX_PATH},
System::{Memory::LocalFree, Registry::HKEY_LOCAL_MACHINE},
Foundation::{LocalFree, ERROR_NO_ASSOCIATION, HLOCAL, MAX_PATH},
System::Registry::HKEY_LOCAL_MACHINE,
UI::Shell::{
AssocQueryStringW, CommandLineToArgvW, SHRegGetPathW, ASSOCF_INIT_IGNOREUNKNOWN,
ASSOCSTR_COMMAND,
Expand Down Expand Up @@ -52,8 +51,8 @@ pub struct Application {
argv: Vec<OsString>,
}

const RUST_EXT: &HSTRING = w!(".rs");
const TEXT_EXT: &HSTRING = w!(".txt");
const RUST_EXT: PCWSTR = w!(".rs");
const TEXT_EXT: PCWSTR = w!(".txt");

impl Application {
pub fn detect_editor() -> Result<Self, DetectEditorError> {
Expand All @@ -77,11 +76,11 @@ impl Application {
Ok(())
}

fn detect_associated_command(ext: &HSTRING) -> Result<Vec<u16>, DetectEditorError> {
fn detect_associated_command(ext: PCWSTR) -> Result<Vec<u16>, DetectEditorError> {
let mut len: u32 = 0;
if let Err(e) = unsafe {
AssocQueryStringW(
ASSOCF_INIT_IGNOREUNKNOWN as u32,
ASSOCF_INIT_IGNOREUNKNOWN,
ASSOCSTR_COMMAND,
// In Shlwapi.h, this parameter's type is `LPCWSTR`.
// So it's not modified actually.
Expand All @@ -90,6 +89,7 @@ impl Application {
PWSTR::null(),
&mut len as _,
)
.ok()
} {
if e.code().0 == (0x80070000 | ERROR_NO_ASSOCIATION.0) as i32 {
return Err(DetectEditorError::NoDefaultEditorSet);
Expand All @@ -99,7 +99,7 @@ impl Application {
let mut command: Vec<u16> = vec![0; len as usize];
unsafe {
AssocQueryStringW(
ASSOCF_INIT_IGNOREUNKNOWN as u32,
ASSOCF_INIT_IGNOREUNKNOWN,
ASSOCSTR_COMMAND,
// In Shlwapi.h, this parameter's type is `LPCWSTR`.
// So it's not modified actually.
Expand All @@ -108,7 +108,8 @@ impl Application {
PWSTR(command.as_mut_ptr()),
&mut len as _,
)
}?;
.ok()?;
}
Ok(command)
}

Expand Down Expand Up @@ -159,9 +160,9 @@ pub fn open_file_with(
}
}

const ANDROID_STUDIO_UNINSTALL_KEY_PATH: &HSTRING =
const ANDROID_STUDIO_UNINSTALL_KEY_PATH: PCWSTR =
w!("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Android Studio");
const ANDROID_STUDIO_UNINSTALLER_VALUE: &HSTRING = w!("UninstallString");
const ANDROID_STUDIO_UNINSTALLER_VALUE: PCWSTR = w!("UninstallString");
#[cfg(target_pointer_width = "64")]
const STUDIO_EXE_PATH: &str = "bin/studio64.exe";
#[cfg(target_pointer_width = "32")]
Expand All @@ -171,18 +172,16 @@ fn open_file_with_android_studio(path: impl AsRef<OsStr>, env: &Env) -> Result<(
let mut application_path = which("studio.cmd").unwrap_or_default();
if !application_path.is_file() {
let mut buffer = [0; MAX_PATH as usize];
let lstatus = unsafe {
unsafe {
SHRegGetPathW(
HKEY_LOCAL_MACHINE,
PCWSTR::from_raw(ANDROID_STUDIO_UNINSTALL_KEY_PATH.as_ptr()),
PCWSTR::from_raw(ANDROID_STUDIO_UNINSTALLER_VALUE.as_ptr()),
&mut buffer,
0,
)
.map_err(|e| OpenFileError::IOError(e.into()))?
};
if lstatus.0 as u32 != ERROR_SUCCESS.0 {
return Err(OpenFileError::IOError(core::Error::from_win32().into()));
}
let len = NullTerminatedWTF16Iterator(buffer.as_ptr()).count();
let uninstaller_path = OsString::from_wide(&buffer[..len]);
application_path = Path::new(&uninstaller_path)
Expand Down Expand Up @@ -225,7 +224,7 @@ impl NativeArgv {

impl Drop for NativeArgv {
fn drop(&mut self) {
unsafe { LocalFree(self.argv as _) };
let _ = unsafe { LocalFree(HLOCAL(self.argv as _)) };
}
}

Expand Down