Skip to content

Commit

Permalink
Properly detect when the game has been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Connicpu committed Feb 13, 2019
1 parent 36aaf2f commit c548470
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
29 changes: 18 additions & 11 deletions FFXIVLauncher/Login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions FFXIVLauncher/Login.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileHash> 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);
}
6 changes: 3 additions & 3 deletions FFXIVLauncher/LoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c548470

Please sign in to comment.