Skip to content

Commit

Permalink
Merge pull request #144 from mxve/versioncheck
Browse files Browse the repository at this point in the history
Fix GitHub version check
  • Loading branch information
Rackover authored Sep 28, 2024
2 parents 717ae61 + ac72a80 commit 68bf9e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/Components/Modules/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Updater.hpp"
#include "Scheduler.hpp"
#include "version.hpp"

#include <Utils/WebIO.hpp>

Expand All @@ -13,21 +14,11 @@ namespace Components
{
const Game::dvar_t* cl_updateAvailable;

// If they use the alterware-launcher once to install they will have this file
// If they don't, what are they waiting for?
constexpr auto* REVISION_FILE = ".iw4xrevision";
constexpr auto* GITHUB_REMOTE_URL = "https://api.github.com/repos/iw4x/iw4x-client/releases/latest";
constexpr auto* INSTALL_GUIDE_REMOTE_URL = "https://forum.alterware.dev/t/how-to-install-the-alterware-launcher/56";

void CheckForUpdate()
{
std::string revision;
if (!Utils::IO::ReadFile(REVISION_FILE, &revision) || revision.empty())
{
Logger::Print("{} does not exist. Notifying the user an update is available\n", REVISION_FILE);
Game::Dvar_SetBool(cl_updateAvailable, true);
}

const auto result = Utils::WebIO("IW4x", GITHUB_REMOTE_URL).setTimeout(5000)->get();
if (result.empty())
{
Expand All @@ -52,8 +43,8 @@ namespace Components
return;
}

const auto* tag = doc["tag_name"].GetString();
if (revision != tag)
const std::string tag = doc["tag_name"].GetString();
if (REVISION_STR != tag)
{
// A new version came out!
Game::Dvar_SetBool(cl_updateAvailable, true);
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/WebIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace Utils
if (success) *success = false;
if (!this->openConnection()) return {};

static const char* acceptTypes[] = { "application/x-www-form-urlencoded", nullptr };
static const char* acceptTypes[] = { "application/x-www-form-urlencoded", "application/json", nullptr };

DWORD dwFlag = INTERNET_FLAG_RELOAD | (this->isSecuredConnection() ? INTERNET_FLAG_SECURE : 0);

Expand Down Expand Up @@ -298,7 +298,7 @@ namespace Utils

DWORD statusCode = 404;
DWORD length = sizeof(statusCode);
if (HttpQueryInfoA(this->hFile_, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE, &statusCode, &length, nullptr) == FALSE || (statusCode != 200 && statusCode != 201))
if (HttpQueryInfoA(this->hFile_, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE, &statusCode, &length, nullptr) == FALSE || (statusCode != 200 && statusCode != 201 && statusCode != 304))
{
this->closeConnection();
return {};
Expand Down

0 comments on commit 68bf9e5

Please sign in to comment.