mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
LP-2 remove unused windows specific utility method winGetDLLVersion (additionally had compile warnings)
This commit is contained in:
parent
b03833e96b
commit
0dc76168a3
@ -30,10 +30,6 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QLibrary>
|
||||
#include <QtCore/QTextStream>
|
||||
|
||||
namespace Utils {
|
||||
QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error)
|
||||
@ -53,60 +49,4 @@ QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error)
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
|
||||
const QString &name,
|
||||
QString *errorMessage)
|
||||
{
|
||||
// Resolve required symbols from the version.dll
|
||||
typedef DWORD (APIENTRY * GetFileVersionInfoSizeProtoType)(LPCTSTR, LPDWORD);
|
||||
typedef BOOL (APIENTRY * GetFileVersionInfoWProtoType)(LPCWSTR, DWORD, DWORD, LPVOID);
|
||||
typedef BOOL (APIENTRY * VerQueryValueWProtoType)(const LPVOID, LPWSTR lpSubBlock, LPVOID, PUINT);
|
||||
|
||||
const char *versionDLLC = "version.dll";
|
||||
QLibrary versionLib(QLatin1String(versionDLLC), 0);
|
||||
if (!versionLib.load()) {
|
||||
*errorMessage = QString::fromLatin1("Unable load %1: %2").arg(QLatin1String(versionDLLC), versionLib.errorString());
|
||||
return QString();
|
||||
}
|
||||
// MinGW requires old-style casts
|
||||
GetFileVersionInfoSizeProtoType getFileVersionInfoSizeW = (GetFileVersionInfoSizeProtoType)(versionLib.resolve("GetFileVersionInfoSizeW"));
|
||||
GetFileVersionInfoWProtoType getFileVersionInfoW = (GetFileVersionInfoWProtoType)(versionLib.resolve("GetFileVersionInfoW"));
|
||||
VerQueryValueWProtoType verQueryValueW = (VerQueryValueWProtoType)(versionLib.resolve("VerQueryValueW"));
|
||||
if (!getFileVersionInfoSizeW || !getFileVersionInfoW || !verQueryValueW) {
|
||||
*errorMessage = QString::fromLatin1("Unable to resolve all required symbols in %1").arg(QLatin1String(versionDLLC));
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Now go ahead, read version info resource
|
||||
DWORD dummy = 0;
|
||||
const LPCTSTR fileName = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGWsy
|
||||
const DWORD infoSize = (*getFileVersionInfoSizeW)(fileName, &dummy);
|
||||
if (infoSize == 0) {
|
||||
*errorMessage = QString::fromLatin1("Unable to determine the size of the version information of %1: %2").arg(name, winErrorMessage(GetLastError()));
|
||||
return QString();
|
||||
}
|
||||
QByteArray dataV(infoSize + 1, '\0');
|
||||
char *data = dataV.data();
|
||||
if (!(*getFileVersionInfoW)(fileName, dummy, infoSize, data)) {
|
||||
*errorMessage = QString::fromLatin1("Unable to determine the version information of %1: %2").arg(name, winErrorMessage(GetLastError()));
|
||||
return QString();
|
||||
}
|
||||
VS_FIXEDFILEINFO *versionInfo;
|
||||
UINT len = 0;
|
||||
if (!(*verQueryValueW)(data, TEXT("\\"), &versionInfo, &len)) {
|
||||
*errorMessage = QString::fromLatin1("Unable to determine version string of %1: %2").arg(name, winErrorMessage(GetLastError()));
|
||||
return QString();
|
||||
}
|
||||
QString rc;
|
||||
switch (t) {
|
||||
case WinDLLFileVersion:
|
||||
QTextStream(&rc) << HIWORD(versionInfo->dwFileVersionMS) << '.' << LOWORD(versionInfo->dwFileVersionMS);
|
||||
break;
|
||||
case WinDLLProductVersion:
|
||||
QTextStream(&rc) << HIWORD(versionInfo->dwProductVersionMS) << '.' << LOWORD(versionInfo->dwProductVersionMS);
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
} // namespace Utils
|
||||
|
@ -39,11 +39,5 @@ namespace Utils {
|
||||
// Helper to format a Windows error message, taking the
|
||||
// code as returned by the GetLastError()-API.
|
||||
QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error);
|
||||
|
||||
// Determine a DLL version
|
||||
enum WinDLLVersionType { WinDLLFileVersion, WinDLLProductVersion };
|
||||
QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
|
||||
const QString &name,
|
||||
QString *errorMessage);
|
||||
} // namespace Utils
|
||||
#endif // WINUTILS_H
|
||||
|
Loading…
Reference in New Issue
Block a user