-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWicketWallpaperDaemon.cpp
101 lines (96 loc) · 2.81 KB
/
WicketWallpaperDaemon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <thread>
#include <string>
#include <iostream>
#include <fstream>
#include "boost/asio/ip/tcp.hpp"
#include <windows.h>
#include <chrono>
using namespace std;
using boost::asio::ip::tcp;
int main(int argc, char* argv[])
{
if (argc != 4)
{
std::cerr << "Usage: Wallpaper <host> <hostfilelocation> <clientfilelocation>" << std::endl;
return 1;
}
ofstream wallpaper;
string header;
string methode = "HEAD";
string lastetag = "";
//string regkey = "L\"";
//regkey.insert(3,1,argv[3])
while (1)
{
bool breakagain = false;
//cout << methode;
tcp::iostream stream;
stream.expires_from_now(chrono::seconds(60));
stream.connect(argv[1], "http");
stream << methode << " " << argv[2] << " HTTP/1.1\r\n";
stream << "Host: " << argv[1] << "\r\n";
stream << "Accept: */*\r\n";
stream << "Connection: close\r\n\r\n";
if (!stream)
{
cerr << "TCP Error" << endl;
this_thread::sleep_for(chrono::seconds(1));
continue;
}
stream.flush();
int i = 1;
while (std::getline(stream, header) && header != "\r")
{
if (header.find("200 OK") == string::npos && i == 1)
{
i = 0;
break;
}
if (methode == "HEAD")
{
if (header.find("ETag") != string::npos)
{
if (header != lastetag)
{
lastetag = header;
methode = "GET";
//cout << "Another ETAg";
}
else {
cerr << "Same ETag" << endl;
this_thread::sleep_for(chrono::seconds(10));
}
breakagain = true;
break;
}
}
i ++;
}
if (i == 0)
{
cerr << "HTTP Error" << endl;
this_thread::sleep_for(chrono::seconds(1));
continue;
}
if (breakagain == true)
{
continue;
}
//cout << "HI";
wallpaper.open(argv[3], ios::trunc | ios::binary);
wallpaper << stream.rdbuf();
wallpaper.close();
if(SystemParametersInfoA(SPI_SETDESKWALLPAPER, NULL, argv[3], SPIF_SENDCHANGE) != true)
{
cerr << "Registry Error" << endl;
this_thread::sleep_for(chrono::seconds(1));
continue;
}
cerr << "Success" << endl;
if (methode == "GET")
{
methode = "HEAD";
}
this_thread::sleep_for(chrono::seconds(10));
}
}