From 184cff8a7731c83f049dedb0f8e20d91c36e77a3 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sun, 1 Nov 2015 18:27:34 +0000 Subject: Add support for version dependency checks --- src/gameinfoimpl.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/gameinfoimpl.cpp') diff --git a/src/gameinfoimpl.cpp b/src/gameinfoimpl.cpp index 025ce4e6..979e6c8d 100644 --- a/src/gameinfoimpl.cpp +++ b/src/gameinfoimpl.cpp @@ -18,8 +18,10 @@ along with Mod Organizer. If not, see . */ #include "gameinfoimpl.h" -#include +#include "gameinfo.h" #include + +#include #include @@ -52,3 +54,50 @@ QString GameInfoImpl::binaryName() const { return ToQString(GameInfo::instance().getBinaryName()); } + +namespace { + +QString GetAppVersion(std::wstring const &app_name) +{ + DWORD handle; + DWORD info_len = ::GetFileVersionInfoSizeW(app_name.c_str(), &handle); + if (info_len == 0) { + qDebug("GetFileVersionInfoSizeW Error %d", ::GetLastError()); + throw std::runtime_error("Failed to get version info"); + } + + std::vector buff(info_len); + if( ! ::GetFileVersionInfoW(app_name.c_str(), handle, info_len, buff.data())) { + qDebug("GetFileVersionInfoW Error %d", ::GetLastError()); + throw std::runtime_error("Failed to get version info"); + } + + VS_FIXEDFILEINFO *pFileInfo; + UINT buf_len; + if ( ! ::VerQueryValueW(buff.data(), L"\\", reinterpret_cast(&pFileInfo), &buf_len)) { + qDebug("VerQueryValueW Error %d", ::GetLastError()); + throw std::runtime_error("Failed to get version info"); + } + return QString("%1.%2.%3.%4").arg(HIWORD(pFileInfo->dwFileVersionMS)) + .arg(LOWORD(pFileInfo->dwFileVersionMS)) + .arg(HIWORD(pFileInfo->dwFileVersionLS)) + .arg(LOWORD(pFileInfo->dwFileVersionLS)); +} + +} + +QString GameInfoImpl::version() const +{ + std::wstring dir = GameInfo::instance().getGameDirectory(); + std::wstring exec = GameInfo::instance().getBinaryName(); + std::wstring target = L"\\\\?\\" + dir + L"\\" + exec; + return GetAppVersion(target.c_str()); +} + +QString GameInfoImpl::extenderVersion() const +{ + std::wstring dir = GameInfo::instance().getGameDirectory(); + std::wstring exec = GameInfo::instance().getExtenderName(); + std::wstring target = L"\\\\?\\" + dir + L"\\" + exec; + return GetAppVersion(target.c_str()); +} -- cgit v1.3.1