Finish up the bare minimum
This commit is contained in:
parent
0f64d8cdc3
commit
4a171be26c
4 changed files with 3701 additions and 21 deletions
|
@ -5,7 +5,7 @@ find_package( CURL REQUIRED )
|
||||||
ENABLE_LANGUAGE(RC)
|
ENABLE_LANGUAGE(RC)
|
||||||
SET(CMAKE_RC_COMPILE_OBJECT
|
SET(CMAKE_RC_COMPILE_OBJECT
|
||||||
"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <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)
|
add_compile_options(-g -fpermissive)
|
||||||
target_link_libraries(wt95 CURL::libcurl)
|
target_link_libraries(wt95 CURL::libcurl)
|
||||||
install(FILES $<TARGET_RUNTIME_DLLS:wt95> TYPE BIN)
|
install(FILES $<TARGET_RUNTIME_DLLS:wt95> TYPE BIN)
|
||||||
|
|
19
README.md
19
README.md
|
@ -10,26 +10,27 @@ $ cmake -DCMAKE_TOOLCHAIN_FILE=../TC-mingw.cmake ../
|
||||||
$ cmake --build .
|
$ 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.
|
You can grab the latest one from [curl.se](https://curl.se/windows/) which should at least work on XP.
|
||||||
|
|
||||||
Feature progress:
|
Feature progress:
|
||||||
|
|
||||||
* [ ] The bare minimum
|
* [X] The bare minimum
|
||||||
- [X] Downloads images
|
- [X] Downloads images
|
||||||
- [X] Sets the wallpaper
|
- [X] Sets the wallpaper
|
||||||
- [X] Converts images to BMP automatically
|
- [X] Converts images to BMP automatically
|
||||||
- [ ] Reads configuration from `config.ini`
|
- [X] Reads configuration from `config.ini`
|
||||||
- [X] Runs in the background
|
- [X] Runs in the background (Current method currently doesn't work in ME/98/95)
|
||||||
- [ ] Continuously and asychronously polls the Walltaker API
|
- [X] Continuously and asychronously polls the Walltaker API
|
||||||
- [ ] Makes sure it isn't grabbing the same image every time
|
- [X] Makes sure it isn't grabbing the same image every time
|
||||||
* [ ] Niceities
|
* [ ] Niceities
|
||||||
- [ ] Context menu
|
- [ ] Context menu
|
||||||
- [ ] Display who set the wallpaper
|
- [ ] Display who set the wallpaper
|
||||||
- [ ] Display the e6 post ID
|
- [ ] Display the e621 post ID
|
||||||
- [ ] Buttons for reacting to the wallpaper
|
- [ ] Buttons for reacting to the wallpaper
|
||||||
- [ ] Display e6 post ID in the tray icon's tooltip
|
- [ ] Button to open config file
|
||||||
- [ ] Allow GIF wallpapers to be set for 32-bit systems via Active Desktop
|
- [ ] 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:
|
Tested and confirmed working on:
|
||||||
|
|
||||||
|
|
3645
src/SimpleIni.h
Normal file
3645
src/SimpleIni.h
Normal file
File diff suppressed because it is too large
Load diff
56
src/main.cpp
56
src/main.cpp
|
@ -13,20 +13,23 @@
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include "SimpleIni.h"
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
|
#define IDT_TIMER1 20
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
std::string old_response = "Dummy";
|
||||||
|
std::string walltaker_id = "";
|
||||||
|
|
||||||
int imgconvert(std::string filepath){
|
int imgconvert(std::string filepath){
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int channels;
|
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) {
|
if (image == NULL) {
|
||||||
printf("Failed to load image!\n");
|
printf("Failed to load image!\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -39,6 +42,8 @@ int imgconvert(std::string filepath){
|
||||||
|
|
||||||
stbi_write_bmp("output.bmp", bmpWidth, bmpHeight, 3, image);
|
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);
|
free(bmpImage);
|
||||||
stbi_image_free(image);
|
stbi_image_free(image);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -54,12 +59,29 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream){
|
||||||
return written;
|
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(){
|
int UpdateWallpaper(){
|
||||||
|
|
||||||
std::string response_string;
|
std::string response_string;
|
||||||
FILE *img;
|
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_FOLLOWLOCATION, 1L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
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_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_WRITEFUNCTION, getAnswerFunction);
|
||||||
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?
|
// Who needs parsing when you have regex?
|
||||||
|
@ -85,12 +106,17 @@ int UpdateWallpaper(){
|
||||||
fileext.erase(0, fileext.size()-4);
|
fileext.erase(0, fileext.size()-4);
|
||||||
std::string fname = "tmp" + fileext;
|
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_URL, esixurl.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
img = fopen(fname.c_str(), "wb");
|
img = fopen(fname.c_str(), "wb");
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, img);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, img);
|
||||||
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||||
curl_easy_perform(curl);
|
curl_easy_perform(curl);
|
||||||
|
old_response = esixurl;
|
||||||
fclose(img);
|
fclose(img);
|
||||||
|
|
||||||
imgconvert(fname);
|
imgconvert(fname);
|
||||||
|
@ -129,10 +155,17 @@ int UpdateWallpaper(){
|
||||||
return 0;
|
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[]) {
|
int main (int argc, char *argv[]) {
|
||||||
|
|
||||||
HWND hwnd = GetConsoleWindow();
|
LoadConfig();
|
||||||
//ShowWindow(hwnd, SW_HIDE);
|
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;
|
NOTIFYICONDATAA nid;
|
||||||
nid.hWnd = hwnd; // handle to the window that will display the tray icon
|
nid.hWnd = hwnd; // handle to the window that will display the tray icon
|
||||||
nid.uID = 100; // unique identifier for the tray icon
|
nid.uID = 100; // unique identifier for the tray icon
|
||||||
|
@ -148,15 +181,14 @@ int main (int argc, char *argv[]) {
|
||||||
getchar();
|
getchar();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
UpdateWallpaper();
|
|
||||||
|
|
||||||
if (Shell_NotifyIcon(NIM_ADD, &nid)) {
|
if (Shell_NotifyIcon(NIM_ADD, &nid)) {
|
||||||
// Tray icon created successfully
|
// Tray icon created successfully
|
||||||
|
ShowWindow(hwnd, SW_HIDE);
|
||||||
|
SetTimer(hwnd, IDT_TIMER1, 10000, TimerProc);
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||||
if (msg.message == nid.uCallbackMessage) {
|
TranslateMessage(&msg);
|
||||||
// Handle the tray icon click here
|
DispatchMessage(&msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,6 +197,8 @@ int main (int argc, char *argv[]) {
|
||||||
getchar();
|
getchar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KillTimer(hwnd, IDT_TIMER1);
|
||||||
|
DestroyWindow(hwnd);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue