Skip to content

Commit

Permalink
Merge pull request #8 from messense/windows-sys
Browse files Browse the repository at this point in the history
Switch from winapi to windows-sys
  • Loading branch information
dylni committed Dec 3, 2022
2 parents d970962 + 82e184d commit 86e169e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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

0 comments on commit 86e169e

Please sign in to comment.