Finish up the bare minimum

This commit is contained in:
Nick Martin 2025-05-25 13:42:14 -04:00
parent 0f64d8cdc3
commit 4a171be26c
4 changed files with 3701 additions and 21 deletions

View file

@ -5,7 +5,7 @@ find_package( CURL REQUIRED )
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")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static -mwindows")
add_compile_options(-g -fpermissive)
target_link_libraries(wt95 CURL::libcurl)
install(FILES $<TARGET_RUNTIME_DLLS:wt95> TYPE BIN)

View file

@ -10,26 +10,27 @@ $ cmake -DCMAKE_TOOLCHAIN_FILE=../TC-mingw.cmake ../
$ cmake --build .
```
Note: You'll need to supply a 32-bit `libcurl-4.dll` manually as I can't figure out how to make it build on it's own
Note: You'll need to supply a 32-bit `libcurl-4.dll` manually as I can't figure out how to make it build on its own at the moment.
You can grab the latest one from [curl.se](https://curl.se/windows/) which should at least work on XP.
Feature progress:
* [ ] The bare minimum
* [X] The bare minimum
- [X] Downloads images
- [X] Sets the wallpaper
- [X] Converts images to BMP automatically
- [ ] Reads configuration from `config.ini`
- [X] Runs in the background
- [ ] Continuously and asychronously polls the Walltaker API
- [ ] Makes sure it isn't grabbing the same image every time
- [X] Reads configuration from `config.ini`
- [X] Runs in the background (Current method currently doesn't work in ME/98/95)
- [X] Continuously and asychronously polls the Walltaker API
- [X] Makes sure it isn't grabbing the same image every time
* [ ] Niceities
- [ ] Context menu
- [ ] Display who set the wallpaper
- [ ] Display the e6 post ID
- [ ] Display the e621 post ID
- [ ] Buttons for reacting to the wallpaper
- [ ] Display e6 post ID in the tray icon's tooltip
- [ ] Allow GIF wallpapers to be set for 32-bit systems via Active Desktop
- [ ] Button to open config file
- [ ] Display e621 post ID in the tray icon's tooltip
- [ ] Allow GIF wallpapers to be set for 32-bit systems via Active Desktop (<= Windows XP only)
Tested and confirmed working on:

3645
src/SimpleIni.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -13,20 +13,23 @@
#include <shellapi.h>
#include <commctrl.h>
#include <curl/curl.h>
#include "SimpleIni.h"
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image.h"
#include "stb_image_write.h"
#define IDT_TIMER1 20
CURL *curl;
CURLcode res;
std::string old_response = "Dummy";
std::string walltaker_id = "";
int imgconvert(std::string filepath){
int width;
int height;
int channels;
stbi_uc *image = stbi_load(filepath.c_str(), &width, &height, &channels, 0);
stbi_uc *image = stbi_load(filepath.c_str(), &width, &height, &channels, 3);
if (image == NULL) {
printf("Failed to load image!\n");
return 1;
@ -39,6 +42,8 @@ int imgconvert(std::string filepath){
stbi_write_bmp("output.bmp", bmpWidth, bmpHeight, 3, image);
std::remove(filepath.c_str()); // Delete original file once we're done with it to save space
free(bmpImage);
stbi_image_free(image);
return 0;
@ -54,12 +59,29 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream){
return written;
}
int LoadConfig(){
CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile("wt95.ini");
const char* pVal = ini.GetValue("Walltaker95", "LinkId", NULL);
if (pVal == NULL){
printf("Error loading config file, using default link ID\n");
walltaker_id = "40573";
} else {
walltaker_id = pVal;
}
return 0;
}
int UpdateWallpaper(){
std::string response_string;
FILE *img;
std::string myurl = "https://walltaker.joi.how/api/links/" + walltaker_id + ".json";
//std::cout << myurl;
curl_easy_setopt(curl, CURLOPT_URL, "https://walltaker.joi.how/api/links/40573.json");
curl_easy_setopt(curl, CURLOPT_URL, myurl.c_str());
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
@ -70,7 +92,6 @@ int UpdateWallpaper(){
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";
// Who needs parsing when you have regex?
@ -85,12 +106,17 @@ int UpdateWallpaper(){
fileext.erase(0, fileext.size()-4);
std::string fname = "tmp" + fileext;
if (!old_response.compare(esixurl)){
return 0; // We already got this wallpaper before, skip it.
}
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);
old_response = esixurl;
fclose(img);
imgconvert(fname);
@ -129,10 +155,17 @@ int UpdateWallpaper(){
return 0;
}
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
if (uMsg == WM_TIMER && idEvent == IDT_TIMER1) {
UpdateWallpaper();
}
}
int main (int argc, char *argv[]) {
HWND hwnd = GetConsoleWindow();
//ShowWindow(hwnd, SW_HIDE);
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;
nid.hWnd = hwnd; // handle to the window that will display the tray icon
nid.uID = 100; // unique identifier for the tray icon
@ -148,15 +181,14 @@ int main (int argc, char *argv[]) {
getchar();
return 0;
}
UpdateWallpaper();
if (Shell_NotifyIcon(NIM_ADD, &nid)) {
// Tray icon created successfully
ShowWindow(hwnd, SW_HIDE);
SetTimer(hwnd, IDT_TIMER1, 10000, TimerProc);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
if (msg.message == nid.uCallbackMessage) {
// Handle the tray icon click here
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} else {
@ -165,6 +197,8 @@ int main (int argc, char *argv[]) {
getchar();
}
KillTimer(hwnd, IDT_TIMER1);
DestroyWindow(hwnd);
curl_easy_cleanup(curl);
return 0;