-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.pas
103 lines (87 loc) · 2.51 KB
/
update.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
unit update;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtActns;
type
TFUpdate = class(TForm)
MUpdateVerText: TMemo;
BUpdateVer: TButton;
BUpdateLater: TButton;
LUpdateVer: TLabel;
PBUpdate: TProgressBar;
LAction: TLabel;
procedure BUpdateLaterClick(Sender: TObject);
procedure BUpdateVerClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
function BetterDownloadFile(strRemoteFileName, strLocalFileName : string) : integer;
private
procedure URL_OnDownloadProgress
(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal;
StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean) ;
public
{ Public declarations }
Files : TStringList;
Dests : TStringList;
end;
var
FUpdate: TFUpdate;
implementation
uses SBMain;
{$R *.dfm}
procedure TFUpdate.URL_OnDownloadProgress;
begin
PBUpdate.Max:=ProgressMax;
PBUpdate.Position:=Progress;
end;
function TFUpdate.BetterDownloadFile(strRemoteFileName, strLocalFileName : string) : integer;
var res : integer;
begin
LAction.Caption:='Downloading '+strLocalFileName+'...';
LAction.Update;
res:=0;
if (FileExists('tmp.download')) then deletefile('tmp.download');
if (FileExists('tmp.replace')) then deletefile('tmp.replace');
with TDownloadURL.Create(self) do begin
try
URL:='https://www.teapotrecords.co.uk/bfree/Songbase/'+strRemoteFileName+'?d='+DateTimeToStr(Now);
FileName := 'tmp.download';
OnDownloadProgress := URL_OnDownloadProgress;
ExecuteTarget(nil);
except
res:=999
end;
Free;
end;
if (FileExists(strLocalFileName+'.preupdate')) then DeleteFile(strLocalFileName+'.preupdate');
RenameFile(strLocalFileName,strLocalFileName+'.preupdate');
RenameFile('tmp.download',strLocalFileName);
BetterDownloadFile:=res;
end;
procedure TFUpdate.BUpdateLaterClick(Sender: TObject);
begin
close;
end;
procedure TFUpdate.BUpdateVerClick(Sender: TObject);
var i : integer;
begin
BUpdateVer.Enabled:=false;
BUpdateLater.Enabled:=false;
BUpdateVer.Update;
BUpdateLater.Update;
for i:=0 to Files.Count-1 do begin
BetterDownloadFile(Files[i],Dests[i]);
end;
messagedlg('Update done - Songbase will now restart',mtInformation,[mbOk],0);
winexec('songbase.exe',SW_NORMAL);
close;
FSongbase.close;
end;
procedure TFUpdate.FormCreate(Sender: TObject);
begin
Files:=TStringList.Create;
Dests:=TStringList.Create;
end;
end.