Skip to content

Commit

Permalink
Show dialog with API error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaterakis committed Aug 22, 2022
1 parent 6e63e28 commit 7a8368c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions sgdboop.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ int _sourceModsCount = 0;
int _goldSourceModsCount = 0;
int _apiReturnedLines = 0;

// Add an icon to IUP windows
void loadIupIcon() {
unsigned char image_data[256] = { 0 };

Ihandle* sgdboop_image = IupImage(16, 16, image_data);
IupSetAttribute(sgdboop_image, "0", "BGCOLOR");
IupSetHandle("SGDBOOPIMAGE", sgdboop_image);
IupSetGlobal("ICON", "SGDBOOPIMAGE");
}

// Log error messages
void logError(const char* error, const int errorCode)
{
time_t now = time(0);
Expand Down Expand Up @@ -91,6 +102,7 @@ void logError(const char* error, const int errorCode)
}
}

// Log an error and exit with the given error code
void exitWithError(const char* error, const int errorCode) {
logError(error, errorCode);
exit(errorCode);
Expand Down Expand Up @@ -126,7 +138,7 @@ char*** callAPI(char* grid_types, char* grid_ids, char* mode)
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, TRUE);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, FALSE);
headers = curl_slist_append(headers, authHeader);
headers = curl_slist_append(headers, apiVersionHeader);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
Expand All @@ -140,6 +152,13 @@ char*** callAPI(char* grid_types, char* grid_ids, char* mode)
char* message = malloc(1000);
strcpy(message, "API Error: ");
strcat(message, s.ptr);

if (startsWith(s.ptr, "error-")) {
strreplace(message, "error-", " ");
IupOpen(NULL, NULL);
loadIupIcon();
IupMessage("SGDBoop Error", message);
}
exitWithError(message, (int)http_code);
}

Expand Down Expand Up @@ -1029,16 +1048,7 @@ void updateVdf(struct nonSteamApp* appData, char* filePath) {
}
}

// Add an icon to IUP windows
void loadIupIcon() {
unsigned char image_data[256] = { 0 };

Ihandle* sgdboop_image = IupImage(16, 16, image_data);
IupSetAttribute(sgdboop_image, "0", "BGCOLOR");
IupSetHandle("SGDBOOPIMAGE", sgdboop_image);
IupSetGlobal("ICON", "SGDBOOPIMAGE");
}

// Main
int main(int argc, char** argv)
{
// If no arguments were given, register the program
Expand Down

0 comments on commit 7a8368c

Please sign in to comment.