Cleaned up code a bit

This commit is contained in:
Nick Martin 2025-05-25 09:37:03 -04:00
parent 299a137580
commit 16392d1c0d

View file

@ -4,9 +4,11 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <regex> #include <regex>
#include <conio.h> #include <future>
//#define _WIN32_WINNT 0x0500 //#define _WIN32_WINNT 0x0500
#include <windows.h> #include <windows.h>
#define APPWM_ICONNOTIFY (WM_APP + 1)
#include <conio.h>
#include "../wt95.rc" #include "../wt95.rc"
#include <shellapi.h> #include <shellapi.h>
#include <commctrl.h> #include <commctrl.h>
@ -16,6 +18,9 @@
#include "stb_image.h" #include "stb_image.h"
#include "stb_image_write.h" #include "stb_image_write.h"
CURL *curl;
CURLcode res;
int imgconvert(std::string filepath){ int imgconvert(std::string filepath){
int width; int width;
@ -44,33 +49,12 @@ size_t getAnswerFunction(void* ptr, size_t size, size_t nmemb, std::string* data
return size * nmemb; return size * nmemb;
} }
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream){
{ size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); return written;
return written;
} }
int main (int argc, char *argv[]) { int UpdateWallpaper(){
CURL *curl;
CURLcode res;
HWND hwnd = GetConsoleWindow();
NOTIFYICONDATAA nid;
nid.hWnd = hwnd; // handle to the window that will display the tray icon
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.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
strcpy(nid.szTip,"Walltaker95\0");
//nid.szTip[]="Walltaker95";
printf("test\n");
curl = curl_easy_init();
if(!curl) {
printf("Curl isn't working for some reason\n");
getchar();
return 0;
}
std::string response_string; std::string response_string;
FILE *img; FILE *img;
@ -87,7 +71,9 @@ int main (int argc, char *argv[]) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
std::cout << response_string << "\n"; //std::cout << response_string << "\n";
// Who needs parsing when you have regex?
std::regex rgx("\"post_url\":[\"]((?=(\\\\?))\\2.*?)[\"]"); std::regex rgx("\"post_url\":[\"]((?=(\\\\?))\\2.*?)[\"]");
std::smatch match; std::smatch match;
std::regex_search(response_string, match, rgx); std::regex_search(response_string, match, rgx);
@ -95,10 +81,8 @@ int main (int argc, char *argv[]) {
esixurl.erase(0, 12); esixurl.erase(0, 12);
esixurl.erase(esixurl.size()-1); esixurl.erase(esixurl.size()-1);
std::cout << esixurl << '\n';
std::string fileext = esixurl; std::string fileext = esixurl;
fileext.erase(0, fileext.size()-4); fileext.erase(0, fileext.size()-4);
std::cout << fileext << '\n';
std::string fname = "tmp" + fileext; std::string fname = "tmp" + fileext;
curl_easy_setopt(curl, CURLOPT_URL, esixurl.c_str()); curl_easy_setopt(curl, CURLOPT_URL, esixurl.c_str());
@ -109,13 +93,12 @@ int main (int argc, char *argv[]) {
curl_easy_perform(curl); curl_easy_perform(curl);
fclose(img); fclose(img);
imgconvert(fname); imgconvert(fname);
// Open the registry key for writing // Open the registry key for writing
HKEY hKey = NULL; HKEY hKey = NULL;
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) { if (RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) {
std::cerr << "Error: Could not open registry key for writing." << std::endl; printf("Error: Could not open registry key for writing.\n");
return -1; return -1;
} }
@ -123,17 +106,17 @@ int main (int argc, char *argv[]) {
GetFullPathName("output.bmp", MAX_PATH, fullFilename, nullptr); GetFullPathName("output.bmp", MAX_PATH, fullFilename, nullptr);
if (RegSetValueEx(hKey, "Wallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) { if (RegSetValueEx(hKey, "Wallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) {
std::cerr << "Error: Could not set registry value." << std::endl; printf("Error: Could not set registry value.\n");
return -1; return -1;
} }
if (RegSetValueEx(hKey, "OriginalWallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) { if (RegSetValueEx(hKey, "OriginalWallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) {
std::cerr << "Error: Could not set registry value." << std::endl; printf("Error: Could not set registry value.\n");
return -1; return -1;
} }
if (RegSetValueEx(hKey, "ConvertedWallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) { if (RegSetValueEx(hKey, "ConvertedWallpaper", 0, REG_SZ, (const BYTE*)fullFilename, sizeof(fullFilename)) != ERROR_SUCCESS) {
std::cerr << "Error: Could not set registry value." << std::endl; printf("Error: Could not set registry value.\n");
return -1; return -1;
} }
@ -143,7 +126,30 @@ int main (int argc, char *argv[]) {
int isWallSet = SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (void*)fullFilename, SPIF_UPDATEINIFILE); int isWallSet = SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (void*)fullFilename, SPIF_UPDATEINIFILE);
//int result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)fullFilename, SPIF_SENDCHANGE); //int result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)fullFilename, SPIF_SENDCHANGE);
printf("Result: %d", isWallSet); return 0;
}
int main (int argc, char *argv[]) {
HWND hwnd = GetConsoleWindow();
//ShowWindow(hwnd, SW_HIDE);
NOTIFYICONDATAA nid;
nid.hWnd = hwnd; // handle to the window that will display the tray icon
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.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
nid.uVersion = 0;
nid.uCallbackMessage = APPWM_ICONNOTIFY;
strcpy(nid.szTip,"Walltaker95");
//nid.szTip[]="Walltaker95";
curl = curl_easy_init(); // Initializing cURL
if(!curl) {
printf("Curl isn't working for some reason\n");
getchar();
return 0;
}
UpdateWallpaper();
if (Shell_NotifyIcon(NIM_ADD, &nid)) { if (Shell_NotifyIcon(NIM_ADD, &nid)) {
// Tray icon created successfully // Tray icon created successfully
MSG msg; MSG msg;
@ -152,11 +158,13 @@ int main (int argc, char *argv[]) {
// Handle the tray icon click here // Handle the tray icon click here
} }
} }
} else { } else {
// Error creating tray icon // Error creating tray icon
printf("The tray icon fucked up somehow, oops...\n"); printf("The tray icon fucked up somehow, oops...\n");
getchar(); getchar();
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
return 0; return 0;