• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版b1c2ecee3f1cc160920c6a701081857311dd7894 (tree)
时间2015-06-21 23:37:03
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Added get_file_version() function + workaround to make get_real_os_version() give the correct result on Windows 10+.

更改概述

差异

--- a/MUtilities_VS2013.vcxproj
+++ b/MUtilities_VS2013.vcxproj
@@ -164,7 +164,7 @@
164164 <SubSystem>Windows</SubSystem>
165165 <GenerateDebugInformation>true</GenerateDebugInformation>
166166 <AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\MSVC-2013\Debug\lib;$(SolutionDir)\..\Prerequisites\VisualLeakDetector\lib\Win32</AdditionalLibraryDirectories>
167- <AdditionalDependencies>QtCored4.lib;QtGuid4.lib;Winmm.lib;Psapi.lib;Sensapi.lib;PowrProf.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
167+ <AdditionalDependencies>QtCored4.lib;QtGuid4.lib;Winmm.lib;Psapi.lib;Sensapi.lib;PowrProf.lib;Shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
168168 </Link>
169169 </ItemDefinitionGroup>
170170 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -193,7 +193,7 @@
193193 <EnableCOMDATFolding>true</EnableCOMDATFolding>
194194 <OptimizeReferences>true</OptimizeReferences>
195195 <AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\MSVC-2013\Shared\lib;$(SolutionDir)\..\Prerequisites\VisualLeakDetector\lib\Win32</AdditionalLibraryDirectories>
196- <AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Psapi.lib;Sensapi.lib;PowrProf.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
196+ <AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Psapi.lib;Sensapi.lib;PowrProf.lib;Shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
197197 <GenerateDebugInformation>false</GenerateDebugInformation>
198198 </Link>
199199 </ItemDefinitionGroup>
--- a/include/MUtils/OSSupport.h
+++ b/include/MUtils/OSSupport.h
@@ -108,6 +108,9 @@ namespace MUtils
108108 typedef bool (*progress_callback_t)(const double &progress, void *const userData);
109109 MUTILS_API bool copy_file(const QString &sourcePath, const QString &outputPath, const bool &overwrite = true, const progress_callback_t callback = NULL, void *const userData = NULL);
110110
111+ //Get file version
112+ MUTILS_API bool get_file_version(const QString fileName, quint16 *const major = NULL, quint16 *const minor = NULL, quint16 *const patch = NULL, quint16 *const build = NULL);
113+
111114 //Get the OS version
112115 MUTILS_API const Version::os_version_t &os_version(void);
113116 MUTILS_API const char *os_friendly_name(const MUtils::OS::Version::os_version_t &os_version);
--- a/src/Config.h
+++ b/src/Config.h
@@ -31,4 +31,4 @@
3131
3232 #define VER_MUTILS_MAJOR 1
3333 #define VER_MUTILS_MINOR_HI 0
34-#define VER_MUTILS_MINOR_LO 3
34+#define VER_MUTILS_MINOR_LO 4
--- a/src/OSSupport_Win32.cpp
+++ b/src/OSSupport_Win32.cpp
@@ -177,6 +177,59 @@ MUTILS_API bool MUtils::OS::copy_file(const QString &sourcePath, const QString &
177177 }
178178
179179 ///////////////////////////////////////////////////////////////////////////////
180+// GET FILE VERSION
181+///////////////////////////////////////////////////////////////////////////////
182+
183+static bool get_file_version_helper(const QString fileName, PVOID buffer, const size_t &size, quint16 *const major, quint16 *const minor, quint16 *const patch, quint16 *const build)
184+{
185+ if(!GetFileVersionInfo(MUTILS_WCHR(fileName), 0, size, buffer))
186+ {
187+ qWarning("GetFileVersionInfo() has failed, file version cannot be determined!");
188+ return false;
189+ }
190+
191+ VS_FIXEDFILEINFO *verInfo;
192+ UINT verInfoLen;
193+ if(!VerQueryValue(buffer, L"\\", (LPVOID*)(&verInfo), &verInfoLen))
194+ {
195+ qWarning("VerQueryValue() has failed, file version cannot be determined!");
196+ return false;
197+ }
198+
199+ if(major) *major = quint16((verInfo->dwFileVersionMS >> 16) & 0x0000FFFF);
200+ if(minor) *minor = quint16((verInfo->dwFileVersionMS) & 0x0000FFFF);
201+ if(patch) *patch = quint16((verInfo->dwFileVersionLS >> 16) & 0x0000FFFF);
202+ if(build) *build = quint16((verInfo->dwFileVersionLS) & 0x0000FFFF);
203+
204+ return true;
205+}
206+
207+bool MUtils::OS::get_file_version(const QString fileName, quint16 *const major, quint16 *const minor, quint16 *const patch, quint16 *const build)
208+{
209+ if(major) *major = 0U; if(minor) *minor = 0U;
210+ if(patch) *patch = 0U; if(build) *build = 0U;
211+
212+ const DWORD size = GetFileVersionInfoSize(MUTILS_WCHR(fileName), NULL);
213+ if(size < 1)
214+ {
215+ qWarning("GetFileVersionInfoSize() has failed, file version cannot be determined!");
216+ return false;
217+ }
218+
219+ PVOID buffer = _malloca(size);
220+ if(!buffer)
221+ {
222+ qWarning("Memory allocation has failed!");
223+ return false;
224+ }
225+
226+ const bool success = get_file_version_helper(fileName, buffer, size, major, minor, patch, build);
227+
228+ _freea(buffer);
229+ return success;
230+}
231+
232+///////////////////////////////////////////////////////////////////////////////
180233 // OS VERSION DETECTION
181234 ///////////////////////////////////////////////////////////////////////////////
182235
@@ -322,6 +375,21 @@ static bool get_real_os_version(unsigned int *major, unsigned int *minor, bool *
322375 break;
323376 }
324377
378+ //Workaround for the mess that is sometimes referred to as "Windows 10"
379+ if(((*major) > 6) || (((*major) == 6) && ((*minor) >= 2)))
380+ {
381+ quint16 kernel32_major, kernel32_minor;
382+ if(MUtils::OS::get_file_version(QLatin1String("kernel32"), &kernel32_major, &kernel32_minor))
383+ {
384+ if((kernel32_major > (*major)) || ((kernel32_major == (*major)) && (kernel32_minor > (*minor))))
385+ {
386+ *major = kernel32_major;
387+ *minor = kernel32_minor;
388+ *pbOverride = true;
389+ }
390+ }
391+ }
392+
325393 return true;
326394 }
327395
Show on old repository browser