]> wimlib.net Git - wimlib/blobdiff - src/win32_common.c
Win32: Improvements on checking for Windows version and FS features
[wimlib] / src / win32_common.c
index 0a7a6d55c48b9c423df776a39a2b13d7919ba89b..484afea6061eda610f8093687a1a3a0fa8fa7aa6 100644 (file)
@@ -1,3 +1,28 @@
+/*
+ * win32_common.c - Windows code common to applying and capturing images, as
+ * well as replacements for various functions not available on Windows, such as
+ * fsync().
+ */
+
+/*
+ * Copyright (C) 2013 Eric Biggers
+ *
+ * This file is part of wimlib, a library for working with WIM files.
+ *
+ * wimlib is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ */
+
 #ifdef __WIN32__
 
 #include <shlwapi.h> /* for PathMatchSpecW() */
@@ -594,8 +619,20 @@ HANDLE (WINAPI *win32func_FindFirstStreamW)(LPCWSTR lpFileName,
 BOOL (WINAPI *win32func_FindNextStreamW)(HANDLE hFindStream,
                                         LPVOID lpFindStreamData) = NULL;
 
+static OSVERSIONINFO windows_version_info = {
+       .dwOSVersionInfoSize = sizeof(OSVERSIONINFO),
+};
+
 static HMODULE hKernel32 = NULL;
 
+bool
+windows_version_is_at_least(unsigned major, unsigned minor)
+{
+       return windows_version_info.dwMajorVersion > major ||
+               (windows_version_info.dwMajorVersion == major &&
+                windows_version_info.dwMinorVersion >= minor);
+}
+
 /* Try to dynamically load some functions */
 void
 win32_global_init()
@@ -609,25 +646,21 @@ win32_global_init()
                        err = GetLastError();
                        WARNING("Can't load Kernel32.dll");
                        win32_error(err);
-                       return;
                }
        }
 
-       DEBUG("Looking for FindFirstStreamW");
-       win32func_FindFirstStreamW = (void*)GetProcAddress(hKernel32, "FindFirstStreamW");
-       if (!win32func_FindFirstStreamW) {
-               WARNING("Could not find function FindFirstStreamW() in Kernel32.dll!");
-               WARNING("Capturing alternate data streams will not be supported.");
-               return;
+       if (hKernel32) {
+               win32func_FindFirstStreamW = (void*)GetProcAddress(hKernel32,
+                                                                  "FindFirstStreamW");
+               if (win32func_FindFirstStreamW) {
+                       win32func_FindNextStreamW = (void*)GetProcAddress(hKernel32,
+                                                                         "FindNextStreamW");
+                       if (!win32func_FindNextStreamW)
+                               win32func_FindFirstStreamW = NULL;
+               }
        }
 
-       DEBUG("Looking for FindNextStreamW");
-       win32func_FindNextStreamW = (void*)GetProcAddress(hKernel32, "FindNextStreamW");
-       if (!win32func_FindNextStreamW) {
-               WARNING("Could not find function FindNextStreamW() in Kernel32.dll!");
-               WARNING("Capturing alternate data streams will not be supported.");
-               win32func_FindFirstStreamW = NULL;
-       }
+       GetVersionEx(&windows_version_info);
 }
 
 void