106 lines
3.9 KiB
Plaintext
106 lines
3.9 KiB
Plaintext
[Setup]
|
|
AppId=LanUps.Desktop
|
|
AppName=LanUps
|
|
AppVersion={#AppVersion}
|
|
VersionInfoVersion={#AppVersion}
|
|
AppPublisher=LanUps Project
|
|
DefaultDirName={code:DefaultInstallDirectory}
|
|
DefaultGroupName=LanUps
|
|
DisableWelcomePage=no
|
|
DisableDirPage=no
|
|
DisableProgramGroupPage=yes
|
|
ArchitecturesAllowed=x64compatible
|
|
ArchitecturesInstallIn64BitMode=x64compatible
|
|
PrivilegesRequired=admin
|
|
WizardStyle=modern
|
|
SetupIconFile=..\..\src\LanUps.Desktop\Assets\ups.ico
|
|
Compression=lzma2
|
|
SolidCompression=yes
|
|
UninstallDisplayIcon={app}\Desktop\LanUps.Desktop.exe
|
|
SetupLogging=yes
|
|
|
|
[Languages]
|
|
Name: "en"; MessagesFile: "compiler:Default.isl"
|
|
#ifdef ChineseMessages
|
|
Name: "zhcn"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
|
|
#endif
|
|
|
|
[Files]
|
|
Source: "deployment.ps1"; Flags: dontcopy
|
|
Source: "{#PayloadDir}\Agent\*"; DestDir: "{app}\Agent"; Excludes: "*.pdb,*.dbg"; Flags: ignoreversion recursesubdirs createallsubdirs
|
|
Source: "{#PayloadDir}\Desktop\*"; DestDir: "{app}\Desktop"; Excludes: "*.pdb,*.dbg"; Flags: ignoreversion recursesubdirs createallsubdirs
|
|
Source: "deployment.ps1"; DestDir: "{app}"; Flags: ignoreversion
|
|
Source: "install.ps1"; DestDir: "{app}"; Flags: ignoreversion
|
|
|
|
[Icons]
|
|
Name: "{autoprograms}\LanUps"; Filename: "{app}\Desktop\LanUps.Desktop.exe"; WorkingDir: "{app}\Desktop"
|
|
Name: "{autodesktop}\局域网 UPS"; Filename: "{app}\Desktop\LanUps.Desktop.exe"; WorkingDir: "{app}\Desktop"
|
|
|
|
[CustomMessages]
|
|
en.DeploymentFailed=LanUps service deployment failed. See %%ProgramData%%\LanUps\setup.log for details.
|
|
#ifdef ChineseMessages
|
|
zhcn.DeploymentFailed=LanUps 后台服务部署失败。详细信息见 %%ProgramData%%\LanUps\setup.log。
|
|
#endif
|
|
|
|
[Code]
|
|
function DefaultInstallDirectory(Param: String): String;
|
|
var
|
|
Command, Suffix: String;
|
|
Ending: Integer;
|
|
begin
|
|
Result := ExpandConstant('{autopf}\LanUps');
|
|
Suffix := '\Agent\LanUps.Agent.exe"';
|
|
if RegQueryStringValue(HKLM, 'SYSTEM\CurrentControlSet\Services\LanUps.Agent', 'ImagePath', Command) then
|
|
begin
|
|
Ending := Pos(Lowercase(Suffix), Lowercase(Command));
|
|
if (Ending > 4) and (Copy(Command, 1, 1) = '"') then
|
|
Result := Copy(Command, 2, Ending - 2);
|
|
end;
|
|
end;
|
|
|
|
function RunDeployment(const Script, Mode: String): Boolean;
|
|
var
|
|
Arguments, Operator: String;
|
|
ExitCode: Integer;
|
|
begin
|
|
Arguments := '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File ' + AddQuotes(Script) +
|
|
' -Mode ' + Mode + ' -AppRoot ' + AddQuotes(ExpandConstant('{app}'));
|
|
if Mode = 'Install' then
|
|
begin
|
|
Operator := ExpandConstant('{param:OPERATOR|}');
|
|
if (Pos('"', Operator) > 0) or (Pos(#13, Operator) > 0) or (Pos(#10, Operator) > 0) then
|
|
RaiseException('Invalid /OPERATOR value.');
|
|
if Operator <> '' then
|
|
Arguments := Arguments + ' -Operator ' + AddQuotes(Operator);
|
|
if ExpandConstant('{param:ENABLESHUTDOWN|0}') = '1' then
|
|
Arguments := Arguments + ' -EnableShutdown';
|
|
end;
|
|
ExitCode := -1;
|
|
Result := Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'),
|
|
Arguments, ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ExitCode);
|
|
Log(Format('LanUps deployment %s: launched=%d, code=%d', [Mode, Ord(Result), ExitCode]));
|
|
Result := Result and (ExitCode = 0);
|
|
end;
|
|
|
|
function PrepareToInstall(var NeedsRestart: Boolean): String;
|
|
begin
|
|
Result := '';
|
|
ExtractTemporaryFile('deployment.ps1');
|
|
if not RunDeployment(ExpandConstant('{tmp}\deployment.ps1'), 'Prepare') then
|
|
Result := CustomMessage('DeploymentFailed');
|
|
end;
|
|
|
|
procedure CurStepChanged(CurStep: TSetupStep);
|
|
begin
|
|
if CurStep = ssPostInstall then
|
|
if not RunDeployment(ExpandConstant('{app}\deployment.ps1'), 'Install') then
|
|
RaiseException(CustomMessage('DeploymentFailed'));
|
|
end;
|
|
|
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
|
begin
|
|
if CurUninstallStep = usUninstall then
|
|
if not RunDeployment(ExpandConstant('{app}\deployment.ps1'), 'Uninstall') then
|
|
RaiseException(CustomMessage('DeploymentFailed'));
|
|
end;
|