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
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
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
237
238
239
240
241
242
243
244
245
246
247
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
273
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
|
package NET.worlds.scape;
import NET.worlds.core.Archive;
import NET.worlds.core.IniFile;
import NET.worlds.network.Cache;
import NET.worlds.network.CacheFile;
import NET.worlds.network.NetUpdate;
import NET.worlds.network.URL;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
public class PendingDrone {
static boolean doAvatarUpdates = true;
protected PosableDrone drone;
protected URL url;
protected boolean loaded;
static final boolean debug = false;
static {
doAvatarUpdates = IniFile.gamma().getIniInt("noAvUpdates", 0) == 0;
}
PendingDrone(PosableDrone _drone, URL _url) {
this.drone = _drone;
this.url = _url;
this.loaded = false;
}
public PosableDrone getDrone() {
return this.drone;
}
public URL getUrl() {
return this.url;
}
public boolean getLoaded() {
return this.loaded;
}
public void setLoaded() {
this.loaded = true;
}
public synchronized void download(URL avURL) {
if (doAvatarUpdates) {
if (avURL != null) {
try {
if (PosableDroneLoader.avatarExistsLocally(avURL)) {
return;
}
} catch (MalformedURLException var5) {
return;
}
String s = PosableDroneLoader.getAvatarBaseName(avURL);
assert s != null;
s = s.toLowerCase();
URL realFile = URL.make(NetUpdate.getUpgradeServerURL() + "AvatarUpgrades/" + s + ".zip");
CacheFile cf = Cache.getFile(realFile);
cf.waitUntilLoaded();
if (!cf.error()) {
this.finishDownload(cf.getLocalName());
cf.close();
}
}
}
}
public synchronized boolean finishDownload(String localName) {
ZipFile patchArchive;
try {
patchArchive = new ZipFile(localName);
} catch (IOException var11) {
this.notify();
return false;
}
Enumeration enums = patchArchive.entries();
while (enums.hasMoreElements()) {
ZipEntry ze = (ZipEntry)enums.nextElement();
String filename = ze.getName();
String avatarFile = URL.homeUnalias("avatars/" + filename);
String[] validExtensions = new String[]{".bod", ".seq", ".dat", ".cmp", ".mov"};
boolean validFile = false;
for (int idx = 0; idx < validExtensions.length; idx++) {
if (avatarFile.toString().endsWith(validExtensions[idx])) {
validFile = true;
break;
}
}
if (validFile) {
if (avatarFile.toString().endsWith("avatars.dat")) {
avatarFile = URL.homeUnalias("avatars/avatars.tmp");
this.CopyAvatarFile(patchArchive, ze, avatarFile);
this.AppendAvatarsDat();
} else {
this.CopyAvatarFile(patchArchive, ze, avatarFile);
}
}
}
try {
patchArchive.close();
} catch (IOException var10) {
}
this.notify();
return false;
}
public Room getBackgroundLoadRoom() {
return this.drone != null && this.drone.getOwner() != null ? this.drone.getOwner().getRoom() : null;
}
private void AppendAvatarsDat() {
String contentZip = URL.homeUnalias("avatars/content.zip");
Archive.flushAll();
ZipFile contentZipArchive;
try {
contentZipArchive = new ZipFile(contentZip);
} catch (IOException var12) {
contentZipArchive = null;
}
if (contentZipArchive != null) {
ZipEntry origAvatarDat = contentZipArchive.getEntry("avatars.dat");
if (origAvatarDat != null) {
this.CopyAvatarFile(contentZipArchive, origAvatarDat, URL.homeUnalias("avatars/avatars.dat"));
this.StripAvatarDat(contentZipArchive);
} else {
try {
contentZipArchive.close();
} catch (IOException var11) {
}
}
}
FileOutputStream avDat;
try {
avDat = new FileOutputStream(URL.homeUnalias("avatars/avatars.dat"), true);
} catch (IOException var10) {
System.out.println(var10);
return;
}
FileInputStream avTmp;
try {
avTmp = new FileInputStream(URL.homeUnalias("avatars/avatars.tmp"));
} catch (FileNotFoundException var9) {
try {
avDat.close();
} catch (IOException var7) {
}
return;
}
byte[] buf = new byte[1024];
while (true) {
try {
int bytesRead = avTmp.read(buf);
if (bytesRead == -1) {
break;
}
avDat.write(buf, 0, bytesRead);
} catch (IOException var13) {
break;
}
}
try {
avDat.close();
avTmp.close();
} catch (IOException var8) {
}
File avTmpFile = new File(URL.homeUnalias("avatars/avatars.tmp"));
avTmpFile.delete();
DroneAnimator.loadconfig(URL.make("home:avatars/avatars.dat").unalias());
}
private void StripAvatarDat(ZipFile contentZipArchive) {
FileOutputStream os;
try {
os = new FileOutputStream(URL.homeUnalias("avatars/content.tmp"));
} catch (IOException var13) {
return;
}
ZipOutputStream zs = new ZipOutputStream(os);
Enumeration enums = contentZipArchive.entries();
while (enums.hasMoreElements()) {
ZipEntry ze = (ZipEntry)enums.nextElement();
String filename = ze.getName();
if (!filename.equals("avatars.dat")) {
try {
InputStream is = contentZipArchive.getInputStream(ze);
ZipEntry ze2 = new ZipEntry(ze.getName());
zs.putNextEntry(ze2);
byte[] buffer = new byte[1024];
while (true) {
try {
int bytesRead = is.read(buffer);
if (bytesRead != -1) {
zs.write(buffer, 0, bytesRead);
continue;
}
} catch (IOException var14) {
System.out.println("IOException " + ze.getName() + " " + var14.getMessage());
}
zs.closeEntry();
is.close();
break;
}
} catch (IOException var15) {
System.out.println("IOException 2 " + var15.getMessage());
}
}
}
try {
contentZipArchive.close();
zs.close();
} catch (IOException var12) {
System.out.println("Error closing zip files " + var12);
}
File origFile = new File(URL.homeUnalias("avatars/content.zip"));
File newFile = new File(URL.homeUnalias("avatars/content.tmp"));
File oldFile = new File(URL.homeUnalias("avatars/content.old"));
Archive.flushAll();
try {
boolean b = origFile.renameTo(oldFile);
b = newFile.renameTo(origFile);
} catch (Exception var11) {
System.out.println(var11);
}
}
private void CopyAvatarFile(ZipFile patchArchive, ZipEntry ze, String avatarFile) {
InputStream is;
try {
is = patchArchive.getInputStream(ze);
} catch (IOException var11) {
return;
}
FileOutputStream os;
try {
os = new FileOutputStream(avatarFile);
} catch (IOException var10) {
try {
is.close();
} catch (IOException var8) {
}
return;
}
byte[] buffer = new byte[1024];
while (true) {
try {
int bytesRead = is.read(buffer);
if (bytesRead == -1) {
break;
}
os.write(buffer, 0, bytesRead);
} catch (IOException var12) {
break;
}
}
try {
is.close();
os.close();
} catch (IOException var9) {
}
}
}
|