summaryrefslogtreecommitdiff
path: root/src/shared/util.cpp
diff options
context:
space:
mode:
authorBrian Munro <brian.alexander.munro@gmail.com>2018-08-02 09:15:12 +0200
committerGitHub <noreply@github.com>2018-08-02 09:15:12 +0200
commit9a3a15b1f6339589be97e2546b7d532d30abc292 (patch)
tree2776d6834b92fdc95b5b26ab43e9e743e10c1128 /src/shared/util.cpp
parent886fb10288baf4f52af2ad812a1c2121e138a16e (diff)
parent1ea43586d8eb304d8e91bf7f1480d7e4db5ef05f (diff)
Merge pull request #454 from Modorganizer2/Develop
Release 2.1.4
Diffstat (limited to 'src/shared/util.cpp')
-rw-r--r--src/shared/util.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/shared/util.cpp b/src/shared/util.cpp
index 5491a9e6..102565f5 100644
--- a/src/shared/util.cpp
+++ b/src/shared/util.cpp
@@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <DbgHelp.h>
#include <set>
#include <boost/scoped_array.hpp>
+#include <QApplication>
namespace MOShared {
@@ -174,5 +175,78 @@ VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
}
}
+std::wstring GetFileVersionString(const std::wstring &fileName)
+{
+ DWORD handle = 0UL;
+ DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
+ if (size == 0) {
+ throw windows_error("failed to determine file version info size");
+ }
+
+ boost::scoped_array<char> buffer(new char[size]);
+ try {
+ handle = 0UL;
+ if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer.get())) {
+ throw windows_error("failed to determine file version info");
+ }
+
+ LPVOID strBuffer = nullptr;
+ UINT strLength = 0;
+ if (!::VerQueryValue(buffer.get(), L"\\StringFileInfo\\040904B0\\ProductVersion", &strBuffer, &strLength)) {
+ throw windows_error("failed to determine file version");
+ }
+
+ return std::wstring((LPCTSTR)strBuffer);
+ }
+ catch (...) {
+ throw;
+ }
+}
+
+MOBase::VersionInfo createVersionInfo()
+{
+ VS_FIXEDFILEINFO version = GetFileVersion(QApplication::applicationFilePath().toStdWString());
+
+ if (version.dwFileFlags | VS_FF_PRERELEASE)
+ {
+ // Pre-release builds need annotating
+ QString versionString = QString::fromStdWString(GetFileVersionString(QApplication::applicationFilePath().toStdWString()));
+
+ // The pre-release flag can be set without the string specifying what type of pre-release
+ bool noLetters = true;
+ for (QChar character : versionString)
+ {
+ if (character.isLetter())
+ {
+ noLetters = false;
+ break;
+ }
+ }
+
+ if (noLetters)
+ {
+ // Default to pre-alpha when release type is unspecified
+ return MOBase::VersionInfo(version.dwFileVersionMS >> 16,
+ version.dwFileVersionMS & 0xFFFF,
+ version.dwFileVersionLS >> 16,
+ version.dwFileVersionLS & 0xFFFF,
+ MOBase::VersionInfo::RELEASE_PREALPHA);
+ }
+ else
+ {
+ // Trust the string to make sense
+ return MOBase::VersionInfo(versionString);
+ }
+ }
+ else
+ {
+ // Non-pre-release builds just need their version numbers reading
+ return MOBase::VersionInfo(version.dwFileVersionMS >> 16,
+ version.dwFileVersionMS & 0xFFFF,
+ version.dwFileVersionLS >> 16,
+ version.dwFileVersionLS & 0xFFFF);
+ }
+}
+
} // namespace MOShared