From a4c4dbc227686c3f340dcaa13751c20e2d722309 Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Mon, 26 May 2025 13:08:15 -0400 Subject: [PATCH] Added basic error handling for the cURL calls --- src/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 588f1ad..86229ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ CURL *curl; CURLcode res; std::string old_response = "Dummy"; std::string walltaker_id = ""; - +NOTIFYICONDATAA nid; int imgconvert(std::string filepath){ int width; @@ -92,6 +92,11 @@ int UpdateWallpaper(){ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getAnswerFunction); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string); res = curl_easy_perform(curl); + if (res != 0){ + // Connection failed for some reason, exit fuction + printf("Error connecting to API, retrying in 10 seconds...\n"); + return 0; + } //std::cout << response_string << "\n"; // Who needs parsing when you have regex? @@ -115,7 +120,11 @@ int UpdateWallpaper(){ img = fopen(fname.c_str(), "wb"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, img); //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_easy_perform(curl); + res = curl_easy_perform(curl); + if (res != 0){ + printf("Error connecting to e621, retrying in 10 seconds...\n"); + return 0; + } old_response = esixurl; fclose(img); @@ -165,11 +174,12 @@ int main (int argc, char *argv[]) { LoadConfig(); HWND hwnd = CreateWindowW(L"static", L"Dummy Window", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL); - printf("Starting Walltaker95, please wait...\n"); - NOTIFYICONDATAA nid; + //printf("Starting Walltaker95, please wait...\n"); + nid.hWnd = hwnd; // handle to the window that will display the tray icon + nid.cbSize = NOTIFYICONDATA_V2_SIZE; nid.uID = 100; // unique identifier for the tray icon - nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; // flags to indicate which fields are valid + nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO; // flags to indicate which fields are valid nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); nid.uVersion = 0; nid.uCallbackMessage = APPWM_ICONNOTIFY;