-
Notifications
You must be signed in to change notification settings - Fork 3
/
CallBackes.pas
111 lines (106 loc) · 3.17 KB
/
CallBackes.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
unit CallBackes;
interface
uses
Windows, ShellAPI, SysUtils, Global;
procedure DownloadComplete(
const
aParameter : TParameter
);
implementation
uses Main, Crc32, Fetcher, PListParser, ConfigParser, Ass_Lib, fusion;
//Active when file is downloaded
procedure DownloadComplete(
const
aParameter : TParameter
);
var
FileName:String;
begin
case aParameter.aType of
//If just main file..
PMain: begin
//Load Config from stream, LoadIndex should able to handle
//all errors
Config.LoadIndex(aParameter.aData);
//Force playable?
if (Config.OpBit and 1)>0 then
begin
MainSwitch(SSuccess);
end else
if not Config.Policy then
begin
//Denied
MainSwitch(SError, Config.PolicyMSG);
end else
begin
//Begin to fetch filelist
TFetcher.Create(Config.PatchList, PList, DownloadComplete);
end;
end;
//Finish downloading patch list?
PList: begin
PatchList.Load(aParameter.aData);
//this shouldn't happen! uhm..runing using wine in LINUX?
if not FileExists(AppFull) then
begin
MainSwitch(SError, 'Unexpected Fatal error. 0x000001');
end else
// check patcher's checksum first!!!
// if (Config.PatcherSum <> '') and (IntToHex(GetFileCrc32(AppFull), 8) <> Config.PatcherSum) then
// begin
// Status('Updating Patcher');
// MainFrm.CancelBTN.Enabled := True;
// LockedDown := False;
// TFetcher.Create(Config.PatcherURL, PCFILE, DownloadComplete, CPatcher);
// end else
// if client not exists then just redownload!
// if (Config.ClientSum <> '') and not FileExists(ClientFile) then
// begin
// Status('Updating Client');
// MainFrm.CancelBTN.Enabled := True;
// LockedDown := False;
// TFetcher.Create(Config.ClientURL, PCFILE, DownloadComplete, CClient);
// end else
// if (Config.ClientSum <> '') and (IntToHex(GetFileCrc32(AppPath + ClientFile), 8)<>Config.ClientSum) then
// begin
// Status('Updating Client');
// MainFrm.CancelBTN.Enabled := True;
// LockedDown := False;
// TFetcher.Create(Config.ClientURL, PCFILE, DownloadComplete, CClient);
// end else
PatchList.GetNext;
end;
PCFILE: begin
case aParameter.ID of
CPatcher: begin
if FileExists(ExtractFilePath(AppFull) + 'tmp.exe') and LockedFile(ExtractFilePath(AppFull) + 'tmp.exe')then
MainSwitch(SError, 'Unexpected Fatal error. 0x000002')
else begin
aParameter.aData.SaveToFile(ExtractFilePath(AppFull) + 'tmp.exe');
ShellExecute(0, 'open', PChar(ExtractFilePath(AppFull) + 'tmp.exe'), Pchar('@idunno "' + AppName +'"'), nil, SW_SHOWNORMAL);
PostMessage(MainFrm.Handle,TH_MESSAGE, 0 ,0);
end;
end;
CClient : begin
if FileExists(AppPath + ClientFile) and LockedFile(AppPath + ClientFile)then
MainSwitch(SError, 'Client Application is locked')
else begin
aParameter.aData.SaveToFile(AppPath + ClientFile);
PatchList.GetNext;
end;
end;
end;
end;
//and patch file
PFile: begin
FileName := 'tmp'+IntToStr(aParameter.ID)+'.ass';
aParameter.aData.SaveToFile(FileName); //save to temp file
if AssFusion(FileName) then //Oh..okay...fusioned!!! next~
begin
Inc(CurrentID);
PatchList.GetNext;
end;
end;
end;
end;
end.