From 689378b435c73b624cfdea8fe971db6b1d72c48e Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 6 Oct 2019 22:17:00 +0200 Subject: Move GetModuleName to Common This unifies GetModuleFileName calls between Dolphin and WinUpdater and allows to gracefully remove MAX_PATH limit from GetExePath --- Source/Core/Common/CompatPatches.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'Source/Core/Common/CompatPatches.cpp') diff --git a/Source/Core/Common/CompatPatches.cpp b/Source/Core/Common/CompatPatches.cpp index 03963ccdee..e07028e9e4 100644 --- a/Source/Core/Common/CompatPatches.cpp +++ b/Source/Core/Common/CompatPatches.cpp @@ -4,12 +4,14 @@ #include #include +#include #include #include #include #include +#include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" #include "Common/LdrWatcher.h" #include "Common/StringUtil.h" @@ -162,37 +164,26 @@ struct Version } }; -static bool GetModulePath(const wchar_t* name, std::wstring* path) +static std::optional GetModulePath(const wchar_t* name) { auto module = GetModuleHandleW(name); if (module == nullptr) - return false; - DWORD path_len = MAX_PATH; -retry: - path->resize(path_len); - path_len = GetModuleFileNameW(module, const_cast(path->data()), - static_cast(path->size())); - if (!path_len) - return false; - auto error = GetLastError(); - if (error == ERROR_SUCCESS) - return true; - if (error == ERROR_INSUFFICIENT_BUFFER) - goto retry; - return false; + return std::nullopt; + + return GetModuleName(module); } static bool GetModuleVersion(const wchar_t* name, Version* version) { - std::wstring path; - if (!GetModulePath(name, &path)) + auto path = GetModulePath(name); + if (!path) return false; DWORD handle; - DWORD data_len = GetFileVersionInfoSizeW(path.c_str(), &handle); + DWORD data_len = GetFileVersionInfoSizeW(path->c_str(), &handle); if (!data_len) return false; std::vector block(data_len); - if (!GetFileVersionInfoW(path.c_str(), handle, data_len, block.data())) + if (!GetFileVersionInfoW(path->c_str(), handle, data_len, block.data())) return false; void* buf; UINT buf_len; -- cgit v1.2.3