diff options
Diffstat (limited to 'NET/worlds/scape/PendingDrone.java')
| -rw-r--r-- | NET/worlds/scape/PendingDrone.java | 303 |
1 files changed, 303 insertions, 0 deletions
diff --git a/NET/worlds/scape/PendingDrone.java b/NET/worlds/scape/PendingDrone.java new file mode 100644 index 0000000..105851f --- /dev/null +++ b/NET/worlds/scape/PendingDrone.java @@ -0,0 +1,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) { + } + } +} |