Skip to content

Commit

Permalink
makes GetVersionInfo static
Browse files Browse the repository at this point in the history
  • Loading branch information
knoxfighter committed Mar 3, 2024
1 parent 6d83703 commit 6810444
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
16 changes: 6 additions & 10 deletions UpdateCheckerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,30 @@ bool ArcdpsExtension::UpdateCheckerBase::UpdateState::ChangeStatus(Status pExpec
return true;
}

std::optional<ArcdpsExtension::UpdateCheckerBase::Version> ArcdpsExtension::UpdateCheckerBase::GetCurrentVersion(HMODULE pDll) noexcept {
std::expected<ArcdpsExtension::UpdateCheckerBase::Version, std::string> ArcdpsExtension::UpdateCheckerBase::GetCurrentVersion(HMODULE pDll) noexcept {
// GetModuleFileName
TCHAR moduleFileName[MAX_PATH + 1]{};
if (!GetModuleFileName(pDll, moduleFileName, MAX_PATH)) {
Log(std::format("GetCurrentVersion: GetModuleFileName failed - {}", GetLastError()));
return std::nullopt;
return std::unexpected(std::format("GetCurrentVersion: GetModuleFileName failed - {}", GetLastError()));
}

// GetFileVersionInfoSize
DWORD dummy; // this will get set to 0 (wtf windows api)
DWORD versionInfoSize = GetFileVersionInfoSize(moduleFileName, &dummy);
if (versionInfoSize == 0) {
Log(std::format("GetCurrentVersion: GetFileVersionInfoSize failed - {}", GetLastError()));
return std::nullopt;
return std::unexpected(std::format("GetCurrentVersion: GetFileVersionInfoSize failed - {}", GetLastError()));
}
std::vector<BYTE> data(versionInfoSize);

// GetFileVersionInfo
if (!GetFileVersionInfo(moduleFileName, NULL, versionInfoSize, &data[0])) {
Log(std::format("GetCurrentVersion: GetFileVersionInfo failed - {}", GetLastError()));
return std::nullopt;
return std::unexpected(std::format("GetCurrentVersion: GetFileVersionInfo failed - {}", GetLastError()));
}

UINT randomPointer = 0;
VS_FIXEDFILEINFO* fixedFileInfo = nullptr;
if (!VerQueryValue(&data[0], TEXT("\\"), (void**) &fixedFileInfo, &randomPointer)) {
Log(std::format("GetCurrentVersion: VerQueryValue failed - {}", GetLastError()));
return std::nullopt;
if (!VerQueryValue(data.data(), TEXT("\\"), (void**) &fixedFileInfo, &randomPointer)) {
std::unexpected(std::format("GetCurrentVersion: VerQueryValue failed - {}", GetLastError()));
}

return Version({HIWORD(fixedFileInfo->dwProductVersionMS), LOWORD(fixedFileInfo->dwProductVersionMS), HIWORD(fixedFileInfo->dwProductVersionLS), LOWORD(fixedFileInfo->dwProductVersionLS)});
Expand Down
3 changes: 2 additions & 1 deletion UpdateCheckerBase.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <array>
#include <expected>
#include <filesystem>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -63,7 +64,7 @@ namespace ArcdpsExtension {
std::string DownloadUrl;
};

std::optional<Version> GetCurrentVersion(HMODULE dll) noexcept;
static std::expected<Version, std::string> GetCurrentVersion(HMODULE dll) noexcept;
void ClearFiles(HMODULE pDll) noexcept;
std::unique_ptr<UpdateState> CheckForUpdate(HMODULE pDll, const Version& pCurrentVersion, std::string&& pRepo, bool pAllowPreRelease) noexcept;
std::unique_ptr<UpdateState> GetInstallState(std::string&& pInstallPath, std::string&& pRepo, bool pAllowPreRelease) noexcept;
Expand Down

0 comments on commit 6810444

Please sign in to comment.