Check-in [fe2a47f131]
Not logged in

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

Overview
Comment:Added unit for auto-update, containing a class for checking and performing auto-update, as well as a form to show available versions, and let the user choose.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | feature/auto-update
Files: files | file ages | folders
SHA1:fe2a47f131480119e633247d8892952c11b389d5
User & Date: tinus 2015-02-25 09:47:35
Context
2015-02-25
09:59
Added comments for future developments. check-in: e867df2a17 user: tinus tags: feature/auto-update
09:47
Added unit for auto-update, containing a class for checking and performing auto-update, as well as a form to show available versions, and let the user choose. check-in: fe2a47f131 user: tinus tags: feature/auto-update
09:45
Started new branch for auto-update feature. Added NativeXml units (SVN revision: http://simdesign.googlecode.com/svn/trunk@221) check-in: d2d9ddc853 user: tinus tags: feature/auto-update
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ZPreview/src/Delphi/F_AutoUpdate.dfm.









































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
object frmAutoUpdate: TfrmAutoUpdate
  Left = 0
  Top = 0
  Caption = 'Update'
  ClientHeight = 448
  ClientWidth = 576
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poOwnerFormCenter
  DesignSize = (
    576
    448)
  PixelsPerInch = 96
  TextHeight = 13
  object lblVersions: TLabel
    Left = 8
    Top = 29
    Width = 90
    Height = 13
    Caption = '&Available versions:'
  end
  object lvwVersions: TListView
    Left = 8
    Top = 48
    Width = 560
    Height = 170
    Anchors = [akLeft, akTop, akRight]
    Columns = <>
    TabOrder = 0
  end
  object mmoChanges: TMemo
    Left = 8
    Top = 224
    Width = 560
    Height = 169
    Anchors = [akLeft, akTop, akRight, akBottom]
    ReadOnly = True
    ScrollBars = ssVertical
    TabOrder = 1
  end
  object btnInstall: TButton
    Left = 338
    Top = 408
    Width = 112
    Height = 32
    Anchors = [akRight, akBottom]
    Caption = '&Install'
    Default = True
    ElevationRequired = True
    Enabled = False
    TabOrder = 2
  end
  object btnCancel: TButton
    Left = 456
    Top = 408
    Width = 112
    Height = 32
    Anchors = [akRight, akBottom]
    Cancel = True
    Caption = '&Cancel'
    TabOrder = 3
  end
end

Added ZPreview/src/Delphi/F_AutoUpdate.pas.









































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
unit F_AutoUpdate;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,
  NativeXml;

type
  TfrmAutoUpdate = class(TForm)
    lvwVersions: TListView;
    mmoChanges: TMemo;
    btnInstall: TButton;
    btnCancel: TButton;
    lblVersions: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TUpdateChecker = class
  private
    FXmlFeed: TNativeXml;
    FForm: TfrmAutoUpdate;
    procedure LoadFeed;
  public
    destructor  Destroy; override;

    function  CheckForUpdate: boolean;
    function  AskUserForUpdate(out UUID: string): boolean;
    procedure UpdateToVersion(const UUID: string);

    property XmlFeed: TNativeXml  read FXmlFeed;
  end;

implementation

{$R *.dfm}

{ ================================================================================================ }
{ TUpdateChecker }

{ ------------------------------------------------------------------------------------------------ }
destructor TUpdateChecker.Destroy;
begin
  if Assigned(FForm) then
    FForm.Free;
  if Assigned(FXmlFeed) then
    FXmlFeed.Free;
  inherited;
end {TUpdateChecker.Destroy};

{ ------------------------------------------------------------------------------------------------ }
procedure TUpdateChecker.LoadFeed;
var
  URL: UTF8String;
begin
  if not Assigned(FXmlFeed) then begin
    URL := Format('http://fossil.2of4.net/zaap/timeline.rss?y=ci&tag=zpreview&name=ZPreview.%d.exe',
                  [{$IFDEF WIN32}32{$ELSE}64{$ENDIF}]);
    FXmlFeed := TNativeXml.Create(nil);
    try
      FXmlFeed.LoadFromURL(URL);
    except
      FreeAndNil(FXmlFeed);
      raise;
    end;
  end;
end {TUpdateChecker.LoadFeed};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.CheckForUpdate: boolean;
var
  xmlChannel: TXmlNode;
  xmlItems: TList;
  i: Integer;
  xmlItem: TXmlNode;
  sPubDate: string;
begin
  LoadFeed;

  Result := False;
  xmlChannel := FXmlFeed.Root.NodeByName('channel');
  xmlItems := TList.Create;
  try
    xmlChannel.NodesByName('item', xmlItems);
    for i := 0 to xmlItems.Count - 1 do begin
      xmlItem := TXmlNode(xmlItems[i]);
      // TODO: keep track of the relevant XML nodes, including some pre-parsed
      //  data, like the publication date as TDateTime, the author, the link,
      //  the title and the description.
      sPubDate := string(xmlItem.ReadString('pubDate'));
      {$MESSAGE WARN 'TODO: Read pubDate; if more recent than our executable’s last-modified date, result is true — MCO 25-02-2015'}

    end;
  finally
    xmlItems.Free;
  end;
end {TUpdateChecker.CheckForUpdate};

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

end {TUpdateChecker.AskUserForUpdate};

{ ------------------------------------------------------------------------------------------------ }
procedure TUpdateChecker.UpdateToVersion(const UUID: string);
begin

end {TUpdateChecker.UpdateToVersion};

end.

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

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  modMain: TmodMain;

implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}

uses
  F_Main,
  F_PE_Graphics, {$IFDEF WIN32}F_PE_FreeImage,{$ENDIF} F_PE_PreviewHandlers, F_PE_WlxPlugins,
  F_PE_Text, F_PE_ShellItemImages, F_PE_Hex;

{ ------------------------------------------------------------------------------------------------ }
procedure TmodMain.tmrStartTimer(Sender: TObject);
begin
  tmrStart.Enabled := False;
  frmMain.ActionManager.FindItemByAction(frmMain.actAutorefresh).Action.Execute;
end {TmodMain.tmrStartTimer};

end.







|











22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  modMain: TmodMain;

implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}

uses
  F_Main, F_AutoUpdate,
  F_PE_Graphics, {$IFDEF WIN32}F_PE_FreeImage,{$ENDIF} F_PE_PreviewHandlers, F_PE_WlxPlugins,
  F_PE_Text, F_PE_ShellItemImages, F_PE_Hex;

{ ------------------------------------------------------------------------------------------------ }
procedure TmodMain.tmrStartTimer(Sender: TObject);
begin
  tmrStart.Enabled := False;
  frmMain.ActionManager.FindItemByAction(frmMain.actAutorefresh).Action.Execute;
end {TmodMain.tmrStartTimer};

end.