Check-in [99141eba3c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Releases are now listed in the correct order.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | feature/auto-update
Files: files | file ages | folders
SHA1:99141eba3c870ecbc12dc722ba544cb5d21380b8
User & Date: Martijn 2015-02-25 18:25:30
Context
2015-02-25
20:45
Double-click. Ask for confirmation when installing an older version. check-in: 15f44b970f user: Martijn tags: feature/auto-update
18:25
Releases are now listed in the correct order. check-in: 99141eba3c user: Martijn tags: feature/auto-update
18:02
ZPreview: streamlined download of release. check-in: 164505d2e1 user: Martijn tags: feature/auto-update
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ZPreview/src/Delphi/F_AutoUpdate.dfm.

60
61
62
63
64
65
66

67
68

69
70
71
72
73
74
75
        HeaderAlign = taLeftJustify
        FooterAlign = taLeftJustify
        TitleImage = -1
      end>
    GroupView = True
    ReadOnly = True
    RowSelect = True

    TabOrder = 0
    ViewStyle = vsReport

    OnSelectItem = lvwVersionsSelectItem
  end
  object mmoChanges: TMemo
    Left = 8
    Top = 224
    Width = 560
    Height = 169







>


>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        HeaderAlign = taLeftJustify
        FooterAlign = taLeftJustify
        TitleImage = -1
      end>
    GroupView = True
    ReadOnly = True
    RowSelect = True
    SortType = stData
    TabOrder = 0
    ViewStyle = vsReport
    OnCompare = lvwVersionsCompare
    OnSelectItem = lvwVersionsSelectItem
  end
  object mmoChanges: TMemo
    Left = 8
    Top = 224
    Width = 560
    Height = 169

Changes to ZPreview/src/Delphi/F_AutoUpdate.pas.

18
19
20
21
22
23
24


25
26


27
28
29
30
31
32
33
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
375
376
377
378
379
380
381











































382
383
384
385
386
387
388
    btnInstall: TButton;
    btnCancel: TButton;
    lblVersions: TLabel;
    btnWebpage: TButton;
    procedure lvwVersionsSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure btnWebpageClick(Sender: TObject);


  private
    { Private declarations }


  public
    { Public declarations }
    procedure Populate(const Versions: TDictionary<TDateTime,TXmlNode>);
  end;

  TUpdateChecker = class
  private
................................................................................
  finally
    xmlItems.Free;
  end;
end {TUpdateChecker.CheckForUpdate};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.AskUserForUpdate(out UUID: string): boolean;
var
  Match: TMatch;
begin
  UUID := '';

  if (not Assigned(FVersions)) or (FVersions.Count = 0) then
    CheckForUpdate;

  FForm := TfrmAutoUpdate.Create(Application);
  try
    // create form, populate list of versions, showmodal, and if the result
    // is mrOK, fill UUID with the link of the selected item.
    FForm.Populate(FVersions);

    Result := (FForm.ShowModal = mrOK);
    if Result and Assigned(FForm.lvwVersions.Selected) and Assigned(FForm.lvwVersions.Selected.Data) then begin
      UUID := TXmlNode(FForm.lvwVersions.Selected.Data).ReadUnicodeString('guid');
      Match := TRegEx.Match(UUID, '[0-9a-f]{10,}$', []);
      if Match.Success then begin
        UUID := Match.Groups[0].Value;
      end;
    end;
  finally
    FreeAndNil(FForm);
  end;
end {TUpdateChecker.AskUserForUpdate};

{ ------------------------------------------------------------------------------------------------ }
................................................................................

    if lvwVersions.Items.Count > 0 then
      lvwVersions.ItemIndex := 0;
  finally
    lvwVersions.Items.EndUpdate;
  end;
end {TfrmAutoUpdate.Populate};












































{ ------------------------------------------------------------------------------------------------ }
procedure TfrmAutoUpdate.lvwVersionsSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var
  xmlItem: TXmlNode;
begin







>
>


>
>







 







<
<













|
|
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
171
172
173
174
175
176
177


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192




193
194
195
196
197
198
199
...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
    btnInstall: TButton;
    btnCancel: TButton;
    lblVersions: TLabel;
    btnWebpage: TButton;
    procedure lvwVersionsSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure btnWebpageClick(Sender: TObject);
    procedure lvwVersionsCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer;
      var Compare: Integer);
  private
    { Private declarations }
    function UUIDFromItem(const Item: TListItem): string;
    function UUIDFromNode(const xmlItem: TXmlNode): string;
  public
    { Public declarations }
    procedure Populate(const Versions: TDictionary<TDateTime,TXmlNode>);
  end;

  TUpdateChecker = class
  private
................................................................................
  finally
    xmlItems.Free;
  end;
end {TUpdateChecker.CheckForUpdate};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.AskUserForUpdate(out UUID: string): boolean;


begin
  UUID := '';

  if (not Assigned(FVersions)) or (FVersions.Count = 0) then
    CheckForUpdate;

  FForm := TfrmAutoUpdate.Create(Application);
  try
    // create form, populate list of versions, showmodal, and if the result
    // is mrOK, fill UUID with the link of the selected item.
    FForm.Populate(FVersions);

    Result := (FForm.ShowModal = mrOK);
    if Result then begin
      UUID := FForm.UUIDFromItem(FForm.lvwVersions.Selected);




    end;
  finally
    FreeAndNil(FForm);
  end;
end {TUpdateChecker.AskUserForUpdate};

{ ------------------------------------------------------------------------------------------------ }
................................................................................

    if lvwVersions.Items.Count > 0 then
      lvwVersions.ItemIndex := 0;
  finally
    lvwVersions.Items.EndUpdate;
  end;
end {TfrmAutoUpdate.Populate};

{ ------------------------------------------------------------------------------------------------ }
function TfrmAutoUpdate.UUIDFromItem(const Item: TListItem): string;
begin
  if Assigned(Item) then
    Result := UUIDFromNode(TXmlNode(Item.Data));
end {TfrmAutoUpdate.UUIDFromItem};

{ ------------------------------------------------------------------------------------------------ }
function TfrmAutoUpdate.UUIDFromNode(const xmlItem: TXmlNode): string;
var
  Match: TMatch;
begin
  if Assigned(xmlItem) then begin
    Result := xmlItem.ReadUnicodeString('guid');
    Match := TRegEx.Match(Result, '[0-9a-f]{10,}$', []);
    if Match.Success then begin
      Result := Match.Groups[0].Value;
    end;
  end;
end {TfrmAutoUpdate.UUIDFromNode};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmAutoUpdate.lvwVersionsCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer;
  var Compare: Integer);
var
  D1, D2: TDateTime;
begin
  if Item1.Data = nil then
    D1 := 0
  else
    D1 := StrToDateTime(Item1.Caption);
  if Item2.Data = nil then
    D2 := 0
  else
    D2 := StrToDateTime(Item2.Caption);
  if D1 = D2 then
    Compare := 0
  else if D1 < D2 then
    Compare := 1
  else
    Compare := -1;
end {TfrmAutoUpdate.lvwVersionsCompare};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmAutoUpdate.lvwVersionsSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var
  xmlItem: TXmlNode;
begin