diff options
author | Emma Miler <27428383+emma-miler@users.noreply.github.com> | 2022-03-26 00:56:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 00:56:52 +0100 |
commit | ebba08beb9e3227c2b646f83745fc0ce5b142264 (patch) | |
tree | 7c78d368aa1bc674a050b6aba12340b6c1ba1b1a /NorthstarDedicatedTest/version.cpp | |
parent | de7deafc7e6ba53deec8dd3c05d2ea5e7cf42264 (diff) | |
download | NorthstarLauncher-ebba08beb9e3227c2b646f83745fc0ce5b142264.tar.gz NorthstarLauncher-ebba08beb9e3227c2b646f83745fc0ce5b142264.zip |
Add version numbering to all master server requests (#113)
* Add version numbering to all master server requests
* Use "+dev" for user agent if dev version instead of "-dev"
* Replace "FindResource" with "FindResourceW"
As per code review suggestion
https://github.com/R2Northstar/NorthstarLauncher/pull/113#discussion_r834788821
* Set User-Agent in SetCommonHttpClientOptions
instead of for each curl call individually
As per code review suggestion
https://github.com/R2Northstar/NorthstarLauncher/pull/113#discussion_r834789168
Co-authored-by: GeckoEidechse <gecko.eidechse+git@pm.me>
Diffstat (limited to 'NorthstarDedicatedTest/version.cpp')
-rw-r--r-- | NorthstarDedicatedTest/version.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/version.cpp b/NorthstarDedicatedTest/version.cpp new file mode 100644 index 00000000..dfeb9670 --- /dev/null +++ b/NorthstarDedicatedTest/version.cpp @@ -0,0 +1,59 @@ +#include "version.h" +#include "pch.h" + +char version[16]; +char NSUserAgent[32]; + +void InitialiseVersion() { + HRSRC hResInfo; + DWORD dwSize; + HGLOBAL hResData; + LPVOID pRes, pResCopy; + UINT uLen = 0; + VS_FIXEDFILEINFO* lpFfi = NULL; + HINSTANCE hInst = ::GetModuleHandle(NULL); + + hResInfo = FindResourceW(hInst, MAKEINTRESOURCE(1), RT_VERSION); + if (hResInfo != NULL) { + dwSize = SizeofResource(hInst, hResInfo); + hResData = LoadResource(hInst, hResInfo); + if (hResData != NULL) { + pRes = LockResource(hResData); + pResCopy = LocalAlloc(LMEM_FIXED, dwSize); + if (pResCopy != 0) { + CopyMemory(pResCopy, pRes, dwSize); + VerQueryValueW(pResCopy, L"\\", (LPVOID*)&lpFfi, &uLen); + + DWORD dwFileVersionMS = lpFfi->dwFileVersionMS; + DWORD dwFileVersionLS = lpFfi->dwFileVersionLS; + + DWORD dwLeftMost = HIWORD(dwFileVersionMS); + DWORD dwSecondLeft = LOWORD(dwFileVersionMS); + DWORD dwSecondRight = HIWORD(dwFileVersionLS); + DWORD dwRightMost = LOWORD(dwFileVersionLS); + + // We actually use the rightmost integer do determine whether or not we're a debug/dev build + // If it is set to 1 (as in resources.rc), we are a dev build + // On github CI, we set this 1 to a 0 automatically as we replace the 0.0.0.1 with the real version number + if (dwRightMost == 1) { + sprintf(version, "%d.%d.%d.%d+dev", dwLeftMost, dwSecondLeft, dwSecondRight, dwRightMost); + sprintf(NSUserAgent, "R2Northstar/%d.%d.%d+dev", dwLeftMost, dwSecondLeft, dwSecondRight); + } + else { + sprintf(version, "%d.%d.%d.%d", dwLeftMost, dwSecondLeft, dwSecondRight, dwRightMost); + sprintf(NSUserAgent, "R2Northstar/%d.%d.%d", dwLeftMost, dwSecondLeft, dwSecondRight); + } + UnlockResource(hResData); + FreeResource(hResData); + LocalFree(pResCopy); + return; + } + UnlockResource(hResData); + FreeResource(hResData); + LocalFree(pResCopy); + } + } + // Could not locate version info for whatever reason + spdlog::error("Failed to load version info:\n{}", std::system_category().message(GetLastError())); + sprintf(NSUserAgent, "R2Northstar/0.0.0"); +} |