-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbonsaiInstaller.simba
164 lines (141 loc) · 6.13 KB
/
bonsaiInstaller.simba
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
122
123
124
125
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
155
156
157
158
159
160
161
162
163
164
{_____________________________________________________________________}
{=====================================================================}
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
{ bonsaiInstaller.simba }
{ Written by: bonsai }
{ Date Last Modified: 2014/09 }
{_____________________________________________________________________}
{=====================================================================}
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
program bonsaiInstaller;
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
const
blBitmapCodeUrl = 'http://pastebin.com/raw/RwkfJn1C';
blBreakCodeUrl = 'http://pastebin.com/raw/=XPiz7BJ5';
blColorizerCodeUrl = 'http://pastebin.com/raw/kxU0Dcvn';
blCombatCodeUrl = 'http://pastebin.com/raw/wuYUh3i8';
blMiscCodeUrl = 'http://pastebin.com/raw/PCmzxGRT';
blNpcCodeUrl = 'http://pastebin.com/raw/9kYFFLAU';
blTrackerCodeUrl = 'http://pastebin.com/raw/Fm7xWtHe';
blUpdaterCodeUrl = 'http://pastebin.com/raw/UM7XpgZQ';
fighterUrl = 'http://pastebin.com/raw/wR7FhHib';
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
type
Tupdater = record
wereUpdatesPerformed : boolean;
end;
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
var
updater: Tupdater;
{¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯}
procedure Tupdater.die(s: string);
begin
writeln('*******************************************************');
writeln('***** FATAL ERROR: ', s);
writeln('*******************************************************');
terminateScript();
end;
procedure Tupdater.header(s: string);
begin
writeln('-------------------------------------------------------');
writeln('-- ', s);
end;
procedure Tupdater.msg(s: string);
begin
writeln('-- ', s);
end;
function Tupdater.rename(oldName: string; newName: string; delIfExists: boolean = true): boolean;
var
inFile, outFile, fsize: integer;
s: string;
begin
if (FileExists(newName)) then
begin
if (not delIfExists) then
self.die('File already exists, could not rename ' + oldName + ' to ' + newName);
self.msg('removing file ' + newName);
result := DeleteFile(newName);
if (not result) then
self.die('Error deleting ' + newName);
end;
inFile := OpenFile(oldName, false);
if (inFile = -1) then
self.die('Error opening ' + oldName + ' for reading.');
outfile := RewriteFile(newName, false);
if (outFile = -1) then
self.die('Error opening ' + newName + ' for writing.');
fsize := FileSize(inFile);
result := ReadFileString(inFile, s, fsize);
if (not result) then
self.die('Error reading from ' + oldName);
result := WriteFileString(outFile, s);
if (not result) then
self.die('Error writing to ' + newName);
CloseFile(inFile);
CloseFile(outFile);
result := true;
end;
function Tupdater.createIncludeFolder(dname: string): boolean
begin
self.header('Checking for ' + dname + ' include folder:');
if (DirectoryExists(includePath + dname)) then
begin
self.msg('include folder already exists, no change made');
result := true;
end
else
begin
result := CreateDirectory(includePath + dname);
if (result) then
self.msg('created include folder ' + includePath + dname)
else
self.die('Could not create directory ' + includePath + dname);
end;
end;
function Tupdater.download(fname: string; url: string; isLib: boolean = false): boolean;
var
fullPath, contents: string;
outFile: integer;
begin
self.header('Installing latest ' + fname);
if (isLib) then
fullPath := includePath + 'bonsai\' + fname
else
fullPath := appPath + 'Scripts\' + fname;
if (FileExists(fullPath)) then
begin
self.msg('file ' + fullPath + ' already exists, renaming to .bak');
self.rename(fullPath, fullPath + '.bak');
end;
contents := GetPage(url);
if (contents = '') then
self.die('Could not load new script contents from ' + url);
outfile := RewriteFile(fullPath, false);
if (outFile = -1) then
self.die('Error opening ' + fullPath + ' for writing.');
if (WriteFileString(outFile, contents)) then
self.msg('Script ' + fullPath + ' has been updated')
else
self.die('Error writing new contents to ' + fullPath);
CloseFile(outFile);
result := true;
end;
begin
updater.header('Installing bonsaiFighter');
updater.createIncludeFolder('bonsai');
updater.createIncludeFolder('bonsai\colors');
updater.download('blBitmap.simba', blBitmapCodeUrl, true);
updater.download('blBreak.simba', blBreakCodeUrl, true);
updater.download('blColorizer.simba', blColorizerCodeUrl, true);
updater.download('blCombat.simba', blCombatCodeUrl, true);
updater.download('blMisc.simba', blMiscCodeUrl, true);
updater.download('blNpc.simba', blNpcCodeUrl, true);
updater.download('blTracker.simba', blTrackerCodeUrl, true);
updater.download('blUpdater.simba', blUpdaterCodeUrl, true);
updater.download('bonsaiFighter.simba', fighterUrl, false);
updater.header('Install Completed');
writeln('-------------------------------------------------------');
// self destruct on the way out
if (FileExists(appPath + 'Scripts\bonsaiInstaller.simba')) then
DeleteFile(appPath + 'Scripts\bonsaiInstaller.simba');
end.