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

Switch from winapi to windows-sys #8

Merged
merged 2 commits into from Dec 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -24,14 +24,15 @@ print_bytes = { version = "0.7", optional = true }
serde = { version = "1.0", optional = true }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["fileapi"] }
windows-sys = { version = "0.42", features = ["Win32_Storage_FileSystem"] }

[dev-dependencies]
bincode = "1.3"
tempfile = "3.2"
windows-sys = { version = "0.42", features = ["Win32_Foundation"] }

[target.'cfg(not(windows))'.dev-dependencies]
libc = "0.2"

[features]
localization = ["winapi/shellapi"]
localization = ["windows-sys/Win32_UI_Shell", "windows-sys/Win32_UI_WindowsAndMessaging"]
7 changes: 3 additions & 4 deletions src/windows/localize.rs
Expand Up @@ -5,9 +5,8 @@ use std::os::windows::ffi::OsStrExt;
use std::os::windows::ffi::OsStringExt;
use std::path::Path;

use winapi::shared::minwindef::UINT;
use winapi::um::shellapi::SHGetFileInfoW;
use winapi::um::shellapi::SHGFI_DISPLAYNAME;
use windows_sys::Win32::UI::Shell::SHGetFileInfoW;
use windows_sys::Win32::UI::Shell::SHGFI_DISPLAYNAME;

pub(super) fn name(path: &Path) -> Option<OsString> {
let mut path: Vec<_> = path.as_os_str().encode_wide().collect();
Expand All @@ -22,7 +21,7 @@ pub(super) fn name(path: &Path) -> Option<OsString> {
path.as_ptr(),
0,
path_info.as_mut_ptr(),
mem::size_of_val(&path_info) as UINT,
mem::size_of_val(&path_info) as _,
SHGFI_DISPLAYNAME,
)
};
Expand Down
6 changes: 3 additions & 3 deletions src/windows/normalize.rs
Expand Up @@ -11,8 +11,7 @@ use std::path::Prefix;
use std::path::PrefixComponent;
use std::ptr;

use winapi::shared::minwindef::DWORD;
use winapi::um::fileapi::GetFullPathNameW;
use windows_sys::Win32::Storage::FileSystem::GetFullPathNameW;

use super::BasePath;
use super::BasePathBuf;
Expand Down Expand Up @@ -104,8 +103,9 @@ pub(super) fn normalize_virtually(
break Err(io::Error::last_os_error());
}

let _: u32 = capacity;
// This assertion should never fail.
static_assert!(mem::size_of::<DWORD>() <= mem::size_of::<usize>());
static_assert!(mem::size_of::<u32>() <= mem::size_of::<usize>());

let length = capacity as usize;
if let Some(mut additional_capacity) =
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Expand Up @@ -14,7 +14,7 @@ mod common;

#[cfg(windows)]
#[rustfmt::skip]
use winapi::shared::winerror::ERROR_INVALID_NAME;
use windows_sys::Win32::Foundation::ERROR_INVALID_NAME;
#[cfg(not(windows))]
use libc::ENOENT as ERROR_INVALID_NAME;

Expand Down