Skip to content

Commit b77c17a

Browse files
committed
Added reading, validation and display of SWAG version number
1 parent d4f3b3e commit b77c17a

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

Src/FmSWAGImportDlg.dfm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ inherited SWAGImportDlg: TSWAGImportDlg
1919
inherited pcWizard: TPageControl
2020
Width = 671
2121
Height = 456
22-
ActivePage = tsUpdate
22+
ActivePage = tsCategories
2323
ExplicitWidth = 671
2424
ExplicitHeight = 456
2525
object tsIntro: TTabSheet
@@ -136,6 +136,12 @@ inherited SWAGImportDlg: TSWAGImportDlg
136136
Caption = '&Select required packets:'
137137
FocusControl = clbSelectPackets
138138
end
139+
object lblVersionNumber: TLabel
140+
Left = 2
141+
Top = 427
142+
Width = 3
143+
Height = 13
144+
end
139145
object lbCategories: TListBox
140146
Left = 0
141147
Top = 64
@@ -147,7 +153,7 @@ inherited SWAGImportDlg: TSWAGImportDlg
147153
OnKeyDown = lbCategoriesKeyDown
148154
end
149155
object clbSelectPackets: TCheckListBox
150-
Left = 256
156+
Left = 240
151157
Top = 64
152158
Width = 404
153159
Height = 321
@@ -178,6 +184,10 @@ inherited SWAGImportDlg: TSWAGImportDlg
178184
Caption = 'tsUpdate'
179185
ImageIndex = 2
180186
TabVisible = False
187+
ExplicitLeft = 0
188+
ExplicitTop = 0
189+
ExplicitWidth = 0
190+
ExplicitHeight = 0
181191
object lblUpdateDesc: TLabel
182192
Left = 0
183193
Top = 3

Src/FmSWAGImportDlg.pas

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ TSWAGImportDlg = class(TWizardDlg, INoPublicConstruct)
6969
btnBrowse: TButton;
7070
actBrowse: TAction;
7171
frmIntro: THTMLTpltDlgFrame;
72+
lblVersionNumber: TLabel;
7273
/// <summary>Handles clicks on the check boxes next to packets in the
7374
/// packet selection list box by selecting and deselecting packets for
7475
/// inclusion in the import.</summary>
@@ -243,6 +244,7 @@ implementation
243244
// Project
244245
FmPreviewDlg,
245246
FmWaitDlg,
247+
SWAG.UVersion,
246248
UBrowseForFolderDlg,
247249
UColours,
248250
UConsts,
@@ -254,6 +256,7 @@ implementation
254256
UMessageBox,
255257
UStrUtils,
256258
UUrl,
259+
UVersionInfo,
257260
UWaitForThreadUI;
258261

259262
{$R *.dfm}
@@ -319,7 +322,7 @@ procedure TSWAGImportDlg.ArrangeForm;
319322
lblCategoriesDesc.Width := tsCategories.ClientWidth;
320323
lblCategoriesDesc.Top := 3;
321324
TCtrlArranger.AlignLefts(
322-
[lblCategoriesDesc, lblCategories, lbCategories], 0
325+
[lblCategoriesDesc, lblCategories, lbCategories, lblVersionNumber], 0
323326
);
324327
TCtrlArranger.AlignTops(
325328
[lblCategories, lblSelectPackets],
@@ -333,6 +336,11 @@ procedure TSWAGImportDlg.ArrangeForm;
333336
[btnDisplayCategory, btnDisplayPacket],
334337
TCtrlArranger.BottomOf([lbCategories, clbSelectPackets], 8)
335338
);
339+
TCtrlArranger.MoveBelow(
340+
[btnDisplayCategory, btnDisplayPacket],
341+
lblVersionNumber,
342+
8
343+
);
336344
TCtrlArranger.AlignHCentresTo([lbCategories], [btnDisplayCategory]);
337345
TCtrlArranger.AlignHCentresTo([clbSelectPackets], [btnDisplayPacket]);
338346

@@ -604,28 +612,23 @@ function TSWAGImportDlg.HeadingText(const PageIdx: Integer): string;
604612
end;
605613

606614
procedure TSWAGImportDlg.InitSelectionPage;
607-
//resourcestring
608-
// sDefaultWaitMsg = 'Accessing SWAG database...';
609615
var
610616
Cats: TList<TSWAGCategory>;
611617
Idx: Integer;
618+
VerNumStr: string;
619+
resourcestring
620+
sLblVersionNumberCaption = 'SWAG version %s';
612621
begin
622+
lblVersionNumber.Caption := Format(
623+
sLblVersionNumberCaption,
624+
[string(TSWAGVersion.GetVersion(GetDirNameFromEditCtrl))]
625+
);
626+
613627
Application.ProcessMessages;
614628

615629
if (lbCategories.Count > 0) then
616630
Exit;
617631

618-
// fPrevSWAGDir := GetDirNameFromEditCtrl;
619-
//
620-
// FreeAndNil(fSWAGReader);
621-
// fSWAGReader := TSWAGReader.Create(
622-
// GetDirNameFromEditCtrl,
623-
// procedure (CallProc: TProc)
624-
// begin
625-
// WaitWrapper(Self, CallProc, sDefaultWaitMsg);
626-
// end
627-
// );
628-
//
629632
Cats := TList<TSWAGCategory>.Create;
630633
try
631634
fSWAGReader.GetCategories(Cats);
@@ -856,11 +859,23 @@ procedure TSWAGImportDlg.ValidatePage(const PageIdx: Integer);
856859
sNoFolder = 'Please enter the directory where you downloaded the SWAG '
857860
+ 'database.';
858861
sBadFolder = 'Directory "%s" does not exist. Please specify a valid one.';
862+
sBadVersion = '%s.' + EOL2
863+
+ 'Please specify a directory containing a supported version.';
864+
sCorrupt = 'Not a valid SWAG database (%s). ' + EOL2
865+
+ 'Please specify a different directory.';
859866
begin
860867
if GetDirNameFromEditCtrl = '' then
861-
raise EDataEntry.Create(sNoFolder);
868+
raise EDataEntry.Create(sNoFolder, edPath);
862869
if not TDirectory.Exists(GetDirNameFromEditCtrl, False) then
863-
raise EDataEntry.CreateFmt(sBadFolder, [GetDirNameFromEditCtrl]);
870+
raise EDataEntry.CreateFmt(sBadFolder, [GetDirNameFromEditCtrl], edPath);
871+
try
872+
TSWAGVersion.ValidateVersionFile(GetDirNameFromEditCtrl);
873+
except
874+
on E: ECorruptSWAGVersion do
875+
raise EDataEntry.CreateFmt(sCorrupt, [E.Message], edPath);
876+
on E: EUnsupportedSWAGVersion do
877+
raise EDataEntry.CreateFmt(sBadVersion, [E.Message], edPath);
878+
end;
864879
end;
865880

866881
procedure ValidateSelectionPage;

0 commit comments

Comments
 (0)