Added tray notification for new version

This commit is contained in:
Birunthan Mohanathas 2012-05-05 15:42:16 +03:00
parent c6f7116031
commit c8e930e10d

View File

@ -19,6 +19,7 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "Litestep.h" #include "Litestep.h"
#include "Rainmeter.h" #include "Rainmeter.h"
#include "TrayWindow.h"
#include "../Version.h" #include "../Version.h"
extern CRainmeter* Rainmeter; extern CRainmeter* Rainmeter;
@ -41,27 +42,47 @@ void CheckVersion(void* dummy)
if (hUrlDump) if (hUrlDump)
{ {
DWORD dwSize; DWORD dwSize;
char buffer[16] = {0}; // 16 should be enough for the version number char urlData[16] = {0};
if (InternetReadFile(hUrlDump, (LPVOID)buffer, 15, &dwSize)) if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
{ {
int version = atoi(buffer) * 1000000; auto parseVersion = [](const WCHAR* str)->int
char* pos = strchr(buffer, '.');
if (pos)
{ {
++pos; // Skip . int version = _wtoi(str) * 1000000;
version += atoi(pos) * 1000; const WCHAR* pos = wcschr(str, L'.');
pos = strchr(pos, '.');
if (pos) if (pos)
{ {
++pos; // Skip . ++pos; // Skip .
version += atoi(pos); version += _wtoi(pos) * 1000;
}
}
if (version > RAINMETER_VERSION) pos = wcschr(pos, '.');
if (pos)
{
++pos; // Skip .
version += _wtoi(pos);
}
}
return version;
};
std::wstring tmpSz = ConvertToWide(urlData);
const WCHAR* version = tmpSz.c_str();
int availableVersion = parseVersion(version);
if (availableVersion > RAINMETER_VERSION)
{ {
Rainmeter->SetNewVersion(); Rainmeter->SetNewVersion();
WCHAR buffer[32];
const WCHAR* dataFile = Rainmeter->GetDataFile().c_str();
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)
{
Rainmeter->GetTrayWindow()->ShowUpdateNotification(version);
WritePrivateProfileString(L"Rainmeter", L"LastCheck", version, dataFile);
}
} }
} }
InternetCloseHandle(hUrlDump); InternetCloseHandle(hUrlDump);