First working prototype
Confirmed to work on Windows XP
This commit is contained in:
parent
7802b00e85
commit
cc0117c0b2
4 changed files with 9832 additions and 7 deletions
|
@ -6,5 +6,6 @@ ENABLE_LANGUAGE(RC)
|
|||
SET(CMAKE_RC_COMPILE_OBJECT
|
||||
"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
add_compile_options(-g)
|
||||
add_compile_options(-g -fpermissive)
|
||||
target_link_libraries(wt95 CURL::libcurl)
|
||||
install(FILES $<TARGET_RUNTIME_DLLS:wt95> TYPE BIN)
|
||||
|
|
124
src/main.cpp
124
src/main.cpp
|
@ -1,21 +1,60 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <conio.h>
|
||||
//#define _WIN32_WINNT 0x0500
|
||||
#include <windows.h>
|
||||
#include "../wt95.rc"
|
||||
#include <shellapi.h>
|
||||
#include <commctrl.h>
|
||||
#include <curl/curl.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
int imgconvert(std::string filepath){
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int channels;
|
||||
stbi_uc *image = stbi_load(filepath.c_str(), &width, &height, &channels, 0);
|
||||
if (image == NULL) {
|
||||
printf("Failed to load image!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bmpWidth = width;
|
||||
int bmpHeight = height;
|
||||
int bpp = 24; // 24-bit color depth
|
||||
stbi_uc *bmpImage = (stbi_uc *) malloc(bmpWidth * bmpHeight * bpp);
|
||||
|
||||
stbi_write_bmp("output.bmp", bmpWidth, bmpHeight, 3, image);
|
||||
|
||||
free(bmpImage);
|
||||
stbi_image_free(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t getAnswerFunction(void* ptr, size_t size, size_t nmemb, std::string* data) {
|
||||
data->append((char*)ptr, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
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;
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
HWND hwnd = GetConsoleWindow();
|
||||
NOTIFYICONDATAA nid;
|
||||
nid.hWnd = hwnd; // handle to the window that will display the tray icon
|
||||
|
@ -26,12 +65,85 @@ int main (int argc, char *argv[]) {
|
|||
//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;
|
||||
FILE *img;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://walltaker.joi.how/api/links/40573.json");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); // set HTTP method to GET
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/8.13.0");
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, getAnswerFunction);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
std::cout << response_string << "\n";
|
||||
std::regex rgx("\"post_url\":[\"]((?=(\\\\?))\\2.*?)[\"]");
|
||||
std::smatch match;
|
||||
std::regex_search(response_string, match, rgx);
|
||||
std::string esixurl = match[0];
|
||||
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());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
img = fopen(fname.c_str(), "wb");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, img);
|
||||
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
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;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char fullFilename[MAX_PATH];
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Close the registry key
|
||||
RegCloseKey(hKey);
|
||||
|
||||
int isWallSet = SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (void*)fullFilename, SPIF_UPDATEINIFILE);
|
||||
//int result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)fullFilename, SPIF_SENDCHANGE);
|
||||
|
||||
printf("Result: %d", isWallSet);
|
||||
if (Shell_NotifyIcon(NIM_ADD, &nid)) {
|
||||
// Tray icon created successfully
|
||||
MSG msg;
|
||||
|
@ -45,7 +157,7 @@ int main (int argc, char *argv[]) {
|
|||
printf("The tray icon fucked up somehow, oops...\n");
|
||||
getchar();
|
||||
}
|
||||
//curl_easy_cleanup(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
7988
src/stb_image.h
Normal file
7988
src/stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
1724
src/stb_image_write.h
Normal file
1724
src/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue