From c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 12 Feb 2026 22:33:32 -0800 Subject: Initial commit --- NET/worlds/console/LanguageManager.java | 163 ++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 NET/worlds/console/LanguageManager.java (limited to 'NET/worlds/console/LanguageManager.java') 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 names = new Vector(); + names.addElement(fName); + Vector urls = new Vector(); + 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 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; + } + } +} -- cgit v1.2.3