e49543f3b3
Reworks CustomSetupTool updates to extract into a staging directory, commit files with deferred finalization, and recover interrupted updates via an on-disk lock and rollback of .new/.bak files. It also replaces direct ZIP handling with the shared 7-Zip wrapper and improves file comparison for ksi.dll. The installer and uninstaller now handle symlinks/junctions, safer directory cleanup, protected install path validation, and better preservation of Windows integration state, including LaunchTM IFEO handling. The wizard/UI code was tightened up as well with safer allocations, dark-mode progress rendering, and improved update completion/error behavior.
248 lines
6.5 KiB
C
248 lines
6.5 KiB
C
/*
|
|
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
|
|
*
|
|
* This file is part of System Informer.
|
|
*
|
|
* Authors:
|
|
*
|
|
* dmex
|
|
*
|
|
*/
|
|
|
|
#include "setup.h"
|
|
|
|
/**
|
|
* Installs System Informer.
|
|
*
|
|
* \param Context The setup context.
|
|
* \return Successful or errant status.
|
|
*/
|
|
_Function_class_(USER_THREAD_START_ROUTINE)
|
|
NTSTATUS CALLBACK SetupProgressThread(
|
|
_In_ PVOID Context
|
|
)
|
|
{
|
|
PPH_SETUP_CONTEXT context = (PPH_SETUP_CONTEXT)Context;
|
|
NTSTATUS status;
|
|
BOOLEAN updateDesktopShortcut = TRUE;
|
|
BOOLEAN desktopShortcutExists = FALSE;
|
|
BOOLEAN removeStartMenuFolder = FALSE;
|
|
#ifndef FORCE_TEST_UPDATE_LOCAL_INSTALL
|
|
BOOLEAN autoRunEntry;
|
|
BOOLEAN autoRunHidden;
|
|
BOOLEAN taskMgrDebugger;
|
|
BOOLEAN launchTMDebugger;
|
|
#endif
|
|
PPH_STRING previousInstallPath;
|
|
PPH_STRING currentInstallPath;
|
|
PPH_STRING desktopShortcutPath;
|
|
|
|
context->SetupProgressActive = TRUE;
|
|
|
|
//
|
|
// Roll back an interrupted update before touching the install directory.
|
|
//
|
|
|
|
SetupRecoverIncompleteUpdate(context);
|
|
|
|
//
|
|
// Determine the install location and filenames for shortcuts.
|
|
//
|
|
|
|
previousInstallPath = GetApplicationInstallPath();
|
|
currentInstallPath = SetupCreateFullPath(context->SetupInstallPath, L"");
|
|
|
|
if (!PhIsNullOrEmptyString(previousInstallPath) &&
|
|
!PhIsNullOrEmptyString(currentInstallPath) &&
|
|
PhEqualStringRef(&previousInstallPath->sr, ¤tInstallPath->sr, TRUE))
|
|
{
|
|
if (desktopShortcutPath = PhGetKnownFolderPathZ(&FOLDERID_PublicDesktop, L"\\System Informer.lnk"))
|
|
{
|
|
desktopShortcutExists = PhDoesFileExistWin32(PhGetString(desktopShortcutPath));
|
|
PhDereferenceObject(desktopShortcutPath);
|
|
}
|
|
|
|
updateDesktopShortcut = context->SetupCreateDesktopShortcut != desktopShortcutExists;
|
|
}
|
|
|
|
PhClearReference(&previousInstallPath);
|
|
PhClearReference(¤tInstallPath);
|
|
|
|
if (!PhIsNullOrEmptyString(context->SetupPreviousStartMenuFolderName) && (!context->SetupCreateStartMenuShortcuts ||
|
|
!PhEqualStringRef(&context->SetupPreviousStartMenuFolderName->sr, &context->SetupStartMenuFolderName->sr, TRUE)))
|
|
{
|
|
removeStartMenuFolder = TRUE;
|
|
}
|
|
|
|
//
|
|
// Create the folder.
|
|
//
|
|
|
|
SetupSetProgressMarquee(context, TRUE);
|
|
SetupSetProgressText(context, L"Creating the installation directory...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = PhCreateDirectoryWin32(&context->SetupInstallPath->sr)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
#ifndef FORCE_TEST_UPDATE_LOCAL_INSTALL
|
|
|
|
//
|
|
// Stop the application.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Stopping System Informer...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = SetupShutdownApplication(context)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Stop the kernel driver.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Stopping the kernel driver...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = SetupUninstallDriver(context)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Upgrade the settings file.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Updating settings...", NULL);
|
|
SetupUpgradeSettingsFile();
|
|
|
|
//
|
|
// Convert the settings file.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Converting settings...", NULL);
|
|
SetupConvertSettingsFile();
|
|
|
|
// Remove the previous installation.
|
|
//if (Context->SetupResetSettings)
|
|
// PhDeleteDirectory(Context->SetupInstallPath);
|
|
|
|
// Perform Windows Options cleanup (registry)
|
|
//
|
|
// The cleanup removes the startup entry and the Task Manager replacement, capture them
|
|
// first and restore them below or the installation silently turns both off.
|
|
|
|
autoRunEntry = SetupHasAutoRunEntry(&autoRunHidden);
|
|
taskMgrDebugger = SetupHasTaskMgrDebuggerIfeo();
|
|
launchTMDebugger = SetupHasLaunchTMDebuggerIfeo();
|
|
|
|
SetupSetProgressText(context, L"Removing previous Windows integration...", NULL);
|
|
SetupDeleteWindowsOptions(Context);
|
|
SetupDeleteAppCompatFlagsLayersEntry();
|
|
|
|
//
|
|
// Delete all shortcuts for cleanup
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Removing previous shortcuts...", NULL);
|
|
SetupDeleteShortcuts(Context, updateDesktopShortcut, removeStartMenuFolder);
|
|
|
|
//
|
|
// Create the uninstaller.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Creating uninstall files...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = SetupCreateUninstallFile(context)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Create the ARP uninstall entries.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Creating uninstall registration...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = SetupCreateUninstallKey(Context)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
//
|
|
// Create Windows Error Reporting LocalDumps key.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Creating LocalDumps configuration...", NULL);
|
|
SetupCreateLocalDumpsKey();
|
|
|
|
//
|
|
// Create autorun configuration.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Creating Windows integration...", NULL);
|
|
SetupCreateWindowsOptions(Context);
|
|
|
|
//
|
|
// Create the autorun and default task manager configuration.
|
|
//
|
|
|
|
if (autoRunEntry)
|
|
{
|
|
SetupCreateAutoRunEntry(Context, autoRunHidden);
|
|
}
|
|
|
|
if (taskMgrDebugger)
|
|
{
|
|
SetupCreateTaskMgrDebuggerIfeo(Context);
|
|
}
|
|
|
|
if (launchTMDebugger)
|
|
{
|
|
SetupCreateLaunchTMDebuggerIfeo(Context);
|
|
}
|
|
|
|
//
|
|
// Create shortcuts.
|
|
//
|
|
|
|
SetupSetProgressText(context, L"Creating shortcuts...", NULL);
|
|
SetupCreateShortcuts(Context, updateDesktopShortcut);
|
|
|
|
// Set the default image execution options.
|
|
//
|
|
//SetupCreateImageFileExecutionOptions();
|
|
|
|
#endif
|
|
|
|
//
|
|
// Extract the updated files.
|
|
//
|
|
SetupSetProgressText(context, L"Extracting files...", NULL);
|
|
|
|
if (!NT_SUCCESS(status = SetupExtractBuild(Context)))
|
|
{
|
|
context->LastStatus = status;
|
|
goto CleanupExit;
|
|
}
|
|
|
|
SetupSetProgressText(context, L"Installation complete.", NULL);
|
|
SetupSetProgressValue(context, 100);
|
|
context->SetupProgressActive = FALSE;
|
|
context->SetupCompleted = TRUE;
|
|
PostMessage(context->DialogHandle, SETUP_SHOWFINAL, 0, 0);
|
|
return STATUS_SUCCESS;
|
|
|
|
CleanupExit:
|
|
SetupSetProgressText(context, L"Installation failed.", NULL);
|
|
context->SetupProgressActive = FALSE;
|
|
PostMessage(context->DialogHandle, SETUP_SHOWERROR, 0, 0);
|
|
return STATUS_UNSUCCESSFUL;
|
|
}
|