[win] updatesvc: fix running process detection

This commit is contained in:
SimplestStudio
2025-09-26 16:57:51 +03:00
parent 600531f252
commit 8e86f32977
3 changed files with 24 additions and 4 deletions

View File

@ -739,8 +739,12 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res
#endif
for (int i = 0; i < sizeof(apps) / sizeof(apps[0]); i++) {
int retries = 10;
#ifdef _WIN32
tstring app = NS_File::toNativeSeparators(appPath + apps[i]);
#else
tstring app(apps[i]);
app = app.substr(1);
#endif
while (NS_File::isProcessRunning(app) && retries-- > 0)
sleep(500);
@ -912,8 +916,12 @@ void CSvcManager::startReplacingService(const bool restartAfterUpdate)
#endif
for (int i = 0; i < sizeof(apps) / sizeof(apps[0]); i++) {
int retries = 10;
#ifdef _WIN32
tstring app = NS_File::toNativeSeparators(appPath + apps[i]);
#else
tstring app(apps[i]);
app = app.substr(1);
#endif
while (NS_File::isProcessRunning(app) && retries-- > 0)
sleep(500);

View File

@ -428,8 +428,9 @@ namespace NS_File
return false;
}
bool isProcessRunning(const wstring &fileName)
bool isProcessRunning(const wstring &filePath)
{
wstring fileName = filePath.substr(filePath.find_last_of(L"\\/") + 1);
HANDLE snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapShot == INVALID_HANDLE_VALUE)
return false;
@ -443,8 +444,19 @@ namespace NS_File
do {
if (lstrcmpi(entry.szExeFile, fileName.c_str()) == 0) {
CloseHandle(snapShot);
return true;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, entry.th32ProcessID);
if (hProcess) {
WCHAR processPath[MAX_PATH];
DWORD pathSize = MAX_PATH;
if (QueryFullProcessImageNameW(hProcess, 0, processPath, &pathSize)) {
if (lstrcmpi(processPath, filePath.c_str()) == 0) {
CloseHandle(hProcess);
CloseHandle(snapShot);
return true;
}
}
CloseHandle(hProcess);
}
}
} while (Process32Next(snapShot, &entry));

View File

@ -69,7 +69,7 @@ bool readBinFile(const wstring &filePath, list<wstring> &linesList);
bool writeToFile(const wstring &filePath, list<wstring> &linesList);
bool writeToBinFile(const wstring &filePath, list<wstring> &linesList);
bool runProcess(const wstring &fileName, const wstring &args);
bool isProcessRunning(const wstring &fileName);
bool isProcessRunning(const wstring &filePath);
bool fileExists(const wstring &filePath);
bool dirExists(const wstring &dirName);
bool dirIsEmpty(const wstring &dirName);