summaryrefslogtreecommitdiff
path: root/NET/worlds/console/PersonalInfoDownload.java
blob: 4e4e89043cb1b3232db3d6edfcf0871f607295ee (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
package NET.worlds.console;

import NET.worlds.network.Cache;
import NET.worlds.network.CacheFile;
import NET.worlds.network.URL;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Label;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Vector;

class PersonalInfoDownload extends OkCancelDialog implements Runnable {
   private static final long serialVersionUID = -198244581766521022L;
   private String name;
   private CacheFile cf;
   private static Font font = new Font(Console.message("MenuFont"), 0, 12);

   public PersonalInfoDownload(String name, Console console) {
      super(Console.getFrame(), null, Console.message("Downloading2"), Console.message("Cancel"), null, false);
      this.name = name;
      String cfS = console.getScriptServer() + "profile" + Console.message(".pl") + "?" + name;
      this.cf = Cache.getFile(URL.make(cfS));
      if (Console.wasHttpNoSuchFile(cfS)) {
         this.cf = Cache.getFile(URL.make(console.getScriptServer() + "profile.pl?" + name));
      }

      this.setFont(new Font(Console.message("FriendsFont"), 0, 12));
      Thread t = new Thread(this);
      t.setDaemon(true);
      t.start();
   }

   @Override
   protected void build() {
      GridBagConstraints c = new GridBagConstraints();
      c.weightx = 1.0;
      c.weighty = 1.0;
      c.gridwidth = 0;
      Object[] arguments = new Object[]{new String(this.name)};
      Label lDown = new Label(MessageFormat.format(Console.message("Downloading"), arguments));
      lDown.setFont(font);
      this.add(this.gbag, lDown, c);
      Label lWait = new Label(Console.message("Please-wait"));
      lWait.setFont(font);
      this.add(this.gbag, lWait, c);
      super.build();
   }

   @Override
   public void run() {
      this.readySetGo();
      this.cf.waitUntilLoaded();
      if (this.cf.isActive()) {
         this.done(true);
         if (this.cf.error()) {
            Object[] arguments = new Object[]{new String(this.name)};
            new OkCancelDialog(
               Console.getFrame(),
               null,
               Console.message("Error"),
               null,
               Console.message("OK"),
               MessageFormat.format(Console.message("Error-down"), arguments),
               false
            );
            System.out.println("Error downloading personal info for " + this.name);
         } else {
            Vector<String> data = new Vector<String>();
            DataInputStream in = null;

            try {
               in = new DataInputStream(new FileInputStream(this.cf.getLocalName()));

               String line;
               while ((line = in.readLine()) != null) {
                  data.addElement(line);
               }

               new PersonalInfoDialog(this.name, data);
            } catch (FileNotFoundException var14) {
            } catch (IOException var15) {
            } finally {
               try {
                  if (in != null) {
                     in.close();
                  }
               } catch (IOException var13) {
               }
            }
         }

         this.cf.close();
      }
   }
}