Skip to content

Commit

Permalink
feat(updater): add check for update server response
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinipux322 committed Nov 30, 2023
1 parent 182bcd8 commit e474657
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Updater/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace std::filesystem;

#define MAX_LOADSTRING 100
#define VERSION "1.0.2"
#define VERSION "1.1.0"

HINSTANCE hInst;
HWND hWnd;
Expand Down Expand Up @@ -275,18 +275,22 @@ void InstallOrProceed() {
return;
}

std::string data = GetUrl(API_URL GET_CACHES);
bool updateServerAvaliable = IsUrlValid(API_URL GET_CACHES);

tinyxml2::XMLDocument doc;
doc.Parse(data.c_str());
if (updateServerAvaliable) {
std::string data = GetUrl(API_URL GET_CACHES);

if (IsUpdaterNeedToUpdate(doc)) {
return;
}
tinyxml2::XMLDocument doc;
doc.Parse(data.c_str());

SetWindowData(L"Checking updates...", 0);
if (IsUpdaterNeedToUpdate(doc)) {
return;
}

CheckFilesToUpdate(doc, appPath + L"\\");
SetWindowData(L"Checking updates...", 0);

CheckFilesToUpdate(doc, appPath + L"\\");
}

SetWindowData(L"Starting app...", 100);

Expand Down
23 changes: 23 additions & 0 deletions Updater/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ std::string GetUrl(std::string const& url)
return data;
}

bool IsUrlValid(std::string const& url)
{
CURL* curl;
CURLcode response;

curl = curl_easy_init();

if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

/* don't write output to stdout */
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);

/* Perform the request */
response = curl_easy_perform(curl);

/* always cleanup */
curl_easy_cleanup(curl);
}

return (response == CURLE_OK) ? true : false;
}

bool UnpackArchive(std::wstring path, std::wstring zipName)
{
int err = 0;
Expand Down
1 change: 1 addition & 0 deletions Updater/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ std::string WideStringToString(const std::wstring& wide_string);
std::vector<std::string> Split(const std::string& s, char delim);
std::string GetFileHash(std::wstring path);
void DownloadFile(std::wstring path, std::string url, std::wstring name);
bool IsUrlValid(std::string const& url);
std::string GetUrl(std::string const& url);
bool UnpackArchive(std::wstring path, std::wstring zipName);

0 comments on commit e474657

Please sign in to comment.