Browse Source

libobs: Use get_win_ver (not GetVersionEx)

jp9000 10 years ago
parent
commit
0fb79a4733
3 changed files with 18 additions and 26 deletions
  1. 6 10
      libobs/obs-win-crash-handler.c
  2. 9 13
      libobs/obs-windows.c
  3. 3 3
      libobs/util/platform-windows.c

+ 6 - 10
libobs/obs-win-crash-handler.c

@@ -24,6 +24,7 @@
 #include "obs-config.h"
 #include "util/dstr.h"
 #include "util/platform.h"
+#include "util/windows/win-version.h"
 
 typedef BOOL (WINAPI *ENUMERATELOADEDMODULES64)(HANDLE process,
 		PENUMLOADED_MODULES_CALLBACK64 enum_loaded_modules_callback,
@@ -84,7 +85,7 @@ struct exception_handler_data {
 	HMODULE                               dbghelp;
 	SYMBOL_INFOW                          *sym_info;
 	PEXCEPTION_POINTERS                   exception;
-	OSVERSIONINFOEX                       osvi;
+	struct win_version_info               win_version;
 	SYSTEMTIME                            time_info;
 	HANDLE                                process;
 
@@ -178,12 +179,7 @@ static inline void init_sym_info(struct exception_handler_data *data)
 
 static inline void init_version_info(struct exception_handler_data *data)
 {
-	data->osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-
-	if (!GetVersionEx((OSVERSIONINFO*)&data->osvi)) {
-		data->osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-		GetVersionEx((OSVERSIONINFO*)&data->osvi);
-	}
+	get_win_ver(&data->win_version);
 }
 
 #define PROCESSOR_REG_KEY L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"
@@ -247,13 +243,13 @@ static inline void write_header(struct exception_handler_data *data)
 	dstr_catf(&data->str, "Unhandled exception: %x\n"
 			"Fault address: %"PRIX64" (%s)\n"
 			"libobs version: "OBS_VERSION"\n"
-			"Windows version: %d.%d (build %d) %s\n"
+			"Windows version: %d.%d build %d (revision %d)\n"
 			"CPU: %s\n\n",
 			data->exception->ExceptionRecord->ExceptionCode,
 			data->main_trace.instruction_ptr,
 			data->module_name.array,
-			data->osvi.dwMajorVersion, data->osvi.dwMinorVersion,
-			data->osvi.dwBuildNumber, data->osvi.szCSDVersion,
+			data->win_version.major, data->win_version.minor,
+			data->win_version.build, data->win_version.revis,
 			data->cpu_info.array);
 }
 

+ 9 - 13
libobs/obs-windows.c

@@ -15,6 +15,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
 
+#include "util/windows/win-version.h"
 #include "util/platform.h"
 #include "util/dstr.h"
 #include "obs.h"
@@ -22,7 +23,6 @@
 
 #include <windows.h>
 
-static OSVERSIONINFOW osvi = {0};
 static uint32_t win_ver = 0;
 
 const char *get_module_extension(void)
@@ -174,16 +174,11 @@ static void log_available_memory(void)
 
 static void log_windows_version(void)
 {
-	char           *build = NULL;
+	struct win_version_info ver;
+	get_win_ver(&ver);
 
-	os_wcs_to_utf8_ptr(osvi.szCSDVersion, 0, &build);
-	blog(LOG_INFO, "Windows Version: %ld.%ld Build %ld %s",
-			osvi.dwMajorVersion,
-			osvi.dwMinorVersion,
-			osvi.dwBuildNumber,
-			build);
-
-	bfree(build);
+	blog(LOG_INFO, "Windows Version: %d.%d Build %d (revision: %d)",
+			ver.major, ver.minor, ver.build, ver.revis);
 }
 
 typedef HRESULT (WINAPI *dwm_is_composition_enabled_t)(BOOL*);
@@ -215,9 +210,10 @@ static void log_aero(void)
 
 void log_system_info(void)
 {
-	osvi.dwOSVersionInfoSize = sizeof(osvi);
-	GetVersionExW(&osvi);
-	win_ver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
+	struct win_version_info ver;
+	get_win_ver(&ver);
+
+	win_ver = (ver.major << 8) | ver.minor;
 
 	log_processor_info();
 	log_processor_cores();

+ 3 - 3
libobs/util/platform-windows.c

@@ -41,9 +41,9 @@ static inline uint64_t get_clockfreq(void)
 static inline uint32_t get_winver(void)
 {
 	if (!winver) {
-		OSVERSIONINFO osvi;
-		memset(&osvi, 0, sizeof(osvi));
-		winver = (osvi.dwMajorVersion << 16) | (osvi.dwMinorVersion);
+		struct win_version_info ver;
+		get_win_ver(&ver);
+		winver = (ver.major << 16) | ver.minor;
 	}
 
 	return winver;