@@ -257,85 +257,19 @@ pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<Path
257257}
258258
259259#[ cfg( windows) ]
260- pub use windows_platform:: { get_function_impl , is_windows_7, windows_version} ;
260+ pub use windows_platform:: { is_windows_7, windows_version} ;
261261
262262#[ cfg( windows) ]
263263mod windows_platform {
264- use std:: { iter:: once, os:: windows:: prelude:: OsStrExt } ;
265- use windows:: {
266- core:: { PCSTR , PCWSTR } ,
267- Win32 :: {
268- Foundation :: FARPROC ,
269- System :: {
270- LibraryLoader :: { GetProcAddress , LoadLibraryW } ,
271- SystemInformation :: OSVERSIONINFOW ,
272- } ,
273- } ,
274- } ;
275-
276264 /// Checks if we're running on Windows 7.
277265 pub fn is_windows_7 ( ) -> bool {
278- if let Some ( v) = windows_version ( ) {
279- // windows 7 is 6.1
280- if v. 0 == 6 && v. 1 == 1 {
281- return true ;
282- }
283- }
284- false
285- }
286-
287- fn encode_wide ( string : impl AsRef < std:: ffi:: OsStr > ) -> Vec < u16 > {
288- string. as_ref ( ) . encode_wide ( ) . chain ( once ( 0 ) ) . collect ( )
289- }
290-
291- /// Helper function to dynamically load function pointer.
292- /// `library` and `function` must be null-terminated.
293- pub fn get_function_impl ( library : & str , function : & str ) -> Option < FARPROC > {
294- let library = encode_wide ( library) ;
295- assert_eq ! ( function. chars( ) . last( ) , Some ( '\0' ) ) ;
296- let function = PCSTR :: from_raw ( function. as_ptr ( ) ) ;
297-
298- // Library names we will use are ASCII so we can use the A version to avoid string conversion.
299- let module = unsafe { LoadLibraryW ( PCWSTR :: from_raw ( library. as_ptr ( ) ) ) } . unwrap_or_default ( ) ;
300- if module. is_invalid ( ) {
301- None
302- } else {
303- Some ( unsafe { GetProcAddress ( module, function) } )
304- }
305- }
306-
307- macro_rules! get_function {
308- ( $lib: expr, $func: ident) => {
309- get_function_impl( concat!( $lib, '\0' ) , concat!( stringify!( $func) , '\0' ) )
310- . map( |f| unsafe { std:: mem:: transmute:: <windows:: Win32 :: Foundation :: FARPROC , $func>( f) } )
311- } ;
266+ let v = windows_version ( ) ;
267+ v. 0 == 6 && v. 1 == 1
312268 }
313269
314270 /// Returns a tuple of (major, minor, buildnumber) for the Windows version.
315- pub fn windows_version ( ) -> Option < ( u32 , u32 , u32 ) > {
316- type RtlGetVersion = unsafe extern "system" fn ( * mut OSVERSIONINFOW ) -> i32 ;
317- let handle = get_function ! ( "ntdll.dll" , RtlGetVersion ) ;
318- if let Some ( rtl_get_version) = handle {
319- unsafe {
320- let mut vi = OSVERSIONINFOW {
321- dwOSVersionInfoSize : 0 ,
322- dwMajorVersion : 0 ,
323- dwMinorVersion : 0 ,
324- dwBuildNumber : 0 ,
325- dwPlatformId : 0 ,
326- szCSDVersion : [ 0 ; 128 ] ,
327- } ;
328-
329- let status = ( rtl_get_version) ( & mut vi as _ ) ;
330-
331- if status >= 0 {
332- Some ( ( vi. dwMajorVersion , vi. dwMinorVersion , vi. dwBuildNumber ) )
333- } else {
334- None
335- }
336- }
337- } else {
338- None
339- }
271+ pub fn windows_version ( ) -> ( u32 , u32 , u32 ) {
272+ let v = windows_version:: OsVersion :: current ( ) ;
273+ ( v. major , v. minor , v. build )
340274 }
341275}
0 commit comments