Merge pull request 'Merge branch hotfix/v9.0.4 into release/v9.1.0' (#426) from hotfix/v9.0.4 into release/v9.1.0

This commit is contained in:
Maxim Kadushkin
2025-08-27 16:50:01 +00:00
130 changed files with 687 additions and 73941 deletions

View File

@ -213,10 +213,36 @@ auto verToAppVer(const wstring &ver)->wstring
size_t pos = ver.find(L'.');
if (pos == std::wstring::npos)
return ver;
pos = ver.find(L'.', pos + 1);
if (pos == std::wstring::npos)
return ver;
pos = ver.find(L'.', pos + 1);
return (pos == std::wstring::npos) ? ver : ver.substr(0, pos);
}
auto displayNameReplaceVersion(const wstring &disp_name, const wstring &newVersion)->wstring
{
for (size_t i = disp_name.size(); i-- > 0;) {
if (iswdigit(disp_name[i])) {
size_t j = i;
bool hasDot = false;
while (j > 0 && (iswdigit(disp_name[j - 1]) || disp_name[j - 1] == L'.')) {
if (disp_name[j - 1] == L'.')
hasDot = true;
--j;
}
if (hasDot) {
return disp_name.substr(0, j) + newVersion + disp_name.substr(i + 1);
} else {
i = j;
}
}
}
return disp_name;
}
auto getCurrentDate()->wstring
{
SYSTEMTIME sysTime;
@ -764,6 +790,14 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res
if (NS_File::fileExists(tmpPath + files[i]))
NS_File::replaceFile(tmpPath + files[i], appPath + files[i]);
}
auto licenseFiles = NS_File::findFilesByPattern(tmpPath, L"LICENSE.*");
auto eulaFiles = NS_File::findFilesByPattern(tmpPath, L"EULA.*");
licenseFiles.insert(licenseFiles.end(), eulaFiles.begin(), eulaFiles.end());
for (const auto &file : licenseFiles) {
if (!NS_File::fileExists(appPath + file) && NS_File::fileExists(tmpPath + file))
NS_File::replaceFile(tmpPath + file, appPath + file);
}
}
// To support a version without updatesvc.exe inside the working folder
@ -788,8 +822,19 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res
wstring app_key(TEXT(REG_UNINST_KEY));
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 disp_name;
wstring ins_date = getCurrentDate();
{
WCHAR pData[MAX_PATH] = {};
DWORD cbData = sizeof(pData);
DWORD dwType = REG_SZ;
if (RegQueryValueEx(hAppKey, TEXT("DisplayName"), nullptr, &dwType, (LPBYTE)pData, &cbData) == ERROR_SUCCESS && pData[0] != L'\0') {
disp_name = displayNameReplaceVersion(pData, verToAppVer(ver));
} else {
NS_Logger::WriteLog(L"Unable to get DisplayName from registry!");
disp_name = app_name + L" " + verToAppVer(ver) + L" (" + currentArch().substr(1) + L")";
}
}
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)

View File

@ -265,6 +265,30 @@ namespace NS_File
return true;
}
std::vector<wstring> findFilesByPattern(const wstring &path, const wstring &pattern)
{
std::vector<wstring> result;
wstring searchPath = toNativeSeparators(path) + L"\\" + pattern;
if (searchPath.size() > MAX_PATH - 1) {
return result;
}
WIN32_FIND_DATAW ffd;
HANDLE hFind = FindFirstFile(searchPath.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
return result;
do {
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
result.push_back(L"/" + wstring(ffd.cFileName));
}
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
return result;
}
bool readFile(const wstring &filePath, list<wstring> &linesList)
{
std::wifstream file(filePath.c_str(), std::ios_base::in);

View File

@ -35,6 +35,7 @@
#include <string>
#include <list>
#include <vector>
using std::string;
using std::wstring;
@ -62,6 +63,7 @@ wstring GetAppLanguage();
namespace NS_File
{
bool GetFilesList(const wstring &path, list<wstring> *lst, wstring &error, bool ignore_locked = false, bool folders_only = false);
std::vector<wstring> findFilesByPattern(const wstring &path, const wstring &pattern);
bool readFile(const wstring &filePath, list<wstring> &linesList);
bool readBinFile(const wstring &filePath, list<wstring> &linesList);
bool writeToFile(const wstring &filePath, list<wstring> &linesList);