ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java
Revision: 593
Committed: Mon Dec 31 13:48:32 2012 UTC (12 years, 9 months ago) by alloc
Content type: text/x-java
File size: 4703 byte(s)
Log Message:

File Contents

# Content
1 package net.oni2.aeinstaller;
2
3 import java.awt.image.BufferedImage;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.PrintStream;
8 import java.net.URL;
9 import java.util.ResourceBundle;
10
11 import javax.imageio.ImageIO;
12 import javax.swing.JFrame;
13 import javax.swing.JOptionPane;
14 import javax.swing.JToolBar;
15 import javax.swing.SwingUtilities;
16 import javax.swing.UIManager;
17 import javax.swing.UIManager.LookAndFeelInfo;
18
19 import net.oni2.aeinstaller.backend.Settings;
20 import net.oni2.aeinstaller.backend.Settings.Platform;
21 import net.oni2.aeinstaller.backend.StuffToRefactorLater;
22 import net.oni2.aeinstaller.backend.depot.DepotManager;
23 import net.oni2.aeinstaller.gui.MainWin;
24
25 import org.javabuilders.swing.SwingJavaBuilder;
26 import org.simplericity.macify.eawt.Application;
27 import org.simplericity.macify.eawt.DefaultApplication;
28
29 /**
30 * @author Christian Illy
31 */
32 public class AEInstaller2 {
33
34 private static ResourceBundle imagesBundle = ResourceBundle
35 .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
36 private static ResourceBundle basicBundle = ResourceBundle
37 .getBundle(AEInstaller2.class.getPackage().getName()
38 + ".AEInstaller");
39
40 private static Application app = null;
41
42 private static void initMacOS() {
43 System.setProperty("apple.laf.useScreenMenuBar", "true");
44 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
45 basicBundle.getString("appname"));
46 app = new DefaultApplication();
47
48 URL icon = AEInstaller2.class.getResource("images/AElogo.png");
49 try {
50 BufferedImage img = ImageIO.read(icon);
51 app.setApplicationIconImage(img);
52 } catch (IOException e) {
53 // TODO Auto-generated catch block
54 e.printStackTrace();
55 }
56 }
57
58 /**
59 * @param args
60 * Command line arguments
61 */
62 public static void main(String[] args) {
63 new File(Settings.getPrefsPath()).mkdirs();
64 new File(Settings.getDownloadPath()).mkdirs();
65
66 boolean debug = false;
67 for (String a : args)
68 if (a.equalsIgnoreCase("-debug"))
69 debug = true;
70 if (!debug) {
71 try {
72 System.setOut(new PrintStream(Settings.getPrefsPath()
73 + "aei_output.log"));
74 System.setErr(new PrintStream(Settings.getPrefsPath()
75 + "aei_error.log"));
76 } catch (FileNotFoundException e1) {
77 e1.printStackTrace();
78 }
79 }
80
81 if (Settings.getPlatform() == Platform.MACOS)
82 initMacOS();
83
84 Settings.deserializeFromFile();
85 Settings.setDebug(debug);
86 DepotManager.getInstance().loadFromFile(
87 new File(Settings.getDepotCacheFilename()));
88
89 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
90 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
91 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
92 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
93 JToolBar.Separator.class);
94
95 System.setProperty("networkaddress.cache.ttl", "5");
96 System.setProperty("networkaddress.cache.negative.ttl", "1");
97
98 try {
99 String laf = Settings.getInstance().get("lookandfeel",
100 (String) null);
101 if (laf == null) {
102 if (Settings.getPlatform() == Platform.MACOS) {
103 laf = UIManager.getSystemLookAndFeelClassName();
104 } else {
105 for (LookAndFeelInfo lafInfo : UIManager
106 .getInstalledLookAndFeels()) {
107 if (lafInfo.getName().equals("Nimbus"))
108 laf = lafInfo.getClassName();
109 }
110 }
111 }
112 if (laf == null)
113 laf = UIManager.getSystemLookAndFeelClassName();
114 UIManager.setLookAndFeel(laf);
115 } catch (Exception e) {
116 e.printStackTrace();
117 }
118 JFrame.setDefaultLookAndFeelDecorated(true);
119
120 // TODO
121 System.out.println("JarPath: " + Settings.getJarPath());
122 System.out.println("PrefsPath: " + Settings.getPrefsPath());
123 System.out.println("DataPath: " + Settings.getDataPath());
124 System.out.println("DownPath: " + Settings.getDownloadPath());
125 System.out.println("TempPath: " + Settings.getTempPath());
126 System.out.println("ValidPath: "
127 + StuffToRefactorLater.verifyRunningDirectory());
128
129 if (!StuffToRefactorLater.verifyRunningDirectory()) {
130 JOptionPane.showMessageDialog(null,
131 basicBundle.getString("invalidPath.text"),
132 basicBundle.getString("invalidPath.title"),
133 JOptionPane.ERROR_MESSAGE);
134 if (!Settings.getDebug()) {
135 return;
136 }
137 }
138
139 SwingUtilities.invokeLater(new Runnable() {
140
141 public void run() {
142 try {
143 MainWin mw = new MainWin();
144 if (app != null) {
145 app.addAboutMenuItem();
146 app.setEnabledAboutMenu(true);
147 app.addPreferencesMenuItem();
148 app.setEnabledPreferencesMenu(true);
149 app.addApplicationListener(mw);
150 }
151 mw.setVisible(true);
152 } catch (Exception e) {
153 e.printStackTrace();
154 }
155 }
156 });
157
158 }
159 }