Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub version check #144

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading