2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 Kimmo Pekkola
|
|
|
|
|
|
|
|
This program 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 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "Litestep.h"
|
|
|
|
#include "Rainmeter.h"
|
2012-05-05 12:42:16 +00:00
|
|
|
#include "TrayWindow.h"
|
2011-02-07 08:02:12 +00:00
|
|
|
#include "../Version.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
void CheckVersion(void* dummy)
|
|
|
|
{
|
2012-04-05 10:27:34 +00:00
|
|
|
HINTERNET hRootHandle = InternetOpen(
|
|
|
|
L"Rainmeter",
|
|
|
|
INTERNET_OPEN_TYPE_PRECONFIG,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2012-04-05 10:27:34 +00:00
|
|
|
0);
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
if (hRootHandle == nullptr)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
HINTERNET hUrlDump = InternetOpenUrl(
|
|
|
|
hRootHandle, L"http://rainmeter.github.io/rainmeter/release", nullptr, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
|
2009-02-10 18:37:48 +00:00
|
|
|
if (hUrlDump)
|
|
|
|
{
|
|
|
|
DWORD dwSize;
|
2012-05-05 12:42:16 +00:00
|
|
|
char urlData[16] = {0};
|
|
|
|
if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-05 12:42:16 +00:00
|
|
|
auto parseVersion = [](const WCHAR* str)->int
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-05 12:42:16 +00:00
|
|
|
int version = _wtoi(str) * 1000000;
|
|
|
|
const WCHAR* pos = wcschr(str, L'.');
|
2012-04-06 17:54:45 +00:00
|
|
|
if (pos)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-04-06 17:54:45 +00:00
|
|
|
++pos; // Skip .
|
2012-05-05 12:42:16 +00:00
|
|
|
version += _wtoi(pos) * 1000;
|
|
|
|
|
|
|
|
pos = wcschr(pos, '.');
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
++pos; // Skip .
|
|
|
|
version += _wtoi(pos);
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-05-05 12:42:16 +00:00
|
|
|
return version;
|
|
|
|
};
|
|
|
|
|
2013-01-27 10:14:37 +00:00
|
|
|
std::wstring tmpSz = StringUtil::Widen(urlData);
|
2012-05-05 12:42:16 +00:00
|
|
|
const WCHAR* version = tmpSz.c_str();
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-05-05 12:42:16 +00:00
|
|
|
int availableVersion = parseVersion(version);
|
2012-06-26 12:45:05 +00:00
|
|
|
if (availableVersion > RAINMETER_VERSION ||
|
|
|
|
(revision_beta && availableVersion == RAINMETER_VERSION))
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().SetNewVersion();
|
2012-05-05 12:42:16 +00:00
|
|
|
|
|
|
|
WCHAR buffer[32];
|
2013-06-13 14:20:27 +00:00
|
|
|
const WCHAR* dataFile = GetRainmeter().GetDataFile().c_str();
|
2012-05-05 12:42:16 +00:00
|
|
|
GetPrivateProfileString(L"Rainmeter", L"LastCheck", L"0", buffer, _countof(buffer), dataFile);
|
|
|
|
|
|
|
|
// Show tray notification only once per new version
|
|
|
|
int lastVersion = parseVersion(buffer);
|
|
|
|
if (availableVersion > lastVersion)
|
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
GetRainmeter().GetTrayWindow()->ShowUpdateNotification(version);
|
2012-05-05 12:42:16 +00:00
|
|
|
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
InternetCloseHandle(hUrlDump);
|
|
|
|
}
|
|
|
|
|
|
|
|
InternetCloseHandle(hRootHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckUpdate()
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
_beginthread(CheckVersion, 0, nullptr);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|