Skip to content

Commit 9b1bb9e

Browse files
author
delphidabbler
committed
Add conditional compilation for how common config file is processed with different program editions
Standard version performs as before, but portable version simply deletes common config file if present.
1 parent 18d49e1 commit 9b1bb9e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Src/FirstRun.UConfigFile.pas

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,26 @@ TCommonConfigFileUpdater = class(TConfigFileUpdater)
130130
public
131131
/// <summary>Stamps config file with current program and file versions.
132132
/// </summary>
133-
/// <remarks>Note that the user config file has program version written to
133+
/// <remarks>
134+
/// <para>Note that the user config file has program version written to
134135
/// a different section to common config file, hence need for overridden
135-
/// methods.</remarks>
136+
/// methods.</para>
137+
/// <para>Does nothing in portable edition.</para>
138+
/// </remarks>
136139
procedure Stamp; override;
140+
{$IFNDEF PORTABLE}
137141
/// <summary>Deletes program registration information from application
138142
/// section.</summary>
143+
/// <remarks>Standard edition only.</remarks>
139144
procedure DeleteRegistrationInfo;
140145
/// <summary>Deletes program key from application section.</summary>
146+
/// <remarks>Standard edition only.</remarks>
141147
procedure DeleteProgramKey;
148+
{$ELSE}
149+
/// <summary>Deletes and common config file</summary>
150+
/// <remarks>Portable edition only</remarks>
151+
procedure DeleteCfgFile;
152+
{$ENDIF}
142153
end;
143154

144155

@@ -488,20 +499,32 @@ procedure TUserConfigFileUpdater.UpdateNamespaces;
488499

489500
{ TCommonConfigFileUpdater }
490501

502+
{$IFDEF PORTABLE}
503+
procedure TCommonConfigFileUpdater.DeleteCfgFile;
504+
begin
505+
if TFile.Exists(CfgFileName, False) then
506+
TFile.Delete(CfgFileName);
507+
end;
508+
{$ENDIF}
509+
510+
{$IFNDEF PORTABLE}
491511
procedure TCommonConfigFileUpdater.DeleteProgramKey;
492512
begin
493513
if not TFile.Exists(CfgFileName, False) then
494514
CreateNewFile;
495515
DeleteIniKey('Application', 'Key', CfgFileName);
496516
end;
517+
{$ENDIF}
497518

519+
{$IFNDEF PORTABLE}
498520
procedure TCommonConfigFileUpdater.DeleteRegistrationInfo;
499521
begin
500522
if not TFile.Exists(CfgFileName, False) then
501523
CreateNewFile;
502524
DeleteIniKey('Application', 'RegCode', CfgFileName);
503525
DeleteIniKey('Application', 'RegName', CfgFileName);
504526
end;
527+
{$ENDIF}
505528

506529
class function TCommonConfigFileUpdater.GetFileVersion: Integer;
507530
begin
@@ -510,10 +533,12 @@ class function TCommonConfigFileUpdater.GetFileVersion: Integer;
510533

511534
procedure TCommonConfigFileUpdater.Stamp;
512535
begin
536+
{$IFNDEF PORTABLE}
513537
inherited;
514538
SetIniString(
515539
'Application', 'Version', TAppInfo.ProgramReleaseVersion, CfgFileName
516540
);
541+
{$ENDIF}
517542
end;
518543

519544
end.

Src/FirstRun.UMain.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,22 @@ procedure TFirstRun.UpdateUserCfgFile(out Changes: TFirstRunCfgChangeSet);
246246

247247
if fCommonConfigFile.FileVer < 7 then
248248
begin
249+
{$IFNDEF PORTABLE}
249250
fCommonConfigFile.DeleteRegistrationInfo;
250251
fCommonConfigFile.DeleteProgramKey;
252+
{$ENDIF}
251253
end;
252254

253255
fUserConfigFile.Stamp;
256+
257+
{$IFNDEF PORTABLE}
254258
// NOTE: strictly speaking we only need to stamp common config file in
255259
// portable version. Installer does this in normal version. However, it does
256260
// no harm to stamp this file twice - belt and braces!
257261
fCommonConfigFile.Stamp;
262+
{$ELSE}
263+
fCommonConfigFile.DeleteCfgFile;
264+
{$ENDIF}
258265
end;
259266

260267
{ TFirstRunMgr }

0 commit comments

Comments
 (0)