mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-01-05 00:04:42 +00:00
91 lines
2.4 KiB
ObjectPascal
91 lines
2.4 KiB
ObjectPascal
{
|
|
Helper functions
|
|
}
|
|
|
|
{
|
|
Checks to see if the installer is an 'upgrade'
|
|
}
|
|
function IsUpgrade: Boolean;
|
|
var
|
|
Value: string;
|
|
UninstallKey: string;
|
|
begin
|
|
UninstallKey := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' +
|
|
ExpandConstant('{#SetupSetting("AppId")}') + '_is1';
|
|
Result := (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or
|
|
RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and (Value <> '');
|
|
end;
|
|
|
|
{
|
|
Kills a running program by its filename
|
|
}
|
|
procedure TaskKill(fileName: String);
|
|
var
|
|
ResultCode: Integer;
|
|
begin
|
|
Exec(ExpandConstant('taskkill.exe'), '/f /im ' + '"' + fileName + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
end;
|
|
|
|
|
|
{
|
|
Executes the MSI Uninstall by GUID functionality
|
|
}
|
|
function MsiExecUnins(appId: String): Integer;
|
|
var
|
|
ResultCode: Integer;
|
|
begin
|
|
ShellExec('', 'msiexec.exe', '/x ' + appId + ' /qn', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
|
Result := ResultCode;
|
|
end;
|
|
|
|
{
|
|
Copies and entire folder
|
|
}
|
|
procedure DirectoryCopy(SourcePath, DestPath: string);
|
|
var
|
|
FindRec: TFindRec;
|
|
SourceFilePath: string;
|
|
DestFilePath: string;
|
|
begin
|
|
if FindFirst(SourcePath + '\*', FindRec) then
|
|
begin
|
|
try
|
|
repeat
|
|
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
|
|
begin
|
|
SourceFilePath := SourcePath + '\' + FindRec.Name;
|
|
DestFilePath := DestPath + '\' + FindRec.Name;
|
|
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
|
|
begin
|
|
if FileCopy(SourceFilePath, DestFilePath, False) then
|
|
begin
|
|
Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath]));
|
|
end
|
|
else
|
|
begin
|
|
Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath]));
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
if DirExists(DestFilePath) or CreateDir(DestFilePath) then
|
|
begin
|
|
Log(Format('Created %s', [DestFilePath]));
|
|
DirectoryCopy(SourceFilePath, DestFilePath);
|
|
end
|
|
else
|
|
begin
|
|
Log(Format('Failed to create %s', [DestFilePath]));
|
|
end;
|
|
end;
|
|
end;
|
|
until not FindNext(FindRec);
|
|
finally
|
|
FindClose(FindRec);
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
Log(Format('Failed to list %s', [SourcePath]));
|
|
end;
|
|
end; |