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:
		| @@ -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, '.'); | 			{ | ||||||
|  | 				int version = _wtoi(str) * 1000000; | ||||||
|  | 				const WCHAR* pos = wcschr(str, L'.'); | ||||||
| 				if (pos) | 				if (pos) | ||||||
| 				{ | 				{ | ||||||
| 					++pos;	// Skip . | 					++pos;	// Skip . | ||||||
| 				version += atoi(pos) * 1000; | 					version += _wtoi(pos) * 1000; | ||||||
|  |  | ||||||
| 				pos = strchr(pos, '.'); | 					pos = wcschr(pos, '.'); | ||||||
| 					if (pos) | 					if (pos) | ||||||
| 					{ | 					{ | ||||||
| 						++pos;	// Skip . | 						++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(); | 				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); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Birunthan Mohanathas
					Birunthan Mohanathas