diff --git a/FFXIVLauncher/Login.cpp b/FFXIVLauncher/Login.cpp index 0a4b0ce..468ed83 100644 --- a/FFXIVLauncher/Login.cpp +++ b/FFXIVLauncher/Login.cpp @@ -328,6 +328,22 @@ static void EncodeFormURIComponent(std::ostream & output, char c) } bool HashFile(std::ostream & output, const fs::path & path) +{ + byte buf[160 / 8]; + HashFile(buf, path); + + output << fs::file_size(path) << '/'; + output << std::hex; + for (size_t i = 0; i < 160 / 8; i++) + { + output << std::setfill('0') << std::setw(2) << (uint32_t)buf[i]; + } + output << std::dec; + + return true; +} + +bool HashFile(byte(&output)[160 / 8], const fs::path & path) { HCRYPTPROV hProv = 0; HCRYPTHASH hHash = 0; @@ -360,17 +376,8 @@ bool HashFile(std::ostream & output, const fs::path & path) return false; } - numread = 160 / 8; - CryptGetHashParam(hHash, HP_HASHVAL, buf, &numread, 0); - - output << fs::file_size(path) << '/'; - output << std::hex; - for (size_t i = 0; i < numread; i++) - { - output << std::setfill('0') << std::setw(2) << (uint32_t)buf[i]; - } - output << std::dec; - + numread = sizeof(output); + CryptGetHashParam(hHash, HP_HASHVAL, output, &numread, 0); return true; } diff --git a/FFXIVLauncher/Login.h b/FFXIVLauncher/Login.h index 9baae08..b883280 100644 --- a/FFXIVLauncher/Login.h +++ b/FFXIVLauncher/Login.h @@ -14,3 +14,25 @@ LoginResult PerformLogin(); void LaunchGame(); void LaunchUpdater(); bool BootWasReplaced(); + + +bool HashFile(byte(&buf)[160 / 8], const fs::path &path); + +struct FileHash { byte buf[160 / 8]; }; +inline std::optional HashFile(const fs::path &path) +{ + FileHash hash; + if (!HashFile(hash.buf, path)) + return {}; + return hash; +} + +inline bool operator==(const FileHash &lhs, const FileHash &rhs) +{ + return memcmp(lhs.buf, rhs.buf, sizeof(lhs.buf)) == 0; +} + +inline bool operator!=(const FileHash &lhs, const FileHash &rhs) +{ + return !(lhs == rhs); +} diff --git a/FFXIVLauncher/LoginDialog.cpp b/FFXIVLauncher/LoginDialog.cpp index 1cb92fe..7dfd2bd 100644 --- a/FFXIVLauncher/LoginDialog.cpp +++ b/FFXIVLauncher/LoginDialog.cpp @@ -156,9 +156,9 @@ static void InitializeUI(HWND dialog) noexcept if (self_path != boot) { - auto selfsize = fs::file_size(self_path); - auto bootsize = fs::file_size(boot); - if (selfsize != bootsize) + auto selfhash = HashFile(self_path); + auto boothash = HashFile(boot); + if (selfhash != boothash) { auto hInstall = GetDlgItem(dialog, IDC_INSTALLBTN); auto style = GetWindowLongW(hInstall, GWL_STYLE);