ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/installer2/src/net/oni2/aeinstaller/AEInstaller2.java
Revision: 629
Committed: Fri Jan 18 11:17:17 2013 UTC (12 years, 8 months ago) by alloc
Content type: text/x-java
Original Path: AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java
File size: 6781 byte(s)
Log Message:
AEI2 0.88:
- Localization files moved to common localization package

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.Paths;
20 import net.oni2.aeinstaller.backend.Settings;
21 import net.oni2.aeinstaller.backend.Settings.Platform;
22 import net.oni2.aeinstaller.backend.SizeFormatter;
23 import net.oni2.aeinstaller.backend.depot.DepotManager;
24 import net.oni2.aeinstaller.backend.oni.Installer;
25 import net.oni2.aeinstaller.backend.oni.OniSplit;
26 import net.oni2.aeinstaller.gui.HTMLLinkLabel;
27 import net.oni2.aeinstaller.gui.MainWin;
28
29 import org.javabuilders.swing.SwingJavaBuilder;
30 import org.simplericity.macify.eawt.Application;
31 import org.simplericity.macify.eawt.DefaultApplication;
32
33 /**
34 * @author Christian Illy
35 */
36 public class AEInstaller2 {
37
38 private static ResourceBundle imagesBundle = ResourceBundle
39 .getBundle("net.oni2.aeinstaller.Images");
40 private static ResourceBundle basicBundle = ResourceBundle
41 .getBundle("net.oni2.aeinstaller.AEInstaller");
42 private static ResourceBundle startupBundle = ResourceBundle
43 .getBundle("net.oni2.aeinstaller.localization.Startup");
44
45 private static Application app = null;
46
47 private static void initMacOS() {
48 System.setProperty("apple.laf.useScreenMenuBar", "true");
49 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
50 basicBundle.getString("appname"));
51 app = new DefaultApplication();
52
53 URL icon = AEInstaller2.class.getResource("images/AElogo.png");
54 try {
55 BufferedImage img = ImageIO.read(icon);
56 app.setApplicationIconImage(img);
57 } catch (IOException e) {
58 e.printStackTrace();
59 }
60 }
61
62 /**
63 * @param args
64 * Command line arguments
65 */
66 public static void main(String[] args) {
67 Paths.getPrefsPath().mkdirs();
68 Paths.getDownloadPath().mkdirs();
69
70 boolean debug = false;
71 for (String a : args)
72 if (a.equalsIgnoreCase("-debug"))
73 debug = true;
74 if (!debug) {
75 try {
76 System.setOut(new PrintStream(new File(Paths.getPrefsPath(),
77 "aei_output.log")));
78 System.setErr(new PrintStream(new File(Paths.getPrefsPath(),
79 "aei_error.log")));
80 } catch (FileNotFoundException e1) {
81 e1.printStackTrace();
82 }
83 }
84
85 if (Settings.getPlatform() == Platform.MACOS)
86 initMacOS();
87
88 Settings.deserializeFromFile();
89 Settings.setDebug(debug);
90 DepotManager.getInstance().loadFromFile(
91 Settings.getDepotCacheFilename());
92
93 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
94 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
95 SwingJavaBuilder.getConfig().addResourceBundle(startupBundle);
96 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
97 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
98 JToolBar.Separator.class);
99
100 System.setProperty("networkaddress.cache.ttl", "5");
101 System.setProperty("networkaddress.cache.negative.ttl", "1");
102
103 try {
104 String laf = Settings.getInstance().get("lookandfeel",
105 (String) null);
106 if (laf == null) {
107 if (Settings.getPlatform() != Platform.LINUX) {
108 laf = UIManager.getSystemLookAndFeelClassName();
109 } else {
110 for (LookAndFeelInfo lafInfo : UIManager
111 .getInstalledLookAndFeels()) {
112 if (lafInfo.getName().equals("Nimbus"))
113 laf = lafInfo.getClassName();
114 }
115 }
116 }
117 if (laf == null)
118 laf = UIManager.getSystemLookAndFeelClassName();
119 UIManager.setLookAndFeel(laf);
120 } catch (Exception e) {
121 e.printStackTrace();
122 }
123 JFrame.setDefaultLookAndFeelDecorated(true);
124
125 // TODO: Remove debug output
126 System.out.println("JarPath: " + Paths.getInstallerPath());
127 System.out.println("PrefsPath: " + Paths.getPrefsPath());
128 System.out.println("DataPath: " + Paths.getModsPath());
129 System.out.println("DownPath: " + Paths.getDownloadPath());
130 System.out.println("TempPath: " + Paths.getTempPath());
131 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
132 System.out.println("Platform: " + Settings.getPlatform());
133 System.out.println("Architect: " + Settings.getArchitecture());
134 System.out.println(".NET: " + OniSplit.isDotNETInstalled());
135 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
136 System.out.println("Globalized:" + Installer.isEditionInitialized());
137
138 // TODO: Check available space
139 System.out
140 .println("Free space on temp: "
141 + SizeFormatter.format(Paths.getTempPath()
142 .getUsableSpace(), 3));
143 System.out.println("Free space on Jar: "
144 + SizeFormatter.format(Paths.getInstallerPath()
145 .getUsableSpace(), 3));
146
147 if (!OniSplit.isDotNETInstalled()) {
148 HTMLLinkLabel hll = new HTMLLinkLabel();
149 String dlUrl = "";
150 switch (Settings.getPlatform()) {
151 case WIN:
152 switch (Settings.getArchitecture()) {
153 case X86:
154 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
155 break;
156 case AMD64:
157 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
158 break;
159 }
160 break;
161 default:
162 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
163 }
164 hll.setText(startupBundle.getString("dotNetMissing.text").replaceAll(
165 "%1", String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
166 JOptionPane.showMessageDialog(null, hll,
167 startupBundle.getString("dotNetMissing.title"),
168 JOptionPane.ERROR_MESSAGE);
169 return;
170 }
171
172 if (!Installer.verifyRunningDirectory()) {
173 JOptionPane.showMessageDialog(null,
174 startupBundle.getString("invalidPath.text"),
175 startupBundle.getString("invalidPath.title"),
176 JOptionPane.ERROR_MESSAGE);
177 if (!Settings.isDebug()) {
178 return;
179 }
180 }
181
182 boolean offline = !DepotManager.getInstance().checkConnection();
183 if (offline) {
184 JOptionPane.showMessageDialog(null,
185 startupBundle.getString("offlineMode.text"),
186 startupBundle.getString("offlineMode.title"),
187 JOptionPane.INFORMATION_MESSAGE);
188 }
189 Settings.getInstance().setOfflineMode(offline);
190
191 SwingUtilities.invokeLater(new Runnable() {
192 public void run() {
193 try {
194 MainWin mw = new MainWin();
195 if (app != null) {
196 app.addAboutMenuItem();
197 app.setEnabledAboutMenu(true);
198 app.addPreferencesMenuItem();
199 app.setEnabledPreferencesMenu(true);
200 app.addApplicationListener(mw);
201 }
202 mw.setVisible(true);
203 } catch (Exception e) {
204 e.printStackTrace();
205 }
206 }
207 });
208
209 }
210 }