[win] updatesvc: update date in registry after updating via archive

This commit is contained in:
SimplestStudio
2023-12-05 12:16:25 +02:00
parent c2f116f5c3
commit 2a80d6a965

View File

@ -173,6 +173,15 @@ auto verToAppVer(const wstring &ver)->wstring
pos = ver.find(L'.', pos + 1);
return (pos == std::wstring::npos) ? ver : ver.substr(0, pos);
}
auto getCurrentDate()->wstring
{
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
wchar_t frmDate[9] = {0};
swprintf(frmDate, _ARRAYSIZE(frmDate), L"%04d%02d%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay);
return frmDate;
}
#endif
CSvcManager::CSvcManager():
@ -564,10 +573,13 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res
app_key += (packageType == TEXT("iss")) ? L"_is1" : L"";
if (RegOpenKeyEx(hKey, app_key.c_str(), 0, KEY_ALL_ACCESS, &hAppKey) == ERROR_SUCCESS) {
wstring disp_name = app_name + L" " + verToAppVer(ver) + L" (" + currentArch().substr(1) + L")";
wstring ins_date = getCurrentDate();
if (RegSetValueEx(hAppKey, TEXT("DisplayName"), 0, REG_SZ, (const BYTE*)disp_name.c_str(), (DWORD)(disp_name.length() + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
NS_Logger::WriteLog(L"Can't update DisplayName in registry!");
if (RegSetValueEx(hAppKey, TEXT("DisplayVersion"), 0, REG_SZ, (const BYTE*)ver.c_str(), (DWORD)(ver.length() + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
NS_Logger::WriteLog(L"Can't update DisplayVersion in registry!");
if (RegSetValueEx(hAppKey, TEXT("InstallDate"), 0, REG_SZ, (const BYTE*)ins_date.c_str(), (DWORD)(ins_date.length() + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
NS_Logger::WriteLog(L"Can't update InstallDate in registry!");
RegCloseKey(hAppKey);
}
RegCloseKey(hKey);