summaryrefslogtreecommitdiff
path: root/NET/worlds/console/LanguageManager.java
blob: fe6977d9920dbec8c81178fd3ba051c1abea4b4b (plain) (blame)
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
/*     */ 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<String> names = new Vector();
/*  51 */     names.addElement(fName);
/*  52 */     Vector<URL> 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<? extends ZipEntry> 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
 */