@@ -19,7 +19,7 @@ interface
1919
2020uses
2121 // Project
22- FirstRun.UConfigFile, FirstRun.UDatabase, FirstRun.UInstallInfo;
22+ FirstRun.UConfigFile, FirstRun.UDatabase, FirstRun.UInstallInfo, UVersionInfo ;
2323
2424
2525type
@@ -79,8 +79,17 @@ TFirstRun = class(TObject)
7979 // / <summary>Creates a new, empty, Unicode encoded per-user config file for
8080 // / current installation.</summary>
8181 procedure CreateEmptyUserCfgFile ;
82- // / <summary>
82+ // / <summary>Checks if the program has been updated since the last run.
83+ // / </summary>
84+ // / <remarks>Compares the version number stored in the brought forward
85+ // / config file against the current program version number from resources.
86+ // / </remarks>
8387 function IsProgramUpdated : Boolean;
88+ // / <summary>Checks if the previous program's version number, as specified
89+ // / in the user config file, is contained in the range Lo..Hi with range
90+ // / endpoints determined by IntervalEndPoints.</summary>
91+ function IsPreviousProgramVerInRange (const Lo, Hi: TVersionNumber;
92+ const IntervalEndPoints: TVersionNumber.TIntervalEndPoints): Boolean;
8493 end ;
8594
8695type
@@ -108,7 +117,8 @@ TFirstRunMgr = class(TObject)
108117 class function IsProgramUpdated : Boolean;
109118 public
110119 // / <summary>Runs start-up checks to detect if program has been run before
111- // / and performs any required user config and user database updates.
120+ // / and performs any required user config and user database updates. In
121+ // / some circumstances a "what's new" dialogue box may be displayed.
112122 // / </summary>
113123 class procedure Execute ;
114124 end ;
@@ -119,9 +129,10 @@ implementation
119129
120130uses
121131 // Delphi
122- SysUtils, IOUtils, Forms
123- { $IFNDEF PORTABLE}
132+ SysUtils, IOUtils, Forms,
124133 // Project
134+ FirstRun.FmWhatsNew
135+ { $IFNDEF PORTABLE}
125136 ,
126137 FirstRun.FmV4ConfigDlg;
127138 { $ELSE}
@@ -187,6 +198,15 @@ function TFirstRun.HaveOldUserDB: Boolean;
187198 Result := TFile.Exists(fInstallInfo.PreviousUserDatabaseFileName, False);
188199end ;
189200
201+ function TFirstRun.IsPreviousProgramVerInRange (const Lo, Hi: TVersionNumber;
202+ const IntervalEndPoints: TVersionNumber.TIntervalEndPoints): Boolean;
203+ var
204+ PrevProgVer: TVersionNumber;
205+ begin
206+ PrevProgVer := fUserConfigFile.PreviousProgramVer;
207+ Result := PrevProgVer.IsInRange(Lo, Hi, IntervalEndPoints);
208+ end ;
209+
190210function TFirstRun.IsProgramUpdated : Boolean;
191211begin
192212 Result := fUserConfigFile.IsCurrentProgramVer;
@@ -270,6 +290,12 @@ procedure TFirstRun.UpdateUserCfgFile(out Changes: TFirstRunCfgChangeSet);
270290{ TFirstRunMgr }
271291
272292class procedure TFirstRunMgr.Execute ;
293+ const
294+ // Version numbers specifying a range in which previous program version must
295+ // lie in order to display "What's New" dialogue box.
296+ // Range is [NeedWhatsNewLoVerIncl, NeedWhatsNewHiVerExcl)
297+ NeedWhatsNewLoVerIncl: TVersionNumber = (V1: 4 ; V2: 0 ; V3: 0 ; V4: 0 );
298+ NeedWhatsNewHiVerExcl: TVersionNumber = (V1: 4 ; V2: 16 ; V3: 0 ; V4: 0 );
273299var
274300 FR: TFirstRun;
275301 Changes: TFirstRunCfgChangeSet;
@@ -295,7 +321,15 @@ class procedure TFirstRunMgr.Execute;
295321 begin
296322 FR := TFirstRun.Create;
297323 try
298- FR.UpdateUserCfgFile(Changes);
324+ // We display "What's New" dialogue box if previous program version number
325+ // is in the given range
326+ if FR.IsPreviousProgramVerInRange(
327+ NeedWhatsNewLoVerIncl,
328+ NeedWhatsNewHiVerExcl,
329+ TVersionNumber.TIntervalEndPoints.iepHalfOpenHi
330+ ) then
331+ TWhatsNewDlg.Execute(Application);
332+ FR.UpdateUserCfgFile(Changes); // we ignore Changes [out] param value
299333 finally
300334 FR.Free;
301335 end ;
0 commit comments