[win] updatesvc: keep license when updating via archive

This commit is contained in:
SimplestStudio
2025-08-20 10:44:01 +03:00
parent 4cefc96e1b
commit e2fc7e5e8d
3 changed files with 34 additions and 0 deletions

View File

@ -760,6 +760,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

View File

@ -254,6 +254,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;
@ -61,6 +62,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);