Check-in [af8a21be2f]
Not logged in

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

Overview
Comment:Merged in changes from develop.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | feature/sentinel-thread
Files: files | file ages | folders
SHA1:af8a21be2fe3c527f862965e5598a8caa4f124dc
User & Date: tinus 2016-03-03 07:42:42
Context
2016-03-03
07:42
Merged in changes from develop. Leaf check-in: af8a21be2f user: tinus tags: feature/sentinel-thread
2016-02-14
12:25
Updated projects to Delphi 10 Seattle. Moved whatsnew for ZPreview to separate file. check-in: d51c3cafcf user: tinus tags: feature/sentinel-thread
2015-09-09
10:45
Auto-update form keeps track of the current executable and version up front, and uses that when necessary. check-in: 11941c0935 user: tinus tags: develop
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

1
2
3
4
5
6
7
8
9
10
11
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'



|







1
2
3
4
5
6
7
8
9
10
11
object frmAutoUpdate: TfrmAutoUpdate
  Left = 0
  Top = 0
  Caption = 'Check for updates'
  ClientHeight = 448
  ClientWidth = 576
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'

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

1
2

3
4
5
6
7
8
9
..
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
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
...
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262



263
264
265
266
267
268
269
...
274
275
276
277
278
279
280

281
282






283
284
285
286
287
288
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
...
322
323
324
325
326
327
328












329
330
331
332
333
334
335
...
446
447
448
449
450
451
452

453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
...
498
499
500
501
502
503
504



























505
unit F_AutoUpdate;


interface

uses
  System.SysUtils, System.Variants, System.Classes, System.Generics.Collections,
  System.Zip,
  Winapi.Windows, Winapi.Messages,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,
................................................................................
    function UUIDFromNode(const xmlItem: TXmlNode): string;
  public
    { Public declarations }
    procedure Populate(const UpdateChecker: TUpdateChecker);
  end;

  TUpdateChecker = class


  private
    FBaseURL: string;
    FTagName: string;
    FXmlFeed: TNativeXml;
    FVersions: TDictionary<TDateTime,TXmlNode>;
    FForm: TfrmAutoUpdate;

    procedure LoadFeed;
    function  DownloadFromURL(const URL: string): TStream;
  public
    constructor Create(const BaseURL, BranchName: string);
    destructor  Destroy; override;




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

    property BaseURL: string                            read FBaseURL;
    property TagName: string                            read FTagName;
    property XmlFeed: TNativeXml                        read FXmlFeed;
    property Versions: TDictionary<TDateTime,TXmlNode>  read FVersions;
  end;


implementation
uses
  System.RegularExpressions, System.Types, System.IOUtils, System.UITypes, System.DateUtils,
  Winapi.ShellAPI, Winapi.WinInet,
  REST.Utils,
  L_VersionInfoW;

{$R *.dfm}




{ ------------------------------------------------------------------------------------------------ }
// http://stackoverflow.com/a/8438985/3092116
function LinkerTimestamp: TDateTime; overload;
begin
  Result := PImageNtHeaders(HInstance + PImageDosHeader(HInstance)^._lfanew)^.FileHeader.TimeDateStamp / SecsPerDay + UnixDateDelta;
end {LinkerTimestamp};

................................................................................
      FreeAndNil(FXmlFeed);
      raise;
    end;
  end;
end {TUpdateChecker.LoadFeed};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.CheckForUpdate: boolean;
var
  en_US: TFormatSettings;
  rexDateTime: TRegEx;
  xmlChannel: TXmlNode;
  xmlItems: TList;
  i, mi: Integer;
  xmlItem: TXmlNode;
  sPubDate: string;
  PubDate: TDateTime;
  Match: TMatch;
  Day, Month, Year: Integer;
begin

  LoadFeed;

  rexDateTime := TRegEx.Create('(\d{1,2})\s+(\w{2,})\s+(\d{4})\s+(\d?\d:\d\d:\d\d)', [roCompiled]);
  en_US := TFormatSettings.Create('en-US');

  Result := False;
  xmlChannel := FXmlFeed.Root.NodeByName('channel');
  xmlItems := TList.Create;
................................................................................
    FreeAndNil(FForm);
  end;
end {TUpdateChecker.AskUserForUpdate};

{ ------------------------------------------------------------------------------------------------ }
procedure TUpdateChecker.UpdateToVersion(const UUID: string);
var
  ExeName, ExeVersion: string;
  WorkPath, PathPrefix, BackupPrefix: string;
  ZipStream: TStream;
  Zip: TZipFile;
  i: Integer;
  FileName, PathName: string;

  SI: TStartupInfo;
  PI: TProcessInformation;
begin
  ExeName := Application.ExeName;
  with TFileVersionInfo.Create(ExeName) do begin
    try
      if HasVersionInfo then begin
        ExeVersion := Format('%d.%d.%d.%d', [MajorVersion, MinorVersion, Revision, Build]);
      end;
    finally
      Free;
    end;
  end;

  WorkPath := ExtractFilePath(ExeName);
  BackupPrefix := '~';
  if ExeVersion <> '' then
    BackupPrefix := BackupPrefix + ExeVersion;

  // download the zip from http://fossil.2of4.net/zaap/zip/zpreview.zip?uuid={UUID}
  {$MESSAGE HINT 'Pass a routine to update the progress bar? — Martijn 2015-08-11'}
  ZipStream := DownloadFromURL(FBaseURL + 'zip/' + URIEncode(FTagName) + '.zip?uuid=' + URIEncode(UUID));
  if not Assigned(ZipStream) then
    raise Exception.Create('Failed to download release ' + UUID + '.');
  try
    Zip := TZipFile.Create;
    try
      Zip.Open(ZipStream, zmRead);

      // extract each file, and try to rename an eventual existing file.
      PathPrefix := FTagName + '/';
................................................................................
        PathName := ExtractFilePath(FileName);
        FileName := ExtractFileName(FileName);
        if FileName <> '' then begin
          if PathName <> '' then
            ForceDirectories(WorkPath + PathName);

          // Test for existing file, and rename that
          {$MESSAGE HINT 'TODO: Save all new files to temp files in the same dir, then afterwards, use ReplaceFile for each of them — MCO 25-02-2015'}
          if FileExists(WorkPath + PathName + FileName) then begin
            RenameFile(WorkPath + PathName + FileName, WorkPath + PathName + ChangeFileExt(FileName, BackupPrefix + ExtractFileExt(FileName)));
          end;

          Zip.Extract(i, WorkPath + PathName, False);

          // adjust the new file's modified time
          TFile.SetLastWriteTime(WorkPath + PathName + FileName, FileDateToDateTime(Zip.FileInfo[i].ModifiedDateTime));



        end;
      end;

      // TODO: use transacted file operations, so we can roll them back if something fails?
    finally
      Zip.Free;
    end;
................................................................................
  // Close the current instance...
  Application.Tag := -1; // signal for the single-instance algorithm that we're shutting down
  Application.OnException := nil;
  Application.Terminate;
  Application.MainForm.Close;

  // ...and start a new one

  if not CreateProcess(nil, PChar(ExeName), nil, nil, True, 0, nil, nil, SI, PI) then
    RaiseLastOSError;






end {TUpdateChecker.UpdateToVersion};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.DownloadFromURL(const URL: string): TStream;
var
  UserAgent: string;
  NetHandle, UrlHandle: HINTERNET;
  Buffer: array[0..$400 - 1] of AnsiChar;
  BytesRead: cardinal;
begin
  Result := nil;

  UserAgent := ChangeFileExt(ExtractFileName(Application.ExeName), '').Replace(' ', '');


  NetHandle := InternetOpenW(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

  if not assigned(NetHandle) then begin
    // NetHandle is not valid.
//    DoDebugOut(Self, wsFail, 'Unable to initialize WinInet');
    exit;
  end;
................................................................................
    InternetCloseHandle(UrlHandle);

    Result.Position := 0;
  finally
    InternetCloseHandle(NetHandle);
  end;
end {TUpdateChecker.DownloadFromURL};

















{ ================================================================================================ }
{ TfrmAutoUpdate }
................................................................................
  xmlItem: TXmlNode;
begin
  if Selected = False then begin
    btnInstall.Enabled := False;
    btnWebpage.Enabled := False;
    mmoChanges.Clear;
  end else begin

    xmlItem := TXmlNode(Item.Data);
    if Assigned(xmlItem) then begin

      mmoChanges.Lines.Text := xmlItem.ReadUnicodeString('description', '(no description provided)');
      btnInstall.Enabled := True;
      btnWebpage.Enabled := True;
    end else begin
      btnInstall.Enabled := False;
      btnWebpage.Enabled := True;
    end;
  end;
end {TfrmAutoUpdate.lvwVersionsSelectItem};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmAutoUpdate.btnInstallClick(Sender: TObject);
begin
  // Check if it's an older version
  if lvwVersions.Selected.GroupID = 1 then begin
    if TaskMessageDlg('Download and install an OLDER version?',
                      'You will overwrite the current version of ZPreview with the following version:'#13#10 +
                        #13#10 +
                        lvwVersions.Selected.SubItems[1] + #13#10 +
                        #13#10 +
                        'Are you certain you want to do this?',
                      mtWarning, mbYesNo, 0, mbNo) <> mrYes then begin
      Self.ModalResult := mrNone;
    end;
................................................................................
procedure TfrmAutoUpdate.btnWebpageClick(Sender: TObject);
var
  UUID, URL: string;
  xmlItem: TXmlNode;
begin
  UUID := UUIDFromItem(lvwVersions.Selected);
  if UUID <> '' then begin
    URL := FUpdateChecker.BaseURL + 'dir?ci=' + URIEncode(UUID) + '&type=tree';
  end else if Assigned(lvwVersions.Selected) then begin
    xmlItem := TXmlNode(lvwVersions.Selected.Data);
    if Assigned(xmlItem) then begin
      URL := xmlItem.ReadUnicodeString('link');
    end else begin
      URL := FUpdateChecker.BaseURL + 'timeline?r=' + URIEncode(FUpdateChecker.TagName);
    end;
................................................................................
  end;
  if URL <> '' then
    ShellExecute(Handle, nil, PChar(URL), nil, nil, SW_SHOW);
end {TfrmAutoUpdate.btnWebpageClick};






























end.


>







 







>
>













>
>
>
|









>









>
>
>







 







|












>
|







 







<





>



|
<
<
<
<
<
<
<
<
<
<
|

|
|


|


|







 







<








>
>
>







 







>
|
|
>
>
>
>
>
>












|
|
>







 







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







 







>


>


<


<










|







 







|







 







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

1
2
3
4
5
6
7
8
9
10
..
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
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226










227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
...
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
...
469
470
471
472
473
474
475
476
477
478
479
480
481

482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
...
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
unit F_AutoUpdate;

////////////////////////////////////////////////////////////////////////////////////////////////////
interface

uses
  System.SysUtils, System.Variants, System.Classes, System.Generics.Collections,
  System.Zip,
  Winapi.Windows, Winapi.Messages,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,
................................................................................
    function UUIDFromNode(const xmlItem: TXmlNode): string;
  public
    { Public declarations }
    procedure Populate(const UpdateChecker: TUpdateChecker);
  end;

  TUpdateChecker = class
  type
    TProgressDelegate = reference to procedure(Sender: TObject; Position: integer; MaxPos: integer);
  private
    FBaseURL: string;
    FTagName: string;
    FXmlFeed: TNativeXml;
    FVersions: TDictionary<TDateTime,TXmlNode>;
    FForm: TfrmAutoUpdate;

    procedure LoadFeed;
    function  DownloadFromURL(const URL: string): TStream;
  public
    constructor Create(const BaseURL, BranchName: string);
    destructor  Destroy; override;

    procedure ShowForm;
    procedure HideForm;

    function  CheckForUpdate(const UpdateProgress: TProgressDelegate = nil): boolean;
    function  AskUserForUpdate(out UUID: string): boolean;
    procedure UpdateToVersion(const UUID: string);

    property BaseURL: string                            read FBaseURL;
    property TagName: string                            read FTagName;
    property XmlFeed: TNativeXml                        read FXmlFeed;
    property Versions: TDictionary<TDateTime,TXmlNode>  read FVersions;
  end;

////////////////////////////////////////////////////////////////////////////////////////////////////
implementation
uses
  System.RegularExpressions, System.Types, System.IOUtils, System.UITypes, System.DateUtils,
  Winapi.ShellAPI, Winapi.WinInet,
  REST.Utils,
  L_VersionInfoW;

{$R *.dfm}

var
  CurrentExe, CurrentVersion: string;

{ ------------------------------------------------------------------------------------------------ }
// http://stackoverflow.com/a/8438985/3092116
function LinkerTimestamp: TDateTime; overload;
begin
  Result := PImageNtHeaders(HInstance + PImageDosHeader(HInstance)^._lfanew)^.FileHeader.TimeDateStamp / SecsPerDay + UnixDateDelta;
end {LinkerTimestamp};

................................................................................
      FreeAndNil(FXmlFeed);
      raise;
    end;
  end;
end {TUpdateChecker.LoadFeed};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.CheckForUpdate(const UpdateProgress: TProgressDelegate): boolean;
var
  en_US: TFormatSettings;
  rexDateTime: TRegEx;
  xmlChannel: TXmlNode;
  xmlItems: TList;
  i, mi: Integer;
  xmlItem: TXmlNode;
  sPubDate: string;
  PubDate: TDateTime;
  Match: TMatch;
  Day, Month, Year: Integer;
begin
  {$MESSAGE WARN 'TODO: If we have a form, then clear it to indicate we’re loading — MCO 12-08-2015'}
  LoadFeed{TODO: (UpdateProgress)};

  rexDateTime := TRegEx.Create('(\d{1,2})\s+(\w{2,})\s+(\d{4})\s+(\d?\d:\d\d:\d\d)', [roCompiled]);
  en_US := TFormatSettings.Create('en-US');

  Result := False;
  xmlChannel := FXmlFeed.Root.NodeByName('channel');
  xmlItems := TList.Create;
................................................................................
    FreeAndNil(FForm);
  end;
end {TUpdateChecker.AskUserForUpdate};

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

  WorkPath, PathPrefix, BackupPrefix: string;
  ZipStream: TStream;
  Zip: TZipFile;
  i: Integer;
  FileName, PathName: string;
  ExeWasReplaced: boolean;
  SI: TStartupInfo;
  PI: TProcessInformation;
begin
  ExeWasReplaced := False;










  WorkPath := ExtractFilePath(CurrentExe);
  BackupPrefix := '~';
  if CurrentVersion <> '' then
    BackupPrefix := BackupPrefix + CurrentVersion;

  // download the zip from http://fossil.2of4.net/zaap/zip/zpreview.zip?uuid={UUID}
  {$MESSAGE HINT 'TODO: Pass a routine to update the progress bar? — Martijn 2015-08-11'}
  ZipStream := DownloadFromURL(FBaseURL + 'zip/' + URIEncode(FTagName) + '.zip?uuid=' + URIEncode(UUID));
  if not Assigned(ZipStream) then
    raise Exception.Create('Failed to download release ' + UUID + ': ' + SysErrorMessage(GetLastError));
  try
    Zip := TZipFile.Create;
    try
      Zip.Open(ZipStream, zmRead);

      // extract each file, and try to rename an eventual existing file.
      PathPrefix := FTagName + '/';
................................................................................
        PathName := ExtractFilePath(FileName);
        FileName := ExtractFileName(FileName);
        if FileName <> '' then begin
          if PathName <> '' then
            ForceDirectories(WorkPath + PathName);

          // Test for existing file, and rename that

          if FileExists(WorkPath + PathName + FileName) then begin
            RenameFile(WorkPath + PathName + FileName, WorkPath + PathName + ChangeFileExt(FileName, BackupPrefix + ExtractFileExt(FileName)));
          end;

          Zip.Extract(i, WorkPath + PathName, False);

          // adjust the new file's modified time
          TFile.SetLastWriteTime(WorkPath + PathName + FileName, FileDateToDateTime(Zip.FileInfo[i].ModifiedDateTime));

          if SameFileName(ExtractFileName(CurrentExe), FileName) then
            ExeWasReplaced := True;
        end;
      end;

      // TODO: use transacted file operations, so we can roll them back if something fails?
    finally
      Zip.Free;
    end;
................................................................................
  // Close the current instance...
  Application.Tag := -1; // signal for the single-instance algorithm that we're shutting down
  Application.OnException := nil;
  Application.Terminate;
  Application.MainForm.Close;

  // ...and start a new one
  if ExeWasReplaced then begin
    if not CreateProcess(nil, PChar(CurrentExe), nil, nil, True, 0, nil, nil, SI, PI) then
      RaiseLastOSError;
  end else begin
    ShellExecute(Application.Handle, nil,
                  PChar('explorer.exe /select,"' + CurrentExe + '"'),
                  nil, PChar(WorkPath),
                  SW_SHOWDEFAULT);
  end;
end {TUpdateChecker.UpdateToVersion};

{ ------------------------------------------------------------------------------------------------ }
function TUpdateChecker.DownloadFromURL(const URL: string): TStream;
var
  UserAgent: string;
  NetHandle, UrlHandle: HINTERNET;
  Buffer: array[0..$400 - 1] of AnsiChar;
  BytesRead: cardinal;
begin
  Result := nil;

  UserAgent := ChangeFileExt(ExtractFileName(CurrentExe), '').Replace(' ', '');
  if CurrentVersion <> '' then
    UserAgent := UserAgent + '/' + CurrentVersion;
  NetHandle := InternetOpenW(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

  if not assigned(NetHandle) then begin
    // NetHandle is not valid.
//    DoDebugOut(Self, wsFail, 'Unable to initialize WinInet');
    exit;
  end;
................................................................................
    InternetCloseHandle(UrlHandle);

    Result.Position := 0;
  finally
    InternetCloseHandle(NetHandle);
  end;
end {TUpdateChecker.DownloadFromURL};

{ ------------------------------------------------------------------------------------------------ }
procedure TUpdateChecker.ShowForm;
begin
  {$MESSAGE WARN 'TUpdateChecker.ShowForm — MCO 12-08-2015'}
end {TUpdateChecker.ShowForm};

{ ------------------------------------------------------------------------------------------------ }
procedure TUpdateChecker.HideForm;
begin
  {$MESSAGE WARN 'TODO: TUpdateChecker.HideForm — MCO 12-08-2015'}
end {TUpdateChecker.HideForm};





{ ================================================================================================ }
{ TfrmAutoUpdate }
................................................................................
  xmlItem: TXmlNode;
begin
  if Selected = False then begin
    btnInstall.Enabled := False;
    btnWebpage.Enabled := False;
    mmoChanges.Clear;
  end else begin
    btnWebpage.Enabled := True;
    xmlItem := TXmlNode(Item.Data);
    if Assigned(xmlItem) then begin
      {$MESSAGE HINT 'TODO: Use a different control that enables links; replace UUIDs by links to FUpdateChecker.BaseURL + ‘info/<uuid>’ — MCO 12-08-2015'}
      mmoChanges.Lines.Text := xmlItem.ReadUnicodeString('description', '(no description provided)');
      btnInstall.Enabled := True;

    end else begin
      btnInstall.Enabled := False;

    end;
  end;
end {TfrmAutoUpdate.lvwVersionsSelectItem};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmAutoUpdate.btnInstallClick(Sender: TObject);
begin
  // Check if it's an older version
  if lvwVersions.Selected.GroupID = 1 then begin
    if TaskMessageDlg('Download and install an OLDER version?',
                      'You will overwrite the current version (' + CurrentVersion + ') of ZPreview with the following version:'#13#10 +
                        #13#10 +
                        lvwVersions.Selected.SubItems[1] + #13#10 +
                        #13#10 +
                        'Are you certain you want to do this?',
                      mtWarning, mbYesNo, 0, mbNo) <> mrYes then begin
      Self.ModalResult := mrNone;
    end;
................................................................................
procedure TfrmAutoUpdate.btnWebpageClick(Sender: TObject);
var
  UUID, URL: string;
  xmlItem: TXmlNode;
begin
  UUID := UUIDFromItem(lvwVersions.Selected);
  if UUID <> '' then begin
    URL := FUpdateChecker.BaseURL + 'dir?type=tree&ci=' + URIEncode(UUID);
  end else if Assigned(lvwVersions.Selected) then begin
    xmlItem := TXmlNode(lvwVersions.Selected.Data);
    if Assigned(xmlItem) then begin
      URL := xmlItem.ReadUnicodeString('link');
    end else begin
      URL := FUpdateChecker.BaseURL + 'timeline?r=' + URIEncode(FUpdateChecker.TagName);
    end;
................................................................................
  end;
  if URL <> '' then
    ShellExecute(Handle, nil, PChar(URL), nil, nil, SW_SHOW);
end {TfrmAutoUpdate.btnWebpageClick};





{ ------------------------------------------------------------------------------------------------ }
procedure ReadCurrentExeVersion;
begin
  try
    CurrentExe := ExpandFileName(ParamStr(0));
    with TFileVersionInfo.Create(CurrentExe) do begin
      try
        if HasVersionInfo then begin
          CurrentVersion := Format('%d.%d.%d.%d', [MajorVersion, MinorVersion, Revision, Build]);
        end;
      finally
        Free;
      end;
    end;
  except
    CurrentVersion := '';
  end;
end {ReadCurrentExeVersion};

////////////////////////////////////////////////////////////////////////////////////////////////////
initialization
  ReadCurrentExeVersion;

finalization

end.

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

75
76
77
78
79
80
81

82
83
84
85
86
87
88
var
  frmMain: TfrmMain;

implementation
uses
  System.IOUtils, System.Types, System.Masks, System.Generics.Defaults,
  Winapi.PsApi, Winapi.ShellAPI,

  Vcl.Imaging.GIFImg, Vcl.Imaging.jpeg, Vcl.Imaging.pngimage,
  U_ShellItemImage,
  F_Sentinel, F_Info, F_ManageEnginesAndRenderers, F_AutoUpdate;

{$R *.dfm}









>







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var
  frmMain: TfrmMain;

implementation
uses
  System.IOUtils, System.Types, System.Masks, System.Generics.Defaults,
  Winapi.PsApi, Winapi.ShellAPI,
  System.UITypes,
  Vcl.Imaging.GIFImg, Vcl.Imaging.jpeg, Vcl.Imaging.pngimage,
  U_ShellItemImage,
  F_Sentinel, F_Info, F_ManageEnginesAndRenderers, F_AutoUpdate;

{$R *.dfm}


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

115
116
117
118
119
120
121


122
123
124
125
126
127
128


129



130
131
132
133
134
135
136
...
158
159
160
161
162
163
164


165
166
167
168
169


170



171
172
173
174
175
176
177
  finally
    Reg.Free;
  end;
end {TTextRenderer.CouldShowFile};

{ ------------------------------------------------------------------------------------------------ }
function TTextRenderer.TryShowFile(const FileName: string): boolean;


begin
  with TfrmPEText(Form).rtePreview do begin
    Lines.BeginUpdate;
    try
      Clear;
      PlainText := True;
      Font.Assign(FFont);


      Lines.LoadFromFile(FileName);



    finally
      Lines.EndUpdate;
    end;
  end;
  Result := True;
end {TTextRenderer.TryShowFile};

................................................................................
function TRichTextRenderer.CouldShowFile(const FileName: string): boolean;
begin
  Result := SameFileName(ExtractFileExt(FileName), '.rtf');
end {TRichTextRenderer.CouldShowFile};

{ ------------------------------------------------------------------------------------------------ }
function TRichTextRenderer.TryShowFile(const FileName: string): boolean;


begin
  with TfrmPEText(Form).rtePreview do begin
    Lines.BeginUpdate;
    try
      PlainText := False;


      Lines.LoadFromFile(FileName);



    finally
      Lines.EndUpdate;
    end;
  end;
  Result := True;
end {TRichTextRenderer.TryShowFile};








>
>







>
>
|
>
>
>







 







>
>





>
>
|
>
>
>







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
165
166
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
  finally
    Reg.Free;
  end;
end {TTextRenderer.CouldShowFile};

{ ------------------------------------------------------------------------------------------------ }
function TTextRenderer.TryShowFile(const FileName: string): boolean;
var
  FS: TStream;
begin
  with TfrmPEText(Form).rtePreview do begin
    Lines.BeginUpdate;
    try
      Clear;
      PlainText := True;
      Font.Assign(FFont);
      FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
      try
        Lines.LoadFromStream(FS);
      finally
        FS.Free;
      end;
    finally
      Lines.EndUpdate;
    end;
  end;
  Result := True;
end {TTextRenderer.TryShowFile};

................................................................................
function TRichTextRenderer.CouldShowFile(const FileName: string): boolean;
begin
  Result := SameFileName(ExtractFileExt(FileName), '.rtf');
end {TRichTextRenderer.CouldShowFile};

{ ------------------------------------------------------------------------------------------------ }
function TRichTextRenderer.TryShowFile(const FileName: string): boolean;
var
  FS: TStream;
begin
  with TfrmPEText(Form).rtePreview do begin
    Lines.BeginUpdate;
    try
      PlainText := False;
      FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
      try
        Lines.LoadFromStream(FS);
      finally
        FS.Free;
      end;
    finally
      Lines.EndUpdate;
    end;
  end;
  Result := True;
end {TRichTextRenderer.TryShowFile};

Changes to ZPreview/src/Delphi/ZPreview.dproj.

1
2
3
4
5
6
7
8
9
10
11
..
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
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208




209
210






211
212
213





214
215
216
217
218
219
220
...
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{714EC425-71E3-4F49-A810-1E4C75A098F2}</ProjectGuid>
        <ProjectVersion>18.0</ProjectVersion>
        <FrameworkType>VCL</FrameworkType>
        <MainSource>ZPreview.dpr</MainSource>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>3</TargetedPlatforms>
        <AppType>Application</AppType>
................................................................................
    </PropertyGroup>
    <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
        <Cfg_2>true</Cfg_2>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Base)'!=''">

        <OutputExt>32.exe</OutputExt>
        <DCC_SYMBOL_PLATFORM>false</DCC_SYMBOL_PLATFORM>
        <DCC_UNIT_PLATFORM>false</DCC_UNIT_PLATFORM>
        <VerInfo_Release>2</VerInfo_Release>
        <VerInfo_PreRelease>true</VerInfo_PreRelease>
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
        <VerInfo_Locale>1033</VerInfo_Locale>
        <DCC_UnitSearchPath>ZAAP;FreeImage;Plugins;Common;Common\NativeXml;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
        <Icon_MainIcon>ZPreview_Icon.ico</Icon_MainIcon>
        <DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)</DCC_Namespace>
        <Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
        <SanitizedProjectName>ZPreview</SanitizedProjectName>
        <VerInfo_Keys>CompanyName=Martijn Coppoolse;FileDescription=ZTreeWin Preview Assistant Application;FileVersion=1.0.2.0;InternalName=ZPreview;LegalCopyright=;LegalTrademarks=;OriginalFilename=ZPreview.exe;ProductName=ZPreview;ProductVersion=1.0;Comments=http://fossil.2of4.net/zaap/</VerInfo_Keys>
        <DCC_DcuOutput>..\..\out\.dcu\$(Platform)\$(Config)</DCC_DcuOutput>
        <DCC_ExeOutput>..\..\out\$(Config)</DCC_ExeOutput>
        <DCC_E>false</DCC_E>
        <DCC_N>false</DCC_N>
        <DCC_S>false</DCC_S>
        <DCC_F>false</DCC_F>
        <DCC_K>false</DCC_K>
................................................................................
                    <VersionInfoKeys Name="restoreAnyVersion"/>
                    <VersionInfoKeys Name="installLocation"/>
                    <VersionInfoKeys Name="largeHeap"/>
                    <VersionInfoKeys Name="theme"/>
                </VersionInfoKeys>
            </Delphi.Personality>
            <Deployment Version="2">
                <DeployFile LocalName="Win32\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="..\..\out\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="Win32\Debug\ZPreview.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="ProjectiOSDeviceResourceRules">




                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>






                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>





                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\MacOS</RemoteDir>
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSSimulator">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>



|







 







>












|







 







|











|





|
>
>
>
>


>
>
>
>
>
>



>
>
>
>
>







 







|
<
<
<
<


<
<
<
<
<
<



<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
..
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
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
...
576
577
578
579
580
581
582
583




584
585






586
587
588





589
590
591
592
593
594
595
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{714EC425-71E3-4F49-A810-1E4C75A098F2}</ProjectGuid>
        <ProjectVersion>18.1</ProjectVersion>
        <FrameworkType>VCL</FrameworkType>
        <MainSource>ZPreview.dpr</MainSource>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Debug</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>3</TargetedPlatforms>
        <AppType>Application</AppType>
................................................................................
    </PropertyGroup>
    <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
        <Cfg_2>true</Cfg_2>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Base)'!=''">
        <VerInfo_Build>1</VerInfo_Build>
        <OutputExt>32.exe</OutputExt>
        <DCC_SYMBOL_PLATFORM>false</DCC_SYMBOL_PLATFORM>
        <DCC_UNIT_PLATFORM>false</DCC_UNIT_PLATFORM>
        <VerInfo_Release>2</VerInfo_Release>
        <VerInfo_PreRelease>true</VerInfo_PreRelease>
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
        <VerInfo_Locale>1033</VerInfo_Locale>
        <DCC_UnitSearchPath>ZAAP;FreeImage;Plugins;Common;Common\NativeXml;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
        <Icon_MainIcon>ZPreview_Icon.ico</Icon_MainIcon>
        <DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)</DCC_Namespace>
        <Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
        <SanitizedProjectName>ZPreview</SanitizedProjectName>
        <VerInfo_Keys>CompanyName=Martijn Coppoolse;FileDescription=ZTreeWin Preview Assistant Application;FileVersion=1.0.2.1;InternalName=ZPreview;LegalCopyright=;LegalTrademarks=;OriginalFilename=ZPreview.exe;ProductName=ZPreview;ProductVersion=1.0;Comments=http://fossil.2of4.net/zaap/</VerInfo_Keys>
        <DCC_DcuOutput>..\..\out\.dcu\$(Platform)\$(Config)</DCC_DcuOutput>
        <DCC_ExeOutput>..\..\out\$(Config)</DCC_ExeOutput>
        <DCC_E>false</DCC_E>
        <DCC_N>false</DCC_N>
        <DCC_S>false</DCC_S>
        <DCC_F>false</DCC_F>
        <DCC_K>false</DCC_K>
................................................................................
                    <VersionInfoKeys Name="restoreAnyVersion"/>
                    <VersionInfoKeys Name="installLocation"/>
                    <VersionInfoKeys Name="largeHeap"/>
                    <VersionInfoKeys Name="theme"/>
                </VersionInfoKeys>
            </Delphi.Personality>
            <Deployment Version="2">
                <DeployFile LocalName="Win32\Debug\ZPreview.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="..\..\out\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployFile LocalName="Win32\Debug\ZPreview.32.exe" Configuration="Debug" Class="ProjectOutput">
                    <Platform Name="Win32">
                        <RemoteName>ZPreview.exe</RemoteName>
                        <Overwrite>true</Overwrite>
                    </Platform>
                </DeployFile>
                <DeployClass Name="DependencyModule">
                    <Platform Name="Win32">
                        <Operation>0</Operation>
                        <Extensions>.dll;.bpl</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\MacOS</RemoteDir>
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                    <Platform Name="iOSSimulator">
                        <Operation>1</Operation>
                        <Extensions>.dylib</Extensions>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectOSXResource">
                    <Platform Name="OSX32">
                        <RemoteDir>Contents\Resources</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
................................................................................
                </DeployClass>
                <DeployClass Name="Android_LauncherIcon36">
                    <Platform Name="Android">
                        <RemoteDir>res\drawable-ldpi</RemoteDir>
                        <Operation>1</Operation>
                    </Platform>
                </DeployClass>
                <DeployClass Name="ProjectiOSDeviceResourceRules">




                    <Platform Name="iOSDevice64">
                        <Operation>1</Operation>






                    </Platform>
                    <Platform Name="iOSDevice32">
                        <Operation>1</Operation>





                    </Platform>
                </DeployClass>
                <ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
                <ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
                <ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>