summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorJeremy Rimpo <jeremy.rimpo@servermonkey.com>2018-05-15 17:55:02 -0500
committerGitHub <noreply@github.com>2018-05-15 17:55:02 -0500
commit75e6c72ae4132ae4d71f5f04f666f5e33c17d1d3 (patch)
tree7dabba3c8eee2849d566eee8fd52a995dac7e220 /src/shared
parent2ee5f0e96dd6928c271e1b37cd1f77ddc456ef9c (diff)
parent9c1806cc74a1600f1c28610532d9a06434adf30d (diff)
Merge pull request #360 from AnyOldName3/better-version-parsing
Better version parsing
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.cpp28
-rw-r--r--src/shared/util.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/util.cpp b/src/shared/util.cpp
index 5491a9e6..008c5050 100644
--- a/src/shared/util.cpp
+++ b/src/shared/util.cpp
@@ -174,5 +174,33 @@ 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;
+ }
+}
+
} // namespace MOShared
diff --git a/src/shared/util.h b/src/shared/util.h
index 1e498059..75c382a7 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -45,6 +45,7 @@ std::wstring ToLower(const std::wstring &text);
bool CaseInsensitiveEqual(const std::wstring &lhs, const std::wstring &rhs);
VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName);
+std::wstring GetFileVersionString(const std::wstring &fileName);
} // namespace MOShared