Skip to content

Commit

Permalink
Fixes #92 - appsettings.json is overwritten during installation
Browse files Browse the repository at this point in the history
  • Loading branch information
replaysMike committed Feb 18, 2023
1 parent 708856b commit dcc7261
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions Binner/BinnerInstaller/BinnerInstaller.iss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
AppId={{5B8E7506-21A8-49BB-B144-6523D0E43E34}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName}
AppVerName={#MyAppName} v{#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
VersionInfoVersion={#MyAppVersion}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=..\Binner.Web\LICENSE
Expand All @@ -28,19 +29,21 @@ UninstallDisplayIcon={app}\{#MyAppExeName}
WizardImageFile=.\WizardLarge.bmp
WizardSmallImageFile=.\WizardSmall.bmp
CloseApplications=force
UsePreviousTasks=no


[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[CustomMessages]
UninstallingService=Uninstalling existing {#MyAppName} service...
InstallingService=Installing {#MyAppName} service...
InstallingService=Installing {#MyAppName} {#MyAppVersion} service...
InstallingCertificates=Installing certificates...
StartingApp=Starting {#MyAppName}...

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "keepconfiguration"; Description: "Keep existing configuration"
Name: "installservice"; Description: "Install {#MyAppName} as a Windows service"

[Files]
Expand Down Expand Up @@ -89,12 +92,49 @@ external '[email protected] stdcall';
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode : Integer;
SourcePath: string;
DestPath: string;
begin
// backup the appsettings
if CurStep = ssInstall then
begin
if WizardIsTaskSelected('keepconfiguration') then
begin
SourcePath := ExpandConstant('{app}\appsettings.json');
DestPath := ExpandConstant('{app}\appsettings.installerbackup.json');
if FileExists(SourcePath) then
begin
if not FileCopy(SourcePath, DestPath, False) then
begin
Log(Format('Backed up %s to %s', [SourcePath, DestPath]));
end
else
begin
Log(Format('Failed to Backup %s', [SourcePath]));
end;
end;
end;
end;
// Install the service if the task was checked by the user
if CurStep = ssPostInstall then
begin
Log('Post install');
if WizardIsTaskSelected('keepconfiguration') then
begin
// restore the appsettings
SourcePath := ExpandConstant('{app}\appsettings.json');
DestPath := ExpandConstant('{app}\appsettings.installerbackup.json');
if FileExists(DestPath) then
begin
if FileCopy(DestPath, SourcePath, False) then
begin
Log(Format('Restored %s from Backup %s', [SourcePath, DestPath]));
end;
end;
end;
// Install the certificate as trusted before launching apps
WizardForm.StatusLabel.Caption := CustomMessage('InstallingCertificates');
WizardForm.StatusLabel.Show();
Expand Down

0 comments on commit dcc7261

Please sign in to comment.