/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.core.Std; /* */ import NET.worlds.network.ProgressDialog; /* */ import NET.worlds.network.URL; /* */ import java.io.FileOutputStream; /* */ import java.io.IOException; /* */ import java.io.InputStream; /* */ import java.io.PrintStream; /* */ import java.util.Enumeration; /* */ import java.util.Vector; /* */ import java.util.zip.ZipEntry; /* */ import java.util.zip.ZipFile; /* */ /* */ /* */ /* */ /* */ public class LanguageManager /* */ implements Runnable /* */ { /* */ private String m_Name; /* */ private String m_FinishName; /* */ private int m_fSize; /* */ /* */ public static void handle(String name, int fSize, String finishName) /* */ { /* 27 */ LanguageManager lm = new LanguageManager(name, fSize, finishName); /* 28 */ Thread t = new Thread(lm); /* 29 */ t.setDaemon(true); /* 30 */ t.start(); /* */ } /* */ /* */ /* */ /* */ public LanguageManager(String name, int fSize, String finishName) /* */ { /* 37 */ this.m_Name = name; /* 38 */ this.m_fSize = fSize; /* 39 */ this.m_FinishName = finishName; /* */ } /* */ /* */ public void run() { /* 43 */ String fName = this.m_Name.substring(this.m_Name.lastIndexOf('/') + 1, /* 44 */ this.m_Name.length()); /* */ /* 46 */ Console.println(Console.message("Downloading-update") + fName); /* */ /* */ /* */ /* 50 */ Vector names = new Vector(); /* 51 */ names.addElement(fName); /* 52 */ Vector urls = new Vector(); /* 53 */ urls.addElement(URL.make(this.m_Name)); /* 54 */ int now = Std.getFastTime(); /* */ /* 56 */ ProgressDialog progD = new ProgressDialog(this.m_fSize); /* */ try /* */ { /* 59 */ System.out.println("ProgressDialog start, now = " + now); /* 60 */ System.out.println("fName = " + fName + ", name = " + this.m_Name); /* */ /* */ /* 63 */ if (!progD.loadFiles(names, urls)) { /* 64 */ System.out.println("Can't load " + fName); /* 65 */ return; /* */ } /* 67 */ now = Std.getFastTime(); /* 68 */ System.out.println("ProgressDialog end, now = " + now); /* */ } /* */ catch (IOException e) { /* 71 */ System.out.println("Exception " + e.toString() + " loading file " + /* 72 */ fName); /* */ } /* */ /* 75 */ finishDownload(this.m_FinishName); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public synchronized boolean finishDownload(String localName) /* */ { /* 98 */ String fType = localName.substring(localName.lastIndexOf('.'), /* 99 */ localName.length()); /* */ /* 101 */ System.out.println("Finished Downloading " + localName); /* 102 */ if (fType.equals(".EXE")) { /* 103 */ if (tryToRun(localName)) { /* 104 */ System.out.println(Console.message("Loading2") + localName); /* */ } else /* 106 */ Console.println( /* 107 */ Console.message("Loading2") + localName + " " + Console.message("failed")); /* 108 */ } else if (fType.equals(".zip")) /* */ { /* */ /* */ try /* */ { /* */ /* 114 */ langZip = new ZipFile(localName); /* */ } catch (IOException e) { ZipFile langZip; /* 116 */ System.out.println("Error opening language file " + localName); /* 117 */ notify(); /* 118 */ return false; /* */ } /* */ ZipFile langZip; /* 121 */ System.out.println("Expanding language file."); /* */ /* 123 */ Enumeration enums = langZip.entries(); /* 124 */ while (enums.hasMoreElements()) { /* 125 */ ZipEntry ze = (ZipEntry)enums.nextElement(); /* 126 */ String filename = ze.getName(); /* */ /* 128 */ String langFile = filename; /* */ /* 130 */ String[] validExtensions = { ".properties", ".jpg", ".bmp", /* 131 */ ".gif" }; /* */ /* 133 */ boolean validFile = false; /* 134 */ for (int idx = 0; idx < validExtensions.length; idx++) { /* 135 */ if (langFile.toString().endsWith(validExtensions[idx])) { /* 136 */ validFile = true; /* 137 */ break; /* */ } /* */ } /* */ /* 141 */ if (validFile) { /* 142 */ CopyLangFile(langZip, ze, langFile); /* 143 */ System.out.println(langFile); /* */ } /* */ } /* */ /* */ try /* */ { /* 149 */ langZip.close(); /* */ } /* */ catch (IOException localIOException1) {} /* */ } /* 153 */ notify(); /* */ /* 155 */ new OkCancelDialog(Console.getFrame(), null, Console.message("Alert"), /* 156 */ null, Console.message("OK"), Console.message("Change-exit"), /* 157 */ true); /* */ /* 159 */ return false; /* */ } /* */ /* */ private void CopyLangFile(ZipFile langZip, ZipEntry ze, String langFile) /* */ { /* */ try /* */ { /* 166 */ is = langZip.getInputStream(ze); /* */ } catch (IOException e) { /* */ InputStream is; /* */ return; /* */ } /* */ InputStream is; /* */ try { /* 173 */ os = new FileOutputStream(langFile); /* */ } catch (IOException e) { /* */ try { FileOutputStream os; /* 176 */ is.close(); /* */ } /* */ catch (IOException localIOException1) {} /* */ /* */ return; /* */ } /* */ FileOutputStream os; /* 183 */ byte[] buffer = new byte['Ѐ']; /* */ try /* */ { /* */ for (;;) { /* 187 */ int bytesRead = is.read(buffer); /* 188 */ if (bytesRead == -1) { /* */ break; /* */ } /* 191 */ os.write(buffer, 0, bytesRead); /* */ } /* */ return; /* */ } /* */ catch (IOException localIOException2) /* */ { /* */ try /* */ { /* 199 */ is.close(); /* 200 */ os.close(); /* */ } /* */ catch (IOException localIOException3) {} /* */ } /* */ } /* */ /* */ public static boolean tryToRun(String s) { /* */ try { /* 208 */ Runtime.getRuntime().exec(s); /* 209 */ return true; /* */ } catch (IOException e) {} /* 211 */ return false; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\LanguageManager.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */