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 --- SConstruct | 4 ---- src/gameinfoimpl.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++- src/gameinfoimpl.h | 2 ++ src/shared/fallout3info.h | 1 + src/shared/falloutnvinfo.h | 1 + src/shared/gameinfo.h | 1 + src/shared/oblivioninfo.h | 1 + src/shared/skyriminfo.h | 1 + 8 files changed, 57 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index eb3da432..5df6f96a 100644 --- a/SConstruct +++ b/SConstruct @@ -50,10 +50,6 @@ def setup_config_variables(): PathVariable.PathIsDir), PathVariable('SEVENZIPPATH', 'Path to 7zip sources', sevenzippath, PathVariable.PathIsDir), - PathVariable('ZLIBPATH', 'Path to zlib install', zlibpath, - PathVariable.PathIsDir). - PathVariable('ZLIBPATH', 'Path to zlib install', zlibpath, - PathVariable.PathIsDir), PathVariable('ZLIBPATH', 'Path to zlib install', zlibpath, PathVariable.PathIsDir) ) 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()); +} diff --git a/src/gameinfoimpl.h b/src/gameinfoimpl.h index 3ed7be6b..b7ac78c5 100644 --- a/src/gameinfoimpl.h +++ b/src/gameinfoimpl.h @@ -33,6 +33,8 @@ public: virtual Type type() const; virtual QString path() const; virtual QString binaryName() const; + virtual QString version() const; + virtual QString extenderVersion() const; }; diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 0045581d..62eb0a08 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -38,6 +38,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } virtual std::wstring getBinaryName() { return L"Fallout3.exe"; } + virtual std::wstring getExtenderName() { return L"fose_loader.exe"; } virtual GameInfo::Type getType() { return TYPE_FALLOUT3; } diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index e1a614d2..3039d8cc 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -38,6 +38,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } virtual std::wstring getBinaryName() { return L"FalloutNV.exe"; } + virtual std::wstring getExtenderName() { return L"nvse_loader.exe"; } virtual GameInfo::Type getType() { return TYPE_FALLOUTNV; } diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index a32b6b82..5b344932 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -60,6 +60,7 @@ public: virtual std::wstring getRegPath() = 0; virtual std::wstring getBinaryName() = 0; + virtual std::wstring getExtenderName() = 0; virtual GameInfo::Type getType() = 0; diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index 87ba26ff..02fa32c6 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -36,6 +36,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } virtual std::wstring getBinaryName() { return L"Oblivion.exe"; } + virtual std::wstring getExtenderName() { return L"obse_loader.exe"; } virtual GameInfo::Type getType() { return TYPE_OBLIVION; } diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index 5951f910..1824eb3e 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -38,6 +38,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() { return getRegPathStatic(); } virtual std::wstring getBinaryName() { return L"TESV.exe"; } + virtual std::wstring getExtenderName() { return L"skse_loader.exe"; } virtual GameInfo::Type getType() { return TYPE_SKYRIM; } -- cgit v1.3.1 From 1a12b1f1f6256139427c2516d314f25c593087c5 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Wed, 4 Nov 2015 21:39:14 +0000 Subject: Decided it shouldn't be an error if i can't get information about the file. --- src/gameinfoimpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gameinfoimpl.cpp b/src/gameinfoimpl.cpp index 979e6c8d..98b0fddf 100644 --- a/src/gameinfoimpl.cpp +++ b/src/gameinfoimpl.cpp @@ -63,20 +63,20 @@ QString GetAppVersion(std::wstring const &app_name) 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"); + return ""; } 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"); + return ""; } 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 ""; } return QString("%1.%2.%3.%4").arg(HIWORD(pFileInfo->dwFileVersionMS)) .arg(LOWORD(pFileInfo->dwFileVersionMS)) -- cgit v1.3.1 From cb09ace972731ecc9b0fb653b88d4c599f4530fc Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 5 Dec 2015 10:43:19 +0000 Subject: Hoist self with own petard - add const --- src/shared/fallout3info.h | 2 +- src/shared/falloutnvinfo.h | 2 +- src/shared/oblivioninfo.h | 2 +- src/shared/skyriminfo.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 698dcb25..fb60d6ae 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -37,7 +37,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() const { return getRegPathStatic(); } virtual std::wstring getBinaryName() const { return L"Fallout3.exe"; } - virtual std::wstring getExtenderName() { return L"fose_loader.exe"; } + virtual std::wstring getExtenderName() const { return L"fose_loader.exe"; } virtual GameInfo::Type getType() const { return TYPE_FALLOUT3; } diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index 67a72ec5..65f17013 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -38,7 +38,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() const { return getRegPathStatic(); } virtual std::wstring getBinaryName() const { return L"FalloutNV.exe"; } - virtual std::wstring getExtenderName() { return L"nvse_loader.exe"; } + virtual std::wstring getExtenderName() const { return L"nvse_loader.exe"; } virtual GameInfo::Type getType() const { return TYPE_FALLOUTNV; } diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index c05aac30..74e3fec6 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -36,7 +36,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() const { return getRegPathStatic(); } virtual std::wstring getBinaryName() const { return L"Oblivion.exe"; } - virtual std::wstring getExtenderName() { return L"obse_loader.exe"; } + virtual std::wstring getExtenderName() const { return L"obse_loader.exe"; } virtual GameInfo::Type getType() const { return TYPE_OBLIVION; } diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index f4dfb2c2..538fffb4 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -38,7 +38,7 @@ public: static std::wstring getRegPathStatic(); virtual std::wstring getRegPath() const { return getRegPathStatic(); } virtual std::wstring getBinaryName() const { return L"TESV.exe"; } - virtual std::wstring getExtenderName() { return L"skse_loader.exe"; } + virtual std::wstring getExtenderName() const { return L"skse_loader.exe"; } virtual GameInfo::Type getType() const { return TYPE_SKYRIM; } -- cgit v1.3.1