Finish up the bare minimum
This commit is contained in:
parent
0f64d8cdc3
commit
4a171be26c
4 changed files with 3701 additions and 21 deletions
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 <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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue