mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added tray notification for new version
This commit is contained in:
parent
c6f7116031
commit
c8e930e10d
@ -19,6 +19,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "Litestep.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "TrayWindow.h"
|
||||
#include "../Version.h"
|
||||
|
||||
extern CRainmeter* Rainmeter;
|
||||
@ -41,27 +42,47 @@ void CheckVersion(void* dummy)
|
||||
if (hUrlDump)
|
||||
{
|
||||
DWORD dwSize;
|
||||
char buffer[16] = {0}; // 16 should be enough for the version number
|
||||
if (InternetReadFile(hUrlDump, (LPVOID)buffer, 15, &dwSize))
|
||||
char urlData[16] = {0};
|
||||
if (InternetReadFile(hUrlDump, (LPVOID)urlData, sizeof(urlData) - 1, &dwSize))
|
||||
{
|
||||
int version = atoi(buffer) * 1000000;
|
||||
char* pos = strchr(buffer, '.');
|
||||
auto parseVersion = [](const WCHAR* str)->int
|
||||
{
|
||||
int version = _wtoi(str) * 1000000;
|
||||
const WCHAR* pos = wcschr(str, L'.');
|
||||
if (pos)
|
||||
{
|
||||
++pos; // Skip .
|
||||
version += atoi(pos) * 1000;
|
||||
version += _wtoi(pos) * 1000;
|
||||
|
||||
pos = strchr(pos, '.');
|
||||
pos = wcschr(pos, '.');
|
||||
if (pos)
|
||||
{
|
||||
++pos; // Skip .
|
||||
version += atoi(pos);
|
||||
version += _wtoi(pos);
|
||||
}
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
if (version > RAINMETER_VERSION)
|
||||
std::wstring tmpSz = ConvertToWide(urlData);
|
||||
const WCHAR* version = tmpSz.c_str();
|
||||
|
||||
int availableVersion = parseVersion(version);
|
||||
if (availableVersion > RAINMETER_VERSION)
|
||||
{
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user