[Setup] AppName=LOGAR Client AppVersion=0.3.2 AppPublisher=LOGAR Security Systems AppPublisherURL=https://logar.eibl.tech AppSupportURL=https://logar.eibl.tech AppUpdatesURL=https://logar.eibl.tech DefaultDirName={autopf}\LOGAR OutputDir=..\dist OutputBaseFilename=LOGAR-Client-Setup PrivilegesRequired=admin Compression=lzma SolidCompression=yes WizardStyle=modern VersionInfoCompany=LOGAR Security Systems VersionInfoDescription=LOGAR Windows Edge Log Forwarder Setup VersionInfoVersion=0.3.2.0 VersionInfoProductName=LOGAR Client VersionInfoProductVersion=0.3.2 [Files] Source: "..\dist\Win_Client.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "..\compilation\nssm.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "..\dist\runtime\*"; DestDir: "{app}\runtime"; Flags: ignoreversion recursesubdirs createallsubdirs [Dirs] Name: "{code:GetDataDir}"; Permissions: users-modify [Run] Filename: "{app}\nssm.exe"; Parameters: "install LOGAR_Client ""{app}\Win_Client.exe"""; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Client AppDirectory ""{app}"""; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Client AppStdout ""{code:GetDataDir}\client.log"""; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Client AppStderr ""{code:GetDataDir}\client_err.log"""; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "set LOGAR_Client AppParameters ""--config """"{code:GetDataDir}\client_config.json"""" --interval 30"""; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "start LOGAR_Client"; Flags: runhidden [UninstallRun] Filename: "{app}\nssm.exe"; Parameters: "stop LOGAR_Client"; Flags: runhidden Filename: "{app}\nssm.exe"; Parameters: "remove LOGAR_Client confirm"; Flags: runhidden [UninstallDelete] Type: filesandordirs; Name: "{app}\certs" Type: files; Name: "{app}\client_config.json" Type: files; Name: "{app}\client_state.json" Type: files; Name: "{app}\*.log" Type: filesandordirs; Name: "{app}\runtime" Type: filesandordirs; Name: "{app}" Type: filesandordirs; Name: "{commonappdata}\LOGAR" [Code] var DataDirPage: TInputDirWizardPage; ConfigFilePage: TInputFileWizardPage; procedure InitializeWizard; begin DataDirPage := CreateInputDirPage( wpSelectDir, 'Data and Configuration Location', 'Where should LOGAR Client store its state tracking and certificates?', 'Select the folder where LOGAR Client should store state tracking (client_state.json), configuration (client_config.json), and mTLS certificates.'#13#10#13#10 + 'By default, this is stored in Common AppData (C:\ProgramData\LOGAR), which is accessible to background Windows services.', False, '' ); DataDirPage.Add('Data Directory:'); DataDirPage.Values[0] := ExpandConstant('{commonappdata}\LOGAR'); ConfigFilePage := CreateInputFilePage( DataDirPage.ID, 'Import Client Configuration (Optional)', 'Do you have a pre-exported client_config.json profile to import?', 'Select your client_config.json profile exported from the LOGAR Server Hub.'#13#10#13#10 + 'If selected, this configuration will be copied into the data directory and used for automated server connection and enrollment.'#13#10#13#10 + 'You can also leave this blank to place client_config.json in the data directory manually later.' ); ConfigFilePage.Add('Client Configuration (client_config.json):', 'JSON Files (*.json)|*.json|All Files (*.*)|*.*', '.json'); end; function GetDataDir(Param: String): String; begin Result := DataDirPage.Values[0]; if Result = '' then Result := ExpandConstant('{commonappdata}\LOGAR'); end; function GetConfigFile(Param: String): String; begin Result := ConfigFilePage.Values[0]; end; procedure CurStepChanged(CurStep: TSetupStep); var ResultCode: Integer; CfgPath, DestCfg: String; begin if CurStep = ssInstall then begin Exec('net.exe', 'stop LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('sc.exe', 'stop LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('taskkill.exe', '/F /T /IM Win_Client.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Sleep(500); end else if CurStep = ssPostInstall then begin RegWriteStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Client', 'DataDir', GetDataDir('')); CfgPath := GetConfigFile(''); if (CfgPath <> '') and FileExists(CfgPath) then begin DestCfg := GetDataDir('') + '\client_config.json'; FileCopy(CfgPath, DestCfg, False); end; end; end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); var CustomDataDir, AppDir, PowerShellCmd: String; I, ResultCode: Integer; begin if CurUninstallStep = usUninstall then begin AppDir := ExpandConstant('{app}'); Exec('net.exe', 'stop LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('sc.exe', 'stop LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); if FileExists(AppDir + '\nssm.exe') then begin Exec(AppDir + '\nssm.exe', 'stop LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec(AppDir + '\nssm.exe', 'remove LOGAR_Client confirm', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); end; Exec('sc.exe', 'delete LOGAR_Client', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('taskkill.exe', '/F /T /IM Win_Client.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); PowerShellCmd := '-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "' + 'Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like ''' + AppDir + '\*'' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }"'; Exec('powershell.exe', PowerShellCmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Sleep(1200); end else if CurUninstallStep = usPostUninstall then begin AppDir := ExpandConstant('{app}'); Exec('taskkill.exe', '/F /T /IM Win_Client.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('taskkill.exe', '/F /T /IM nssm.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Client', 'DataDir', CustomDataDir) then begin if (CustomDataDir <> '') and DirExists(CustomDataDir) then begin for I := 1 to 5 do begin if DelTree(CustomDataDir, True, True, True) or not DirExists(CustomDataDir) then Break; Sleep(300); end; end; RegDeleteKeyIncludingSubkeys(HKEY_LOCAL_MACHINE, 'Software\LOGAR\LOGAR-Client'); end; if (AppDir <> '') and DirExists(AppDir) then begin for I := 1 to 10 do begin DeleteFile(AppDir + '\nssm.exe'); DeleteFile(AppDir + '\Win_Client.exe'); DelTree(AppDir + '\runtime', True, True, True); DelTree(AppDir + '\certs', True, True, True); if DelTree(AppDir, True, True, True) or not DirExists(AppDir) then Break; Sleep(300); end; end; end; end;