summaryrefslogtreecommitdiff
path: root/NET/worlds/network/ProgressDialog.java
blob: 5454c96616c4cc203b719e3c8facb11b3ed3f39d (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*     */ package NET.worlds.network;
/*     */ 
/*     */ import NET.worlds.console.Console;
/*     */ import NET.worlds.console.GammaFrame;
/*     */ import NET.worlds.console.PolledDialog;
/*     */ import NET.worlds.core.Std;
/*     */ import java.awt.Event;
/*     */ import java.awt.GridBagConstraints;
/*     */ import java.awt.GridBagLayout;
/*     */ import java.awt.Insets;
/*     */ import java.awt.Label;
/*     */ import java.io.IOException;
/*     */ import java.text.MessageFormat;
/*     */ import java.text.NumberFormat;
/*     */ import java.util.Locale;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ProgressDialog
/*     */   extends PolledDialog
/*     */ {
/*     */   private static final long serialVersionUID = 7533646170494183110L;
/*  56 */   private static final String bytesMsg = Console.message("Bytes-remaining");
/*     */   private int bytesTotal;
/*     */   private int bytesLoaded;
/*     */   private ProgressBar progressBar;
/*     */   private Label progressBytes;
/*     */   private Label progressTime;
/*  62 */   private int startTime = Std.getFastTime();
/*     */   
/*     */   private CacheFile cf;
/*     */   
/*     */   private boolean cancelled;
/*  67 */   private int wholeFileBytes = 0;
/*     */   
/*     */   public ProgressDialog(int totalSize)
/*     */   {
/*  71 */     super(Console.getFrame(), null, Console.message("Download-Progress"), false);
/*  72 */     this.bytesTotal = totalSize;
/*  73 */     this.progressBar = new ProgressBar(240);
/*     */     
/*  75 */     NumberFormat nF = NumberFormat.getNumberInstance(Locale.getDefault());
/*  76 */     String strSize = nF.format(totalSize);
/*     */     
/*  78 */     this.progressBytes = new Label(bytesMsg + strSize);
/*  79 */     this.progressTime = new Label("");
/*  80 */     setAlignment(1);
/*     */     
/*     */ 
/*     */ 
/*  84 */     readySetGo();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean loadFiles(Vector<String> names, Vector<URL> urls)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/*  95 */       int count = names.size();
/*  96 */       for (int i = 0; i < count; i++) {
/*  97 */         synchronized (this) {
/*  98 */           if (this.cancelled) {
/*  99 */             NetUpdate.warnUser("Upgrade cancelled.");
/* 100 */             return false;
/*     */           }
/*     */           
/* 103 */           if (this.cf != null)
/* 104 */             this.wholeFileBytes += this.cf.bytesLoaded();
/* 105 */           this.cf = Cache.getFile((URL)urls.elementAt(i));
/*     */         }
/* 107 */         this.cf.waitUntilLoaded();
/*     */         
/* 109 */         if (!this.cf.isActive()) {
/* 110 */           this.cf.markTemporary();
/* 111 */           NetUpdate.warnUser("Upgrade cancelled.");
/* 112 */           return false; }
/* 113 */         if (this.cf.error()) {
/* 114 */           this.cf.markTemporary();
/*     */           
/* 116 */           NetUpdate.warnUser("Error getting upgrade info, try again later");
/* 117 */           return false;
/*     */         }
/*     */         
/*     */ 
/* 121 */         copyFile(this.cf.getLocalName(), (String)names.elementAt(i));
/*     */         
/* 123 */         this.cf.markTemporary();
/* 124 */         this.cf.close();
/*     */       }
/* 126 */       return true;
/*     */     } finally {
/* 128 */       done(true);
/*     */     }
/*     */   }
/*     */   
/*     */   /* Error */
/*     */   public static boolean copyFile(String from, String to)
/*     */   {
/*     */     // Byte code:
/*     */     //   0: aload_1
/*     */     //   1: bipush 47
/*     */     //   3: invokevirtual 205	java/lang/String:lastIndexOf	(I)I
/*     */     //   6: istore_2
/*     */     //   7: aload_1
/*     */     //   8: bipush 92
/*     */     //   10: invokevirtual 205	java/lang/String:lastIndexOf	(I)I
/*     */     //   13: istore_3
/*     */     //   14: iload_3
/*     */     //   15: iload_2
/*     */     //   16: if_icmple +5 -> 21
/*     */     //   19: iload_3
/*     */     //   20: istore_2
/*     */     //   21: iload_2
/*     */     //   22: iflt +20 -> 42
/*     */     //   25: new 209	java/io/File
/*     */     //   28: dup
/*     */     //   29: aload_1
/*     */     //   30: iconst_0
/*     */     //   31: iload_2
/*     */     //   32: invokevirtual 211	java/lang/String:substring	(II)Ljava/lang/String;
/*     */     //   35: invokespecial 215	java/io/File:<init>	(Ljava/lang/String;)V
/*     */     //   38: invokevirtual 216	java/io/File:mkdirs	()Z
/*     */     //   41: pop
/*     */     //   42: aconst_null
/*     */     //   43: astore 4
/*     */     //   45: aconst_null
/*     */     //   46: astore 5
/*     */     //   48: new 219	java/io/FileInputStream
/*     */     //   51: dup
/*     */     //   52: aload_0
/*     */     //   53: invokespecial 221	java/io/FileInputStream:<init>	(Ljava/lang/String;)V
/*     */     //   56: astore 4
/*     */     //   58: new 222	java/io/FileOutputStream
/*     */     //   61: dup
/*     */     //   62: aload_1
/*     */     //   63: invokespecial 224	java/io/FileOutputStream:<init>	(Ljava/lang/String;)V
/*     */     //   66: astore 5
/*     */     //   68: sipush 1024
/*     */     //   71: newarray <illegal type>
/*     */     //   73: astore 6
/*     */     //   75: aload 4
/*     */     //   77: aload 6
/*     */     //   79: invokevirtual 225	java/io/FileInputStream:read	([B)I
/*     */     //   82: istore 7
/*     */     //   84: iload 7
/*     */     //   86: iconst_m1
/*     */     //   87: if_icmpne +6 -> 93
/*     */     //   90: goto +41 -> 131
/*     */     //   93: aload 5
/*     */     //   95: aload 6
/*     */     //   97: iconst_0
/*     */     //   98: iload 7
/*     */     //   100: invokevirtual 229	java/io/FileOutputStream:write	([BII)V
/*     */     //   103: goto -28 -> 75
/*     */     //   106: astore 8
/*     */     //   108: aload 5
/*     */     //   110: ifnull +8 -> 118
/*     */     //   113: aload 5
/*     */     //   115: invokevirtual 233	java/io/FileOutputStream:close	()V
/*     */     //   118: aload 4
/*     */     //   120: ifnull +8 -> 128
/*     */     //   123: aload 4
/*     */     //   125: invokevirtual 234	java/io/FileInputStream:close	()V
/*     */     //   128: aload 8
/*     */     //   130: athrow
/*     */     //   131: aload 5
/*     */     //   133: ifnull +8 -> 141
/*     */     //   136: aload 5
/*     */     //   138: invokevirtual 233	java/io/FileOutputStream:close	()V
/*     */     //   141: aload 4
/*     */     //   143: ifnull +8 -> 151
/*     */     //   146: aload 4
/*     */     //   148: invokevirtual 234	java/io/FileInputStream:close	()V
/*     */     //   151: iconst_1
/*     */     //   152: ireturn
/*     */     //   153: astore 6
/*     */     //   155: iconst_0
/*     */     //   156: ireturn
/*     */     // Line number table:
/*     */     //   Java source line #138	-> byte code offset #0
/*     */     //   Java source line #139	-> byte code offset #7
/*     */     //   Java source line #140	-> byte code offset #14
/*     */     //   Java source line #141	-> byte code offset #19
/*     */     //   Java source line #142	-> byte code offset #21
/*     */     //   Java source line #143	-> byte code offset #25
/*     */     //   Java source line #145	-> byte code offset #42
/*     */     //   Java source line #146	-> byte code offset #45
/*     */     //   Java source line #149	-> byte code offset #48
/*     */     //   Java source line #150	-> byte code offset #58
/*     */     //   Java source line #151	-> byte code offset #68
/*     */     //   Java source line #153	-> byte code offset #75
/*     */     //   Java source line #154	-> byte code offset #84
/*     */     //   Java source line #155	-> byte code offset #90
/*     */     //   Java source line #156	-> byte code offset #93
/*     */     //   Java source line #152	-> byte code offset #103
/*     */     //   Java source line #158	-> byte code offset #106
/*     */     //   Java source line #159	-> byte code offset #108
/*     */     //   Java source line #160	-> byte code offset #113
/*     */     //   Java source line #161	-> byte code offset #118
/*     */     //   Java source line #162	-> byte code offset #123
/*     */     //   Java source line #163	-> byte code offset #128
/*     */     //   Java source line #159	-> byte code offset #131
/*     */     //   Java source line #160	-> byte code offset #136
/*     */     //   Java source line #161	-> byte code offset #141
/*     */     //   Java source line #162	-> byte code offset #146
/*     */     //   Java source line #164	-> byte code offset #151
/*     */     //   Java source line #165	-> byte code offset #153
/*     */     //   Java source line #166	-> byte code offset #155
/*     */     // Local variable table:
/*     */     //   start	length	slot	name	signature
/*     */     //   0	157	0	from	String
/*     */     //   0	157	1	to	String
/*     */     //   6	26	2	lastSlash	int
/*     */     //   13	7	3	lastBackslash	int
/*     */     //   43	104	4	s	java.io.FileInputStream
/*     */     //   46	91	5	d	java.io.FileOutputStream
/*     */     //   73	23	6	buffer	byte[]
/*     */     //   153	3	6	e	IOException
/*     */     //   82	17	7	got	int
/*     */     //   106	23	8	localObject	Object
/*     */     // Exception table:
/*     */     //   from	to	target	type
/*     */     //   48	106	106	finally
/*     */     //   48	151	153	java/io/IOException
/*     */   }
/*     */   
/*     */   protected void build()
/*     */   {
/* 172 */     GridBagLayout gbag = new GridBagLayout();
/* 173 */     setLayout(gbag);
/* 174 */     GridBagConstraints c = new GridBagConstraints();
/* 175 */     c.anchor = 10;
/* 176 */     c.gridwidth = 0;
/* 177 */     c.weightx = 1.0D;
/* 178 */     c.weighty = 1.0D;
/* 179 */     add(gbag, new Label(Console.message("Downloading-update")), c);
/* 180 */     c.insets = new Insets(2, 2, 2, 2);
/* 181 */     add(gbag, this.progressBar, c);
/* 182 */     c.insets = new Insets(0, 2, 0, 2);
/* 183 */     c.anchor = 17;
/* 184 */     add(gbag, this.progressBytes, c);
/* 185 */     c.fill = 2;
/* 186 */     add(gbag, this.progressTime, c);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   protected synchronized void activeCallback()
/*     */   {
/* 193 */     synchronized (this) {
/* 194 */       int n = this.wholeFileBytes;
/* 195 */       if (this.cf != null)
/* 196 */         n += this.cf.bytesLoaded();
/*     */     }
/*     */     int n;
/* 199 */     if (n != this.bytesLoaded) {
/* 200 */       this.bytesLoaded = n;
/* 201 */       this.progressBar.setProgress(this.bytesLoaded / this.bytesTotal);
/* 202 */       int bytesRemaining = this.bytesTotal - this.bytesLoaded;
/*     */       
/* 204 */       NumberFormat nF = NumberFormat.getNumberInstance(
/* 205 */         Locale.getDefault());
/* 206 */       String strRemain = nF.format(bytesRemaining);
/* 207 */       this.progressBytes.setText(bytesMsg + strRemain);
/*     */       
/* 209 */       int elapsed = (Std.getFastTime() - this.startTime) / 1000;
/* 210 */       if (elapsed > 0) {
/* 211 */         double bytesPerSec = this.bytesLoaded / elapsed;
/* 212 */         if (bytesPerSec > 0.0D) {
/* 213 */           String bps = formatTime((bytesRemaining / bytesPerSec));
/* 214 */           Object[] arguments = { new String(bps) };
/*     */           
/* 216 */           this.progressTime.setText(MessageFormat.format(
/* 217 */             Console.message("Time-remaining"), arguments));
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 222 */     notify();
/*     */   }
/*     */   
/*     */   protected boolean done(boolean confirmed)
/*     */   {
/* 227 */     synchronized (this) {
/* 228 */       this.cancelled = true;
/* 229 */       if (this.cf != null)
/* 230 */         this.cf.close();
/*     */     }
/* 232 */     return super.done(confirmed);
/*     */   }
/*     */   
/*     */   private static String fmtTwoDigit(long val) {
/* 236 */     if (val < 10L)
/* 237 */       return "0" + val;
/* 238 */     return val;
/*     */   }
/*     */   
/*     */   private static String formatTime(long secs) {
/* 242 */     String result = "";
/* 243 */     long hrs = secs / 3600L;
/* 244 */     secs -= hrs * 3600L;
/* 245 */     long mins = secs / 60L;
/* 246 */     secs -= mins * 60L;
/* 247 */     if (hrs > 0L)
/* 248 */       result = result + hrs + ":";
/* 249 */     return result + fmtTwoDigit(mins) + ":" + fmtTwoDigit(secs);
/*     */   }
/*     */   
/*     */ 
/*     */   @Deprecated
/*     */   public boolean handleEvent(Event event)
/*     */   {
/* 256 */     if (event.id == 1004) {
/* 257 */       Console.getFrame().requestFocus();
/* 258 */       return true;
/*     */     }
/* 260 */     return super.handleEvent(event);
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\ProgressDialog.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */