summaryrefslogtreecommitdiff
path: root/NET/worlds/console/LanguageManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/console/LanguageManager.java')
-rw-r--r--NET/worlds/console/LanguageManager.java163
1 files changed, 163 insertions, 0 deletions
diff --git a/NET/worlds/console/LanguageManager.java b/NET/worlds/console/LanguageManager.java
new file mode 100644
index 0000000..c8fe072
--- /dev/null
+++ b/NET/worlds/console/LanguageManager.java
@@ -0,0 +1,163 @@
+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.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) {
+ LanguageManager lm = new LanguageManager(name, fSize, finishName);
+ Thread t = new Thread(lm);
+ t.setDaemon(true);
+ t.start();
+ }
+
+ public LanguageManager(String name, int fSize, String finishName) {
+ this.m_Name = name;
+ this.m_fSize = fSize;
+ this.m_FinishName = finishName;
+ }
+
+ @Override
+ public void run() {
+ String fName = this.m_Name.substring(this.m_Name.lastIndexOf(47) + 1, this.m_Name.length());
+ Console.println(Console.message("Downloading-update") + fName);
+ Vector<String> names = new Vector<String>();
+ names.addElement(fName);
+ Vector<URL> urls = new Vector<URL>();
+ urls.addElement(URL.make(this.m_Name));
+ int now = Std.getFastTime();
+ ProgressDialog progD = new ProgressDialog(this.m_fSize);
+
+ try {
+ System.out.println("ProgressDialog start, now = " + now);
+ System.out.println("fName = " + fName + ", name = " + this.m_Name);
+ if (!progD.loadFiles(names, urls)) {
+ System.out.println("Can't load " + fName);
+ return;
+ }
+
+ now = Std.getFastTime();
+ System.out.println("ProgressDialog end, now = " + now);
+ } catch (IOException var7) {
+ System.out.println("Exception " + var7.toString() + " loading file " + fName);
+ }
+
+ this.finishDownload(this.m_FinishName);
+ }
+
+ public synchronized boolean finishDownload(String localName) {
+ String fType = localName.substring(localName.lastIndexOf(46), localName.length());
+ System.out.println("Finished Downloading " + localName);
+ if (fType.equals(".EXE")) {
+ if (tryToRun(localName)) {
+ System.out.println(Console.message("Loading2") + localName);
+ } else {
+ Console.println(Console.message("Loading2") + localName + " " + Console.message("failed"));
+ }
+ } else if (fType.equals(".zip")) {
+ ZipFile langZip;
+ try {
+ langZip = new ZipFile(localName);
+ } catch (IOException var12) {
+ System.out.println("Error opening language file " + localName);
+ this.notify();
+ return false;
+ }
+
+ System.out.println("Expanding language file.");
+ Enumeration<? extends ZipEntry> enums = langZip.entries();
+
+ while (enums.hasMoreElements()) {
+ ZipEntry ze = enums.nextElement();
+ String filename = ze.getName();
+ String langFile = filename;
+ String[] validExtensions = new String[]{".properties", ".jpg", ".bmp", ".gif"};
+ boolean validFile = false;
+
+ for (int idx = 0; idx < validExtensions.length; idx++) {
+ if (langFile.toString().endsWith(validExtensions[idx])) {
+ validFile = true;
+ break;
+ }
+ }
+
+ if (validFile) {
+ this.CopyLangFile(langZip, ze, langFile);
+ System.out.println(langFile);
+ }
+ }
+
+ try {
+ langZip.close();
+ } catch (IOException var11) {
+ }
+ }
+
+ this.notify();
+ new OkCancelDialog(Console.getFrame(), null, Console.message("Alert"), null, Console.message("OK"), Console.message("Change-exit"), true);
+ return false;
+ }
+
+ private void CopyLangFile(ZipFile langZip, ZipEntry ze, String langFile) {
+ InputStream is;
+ try {
+ is = langZip.getInputStream(ze);
+ } catch (IOException var11) {
+ return;
+ }
+
+ FileOutputStream os;
+ try {
+ os = new FileOutputStream(langFile);
+ } 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) {
+ }
+ }
+
+ public static boolean tryToRun(String s) {
+ try {
+ Runtime.getRuntime().exec(s);
+ return true;
+ } catch (IOException var2) {
+ return false;
+ }
+ }
+}