Cleaned up code a bit
This commit is contained in:
parent
299a137580
commit
16392d1c0d
1 changed files with 43 additions and 35 deletions
74
src/main.cpp
74
src/main.cpp
|
@ -4,9 +4,11 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <conio.h>
|
||||
#include <future>
|
||||
//#define _WIN32_WINNT 0x0500
|
||||
#include <windows.h>
|
||||
#define APPWM_ICONNOTIFY (WM_APP + 1)
|
||||
#include <conio.h>
|
||||
#include "../wt95.rc"
|
||||
#include <shellapi.h>
|
||||
#include <commctrl.h>
|
||||
|
@ -16,6 +18,9 @@
|
|||
#include "stb_image.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
int imgconvert(std::string filepath){
|
||||
|
||||
int width;
|
||||
|
@ -44,33 +49,12 @@ size_t getAnswerFunction(void* ptr, size_t size, size_t nmemb, std::string* data
|
|||
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);
|
||||
return written;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
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;
|
||||
}
|
||||
int UpdateWallpaper(){
|
||||
|
||||
std::string response_string;
|
||||
FILE *img;
|
||||
|
@ -87,7 +71,9 @@ int main (int argc, char *argv[]) {
|
|||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
|
||||
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::smatch match;
|
||||
std::regex_search(response_string, match, rgx);
|
||||
|
@ -95,10 +81,8 @@ int main (int argc, char *argv[]) {
|
|||
esixurl.erase(0, 12);
|
||||
esixurl.erase(esixurl.size()-1);
|
||||
|
||||
std::cout << esixurl << '\n';
|
||||
std::string fileext = esixurl;
|
||||
fileext.erase(0, fileext.size()-4);
|
||||
std::cout << fileext << '\n';
|
||||
std::string fname = "tmp" + fileext;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, esixurl.c_str());
|
||||
|
@ -109,13 +93,12 @@ int main (int argc, char *argv[]) {
|
|||
curl_easy_perform(curl);
|
||||
fclose(img);
|
||||
|
||||
|
||||
imgconvert(fname);
|
||||
|
||||
// Open the registry key for writing
|
||||
HKEY hKey = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -123,17 +106,17 @@ int main (int argc, char *argv[]) {
|
|||
GetFullPathName("output.bmp", MAX_PATH, fullFilename, nullptr);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -143,7 +126,30 @@ int main (int argc, char *argv[]) {
|
|||
int isWallSet = SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (void*)fullFilename, SPIF_UPDATEINIFILE);
|
||||
//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)) {
|
||||
// Tray icon created successfully
|
||||
MSG msg;
|
||||
|
@ -152,11 +158,13 @@ int main (int argc, char *argv[]) {
|
|||
// Handle the tray icon click here
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Error creating tray icon
|
||||
printf("The tray icon fucked up somehow, oops...\n");
|
||||
getchar();
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
return 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue