-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathversionupdate.cpp
67 lines (57 loc) · 2.2 KB
/
versionupdate.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
// Copyright © 2010 Martin Stone.
//
// This file is part of TouchCursor.
//
// TouchCursor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TouchCursor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TouchCursor. If not, see <http://www.gnu.org/licenses/>.
#include "versionupdate.h"
#include "options.h"
#include "launch.h"
#include <windows.h>
#include <wininet.h>
#include <string>
#include <sstream>
namespace {
const int buildNum = 10;
std::wstring versionCheckUrl() {
std::wostringstream url;
url << L"http://touchcursor.sourceforge.net/version/o/" << buildNum;
return url.str();
}
}
namespace tclib {
VersionStatus GetVersionStatus() {
VersionStatus status = dontKnow;
HINTERNET hi = InternetOpen(L"touchcursor version check", INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, 0, 0, 0);
if (hi) {
std::wstring url = versionCheckUrl();
//const wchar_t* url = L"http://asdfadflkjdfa/";
HINTERNET hu = InternetOpenUrl(hi, url.c_str(), 0, 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
if (hu) {
const size_t buffSize = 100;
char buffer[buffSize];
DWORD numRead = 0;
if (InternetReadFile(hu, buffer, buffSize-1, &numRead)) {
// if there's no empty file matching at this url (& got a 404), then there's a new version out
status = (numRead != 0) ? outOfDate : upToDate;
}
InternetCloseHandle(hu);
}
InternetCloseHandle(hi);
}
return status;
}
void BrowseToDownload() {
LaunchUrl(L"http://touchcursor.sourceforge.net/update.html");
}
} // namespace tclib