Skip to content

Commit 541b2bb

Browse files
committed
Improve prompt for locked files during update
1 parent 14ad62c commit 541b2bb

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

Client/loader/Install.cpp

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -239,42 +239,50 @@ static bool TerminateFileLockingProcesses(const SString& absolutePath, const SSt
239239
WString filePath(absolutePath);
240240
std::vector<DWORD> processIds = GetProcessListUsingFile(filePath);
241241

242-
if (processIds.empty())
243-
return true;
242+
while (true)
243+
{
244+
if (processIds.empty())
245+
return true;
244246

245-
SString nameList;
247+
SString nameList;
246248

247-
for (DWORD processId : processIds)
248-
{
249-
if (!nameList.empty())
250-
nameList += '\n';
249+
for (DWORD processId : processIds)
250+
{
251+
if (!nameList.empty())
252+
nameList += '\n';
251253

252-
SString processName = GetProcessFilename(processId);
254+
SString processName = GetProcessFilename(processId);
253255

254-
if (processName.empty())
255-
processName = _("Unknown");
256+
if (processName.empty())
257+
processName = _("Unknown");
256258

257-
nameList += SString(" %s [%lu]", processName.c_str(), processId);
258-
}
259+
nameList += SString(" %s [%lu]", processName.c_str(), processId);
260+
}
259261

260-
int decision = MessageBoxUTF8(
261-
nullptr,
262-
SString(_("The file '%s' is currently locked by %zu processes.\n\nDo you want to terminate the following processes and continue updating?\n\n%s"),
263-
displayName.c_str(), processIds.size(), nameList.c_str()),
264-
"MTA: San Andreas", MB_YESNO | MB_ICONQUESTION | MB_TOPMOST);
262+
int decision = MessageBoxUTF8(
263+
nullptr,
264+
SString(_("The file '%s' is currently locked by %zu processes.\n\nDo you want to terminate the following processes and continue updating?\n\n%s"),
265+
displayName.c_str(), processIds.size(), nameList.c_str()),
266+
"MTA: San Andreas", MB_CANCELTRYCONTINUE | MB_ICONQUESTION | MB_TOPMOST);
265267

266-
if (decision != IDYES)
267-
return false;
268+
processIds = GetProcessListUsingFile(filePath);
268269

269-
for (DWORD processId : processIds)
270-
{
271-
if (!TerminateProcess(processId, 0))
270+
if (processIds.empty())
271+
return true;
272+
273+
if (decision == IDTRYAGAIN)
274+
continue;
275+
276+
if (decision != IDCONTINUE)
277+
return false;
278+
279+
for (DWORD processId : processIds)
272280
{
273-
AddReportLog(5055, SString("TerminateFileLockingProcesses: Failed to terminate process '%s' (%lu)", GetProcessPathFilename(processId), processId));
281+
TerminateProcess(processId, 0);
274282
}
275-
}
276283

277-
return GetProcessListUsingFile(filePath).empty();
284+
processIds = GetProcessListUsingFile(filePath);
285+
}
278286
}
279287

280288
/**

0 commit comments

Comments
 (0)