Skip to content

Commit 9edf496

Browse files
committed
Fix setup error checking
1 parent 054af2f commit 9edf496

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

tools/CustomSetupTool/CustomSetupTool/appsup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ static BOOLEAN NTAPI PhpPreviousInstancesCallback(
505505
BOOLEAN ShutdownProcessHacker(VOID)
506506
{
507507
PhEnumDirectoryObjects(PhGetNamespaceHandle(), PhpPreviousInstancesCallback, NULL);
508-
509508
return TRUE;
510509
}
511510

tools/CustomSetupTool/CustomSetupTool/setup.c

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -178,41 +178,51 @@ BOOLEAN SetupCreateUninstallFile(
178178

179179
// Check if the user has started the setup from the installation folder.
180180
if (PhStartsWithStringRef2(&currentFilePath, PhGetString(Context->SetupInstallPath), TRUE))
181-
{
182-
// Do nothing, latest version already in the installation folder.
183181
return TRUE;
184-
}
185182

186183
backupFilePath = PhConcatStrings2(PhGetString(Context->SetupInstallPath), L"\\processhacker-setup.bak");
187184
uninstallFilePath = PhConcatStrings2(PhGetString(Context->SetupInstallPath), L"\\processhacker-setup.exe");
188185

189186
if (RtlDoesFileExists_U(backupFilePath->Buffer))
190187
{
191-
// TODO: Move to temp directory
192-
}
188+
GUID randomGuid;
189+
PPH_STRING tempPath = NULL;
190+
PPH_STRING guidString = NULL;
193191

194-
if (RtlDoesFileExists_U(uninstallFilePath->Buffer))
195-
{
196-
if (!DeleteFile(backupFilePath->Buffer))
192+
tempPath = PhCreateStringEx(NULL, GetTempPath(0, NULL) * sizeof(WCHAR));
193+
GetTempPath((ULONG)tempPath->Length / sizeof(WCHAR), tempPath->Buffer);
194+
195+
PhGenerateGuid(&randomGuid);
196+
197+
if (guidString = PhFormatGuid(&randomGuid))
198+
{
199+
PhMoveReference(&guidString, PhSubstring(guidString, 1, guidString->Length / sizeof(WCHAR) - 2));
200+
}
201+
202+
PhMoveReference(&guidString, PhConcatStrings(
203+
3,
204+
PhGetString(tempPath),
205+
L"\\",
206+
PhGetString(guidString)
207+
));
208+
209+
if (!MoveFile(backupFilePath->Buffer, guidString->Buffer))
197210
{
198211
Context->ErrorCode = GetLastError();
199-
PhDereferenceObject(uninstallFilePath);
200-
return FALSE;
201212
}
213+
}
202214

215+
if (RtlDoesFileExists_U(uninstallFilePath->Buffer))
216+
{
203217
if (!MoveFile(uninstallFilePath->Buffer, backupFilePath->Buffer))
204218
{
205219
Context->ErrorCode = GetLastError();
206-
PhDereferenceObject(uninstallFilePath);
207-
return FALSE;
208220
}
209221
}
210222

211-
if (!CopyFile(currentFilePath.Buffer, uninstallFilePath->Buffer, FALSE))
223+
if (!CopyFile(currentFilePath.Buffer, uninstallFilePath->Buffer, TRUE))
212224
{
213225
Context->ErrorCode = GetLastError();
214-
PhDereferenceObject(uninstallFilePath);
215-
return FALSE;
216226
}
217227

218228
PhDereferenceObject(uninstallFilePath);
@@ -336,27 +346,24 @@ BOOLEAN SetupUninstallKph(
336346
_In_ PPH_SETUP_CONTEXT Context
337347
)
338348
{
339-
BOOLEAN deleted = FALSE;
340-
SC_HANDLE serviceHandle;
341-
SERVICE_STATUS serviceStatus;
342-
343-
if (serviceHandle = PhOpenService(
344-
L"KProcessHacker3",
345-
SERVICE_STOP | DELETE
346-
))
349+
while (TRUE)
347350
{
348-
ControlService(serviceHandle, SERVICE_CONTROL_STOP, &serviceStatus);
351+
SC_HANDLE serviceHandle;
352+
SERVICE_STATUS serviceStatus;
349353

350-
deleted = DeleteService(serviceHandle);
354+
if (!(serviceHandle = PhOpenService(
355+
L"KProcessHacker3",
356+
SERVICE_STOP | DELETE
357+
)))
358+
break;
359+
360+
ControlService(serviceHandle, SERVICE_CONTROL_STOP, &serviceStatus);
361+
DeleteService(serviceHandle);
351362

352363
CloseServiceHandle(serviceHandle);
353364
}
354-
else
355-
{
356-
deleted = TRUE;
357-
}
358365

359-
return deleted;
366+
return TRUE;
360367
}
361368

362369
VOID SetupSetWindowsOptions(

tools/CustomSetupTool/CustomSetupTool/update.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,7 @@ VOID SetupShowUpdatingErrorDialog(
141141
config.pfCallback = SetupErrorTaskDialogCallbackProc;
142142
config.lpCallbackData = (LONG_PTR)Context;
143143
config.pszWindowTitle = PhApplicationName;
144-
config.pszMainInstruction = PhaFormatString(
145-
L"Error updating to the latest version...",
146-
PHAPP_VERSION_MAJOR,
147-
PHAPP_VERSION_MINOR,
148-
PHAPP_VERSION_REVISION
149-
)->Buffer;
144+
config.pszMainInstruction = L"Error updating to the latest version.";
150145

151146
if (Context->ErrorCode)
152147
{

0 commit comments

Comments
 (0)