-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.pas
121 lines (105 loc) · 2.88 KB
/
Main.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
117
118
119
120
121
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, pngimage, ExtCtrls, StdCtrls, CommandoSettings, UpdateInfo,
ASyncPatcher;
type
TPatcherForm = class(TForm)
Progress: TProgressBar;
Image1: TImage;
Log: TMemo;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
FSettings: TCommandoSettings;
FUpdates: TUpdateInfo;
FPatcher: TAsyncPatcher;
FRunning: Boolean;
procedure HandleTerminate(Sender: TObject);
procedure HandleLog(AMessage: string);
procedure HandleProgress(AMin, AMax, APosition: Integer);
protected
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
end;
var
PatcherForm: TPatcherForm;
implementation
uses
VersionCompare, PatcherVersion;
{$R *.dfm}
{$R StarterManifest.res}
{ TPatcherForm }
constructor TPatcherForm.Create(AOwner: TComponent);
begin
inherited;
FUpdates := TUpdateInfo.Create();
FSettings := TCommandoSettings.Create();
FPatcher := TAsyncPatcher.Create(FSettings, FUpdates);
FPatcher.OnProgress := HandleProgress;
FPatcher.OnLog := HandleLog;
FPatcher.OnTerminate := HandleTerminate;
FSettings.ReadFromCommandLine();
Log.Lines.Add('D16Patcher v. ' + CPatcherVersion);
if FSettings.HasUpdateFile() then
begin
if not FSettings.IsSelfInstall then
begin
FUpdates.LoadFromFile(ExtractFilePath(Application.ExeName) + '\' + FSettings.UpdateFile);
end;
FRunning := True;
FPatcher.Start();
end
else
begin
Log.Lines.Add('No updatefile specified');
end;
end;
destructor TPatcherForm.Destroy;
begin
FSettings.Free();
FUpdates.Free;
inherited;
end;
procedure TPatcherForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := True;
if FRunning then
begin
if MessageDlg('Patcher is still performing an action. Do you really want to abort while patching?', mtWarning, mbYesNo, 0) = mrNo then
begin
CanClose := False;
end;
end;
end;
procedure TPatcherForm.HandleLog(AMessage: string);
begin
Log.Lines.Add(AMessage);
end;
procedure TPatcherForm.HandleProgress(AMin, AMax, APosition: Integer);
begin
//all the following +1 and backsetting forces the progressbar to update IMMEDIATELY instead of animating
if APosition < AMax then
begin
Progress.Min := AMin;
Progress.Max := AMax;
Progress.Position := APosition + 1;
Progress.Position := APosition;
end
else
begin
Progress.Min := AMin;
Progress.Max := AMax + 1;
Progress.Position := AMax + 1;
Progress.Max := AMax;
end;
end;
procedure TPatcherForm.HandleTerminate(Sender: TObject);
begin
FRunning := False;
Self.Close();
end;
end.