source: AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java@ 659

Last change on this file since 659 was 653, checked in by alloc, 12 years ago

AEI2 0.99g:

  • Fixed MacOS launch
  • Added version information to installation.log
File size: 8.0 KB
Line 
1package net.oni2.aeinstaller;
2
3import java.awt.image.BufferedImage;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.io.PrintStream;
8import java.lang.reflect.InvocationTargetException;
9import java.lang.reflect.Method;
10import java.net.MalformedURLException;
11import java.net.URL;
12import java.net.URLClassLoader;
13import java.util.ResourceBundle;
14
15import javax.imageio.ImageIO;
16import javax.swing.JFrame;
17import javax.swing.JOptionPane;
18import javax.swing.JToolBar;
19import javax.swing.SwingUtilities;
20import javax.swing.UIManager;
21import javax.swing.UIManager.LookAndFeelInfo;
22
23import net.oni2.aeinstaller.backend.Paths;
24import net.oni2.aeinstaller.backend.Settings;
25import net.oni2.aeinstaller.backend.Settings.Platform;
26import net.oni2.aeinstaller.backend.SizeFormatter;
27import net.oni2.aeinstaller.backend.depot.DepotManager;
28import net.oni2.aeinstaller.backend.oni.Installer;
29import net.oni2.aeinstaller.backend.oni.OniSplit;
30import net.oni2.aeinstaller.gui.HTMLLinkLabel;
31import net.oni2.aeinstaller.gui.MainWin;
32
33import org.javabuilders.swing.SwingJavaBuilder;
34import org.simplericity.macify.eawt.Application;
35import org.simplericity.macify.eawt.DefaultApplication;
36
37/**
38 * @author Christian Illy
39 */
40public class AEInstaller2 {
41
42 private static ResourceBundle imagesBundle;
43 private static ResourceBundle basicBundle;
44 private static ResourceBundle globalBundle;
45
46 private static Application app = null;
47
48 private static void initMacOS() {
49 System.setProperty("apple.laf.useScreenMenuBar", "true");
50 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
51 basicBundle.getString("appname"));
52 app = new DefaultApplication();
53
54 URL icon = AEInstaller2.class.getResource(imagesBundle
55 .getString("img.ae"));
56 try {
57 BufferedImage img = ImageIO.read(icon);
58 app.setApplicationIconImage(img);
59 } catch (IOException e) {
60 e.printStackTrace();
61 }
62 }
63
64 private static void initBundles() {
65 File localesDir = new File(Paths.getInstallerPath(), "locales");
66 if (localesDir.isDirectory())
67 addClassPath(localesDir);
68 imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
69 basicBundle = ResourceBundle
70 .getBundle("net.oni2.aeinstaller.AEInstaller");
71 globalBundle = ResourceBundle
72 .getBundle("net.oni2.aeinstaller.localization.Global");
73 }
74
75 private static void addClassPath(File dir) {
76 try {
77 URL u = dir.toURI().toURL();
78 URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader
79 .getSystemClassLoader();
80 Class<URLClassLoader> urlClass = URLClassLoader.class;
81 Method method = urlClass.getDeclaredMethod("addURL",
82 new Class[] { URL.class });
83 method.setAccessible(true);
84 method.invoke(urlClassLoader, new Object[] { u });
85 } catch (MalformedURLException e) {
86 } catch (SecurityException e) {
87 } catch (NoSuchMethodException e) {
88 } catch (IllegalArgumentException e) {
89 } catch (IllegalAccessException e) {
90 } catch (InvocationTargetException e) {
91 }
92 }
93
94 /**
95 * @param args
96 * Command line arguments
97 */
98 public static void main(String[] args) {
99 Paths.getPrefsPath().mkdirs();
100 Paths.getDownloadPath().mkdirs();
101
102 boolean debug = false;
103 boolean noCacheUpdate = false;
104 for (String a : args) {
105 if (a.equalsIgnoreCase("-debug"))
106 debug = true;
107 if (a.equalsIgnoreCase("-nocacheupdate"))
108 noCacheUpdate = true;
109 }
110 if (!debug) {
111 try {
112 PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
113 "aei_output.log"));
114 System.setOut(ps);
115 System.setErr(ps);
116 } catch (FileNotFoundException e1) {
117 e1.printStackTrace();
118 }
119 }
120
121 initBundles();
122
123 if (Settings.getPlatform() == Platform.MACOS)
124 initMacOS();
125
126 Settings.setDebug(debug);
127 Settings.deserializeFromFile();
128 Settings.setDebug(debug);
129 Settings.getInstance().setNoCacheUpdateMode(noCacheUpdate);
130
131 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
132 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
133 SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
134 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
135 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
136 JToolBar.Separator.class);
137
138 System.setProperty("networkaddress.cache.ttl", "5");
139 System.setProperty("networkaddress.cache.negative.ttl", "1");
140
141 try {
142 String laf = Settings.getInstance().get("lookandfeel",
143 (String) null);
144 if (laf == null) {
145 if (Settings.getPlatform() != Platform.LINUX) {
146 laf = UIManager.getSystemLookAndFeelClassName();
147 } else {
148 for (LookAndFeelInfo lafInfo : UIManager
149 .getInstalledLookAndFeels()) {
150 if (lafInfo.getName().equals("Nimbus"))
151 laf = lafInfo.getClassName();
152 }
153 }
154 }
155 if (laf == null)
156 laf = UIManager.getSystemLookAndFeelClassName();
157 UIManager.setLookAndFeel(laf);
158 } catch (Exception e) {
159 e.printStackTrace();
160 }
161 JFrame.setDefaultLookAndFeelDecorated(true);
162
163 System.out.println(basicBundle.getString("appname") + " "
164 + basicBundle.getString("appversion"));
165 System.out.println("JarPath: " + Paths.getInstallerPath());
166 System.out.println("PrefsPath: " + Paths.getPrefsPath());
167 System.out.println("DataPath: " + Paths.getModsPath());
168 System.out.println("DownPath: " + Paths.getDownloadPath());
169 System.out.println("TempPath: " + Paths.getTempPath());
170 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
171 System.out.println("Platform: " + Settings.getPlatform());
172 System.out.println("Architect: " + Settings.getArchitecture());
173 System.out.println(".NET: " + OniSplit.isDotNETInstalled());
174 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
175 System.out.println("Globalized:" + Installer.isEditionInitialized());
176
177 // TODO: Check available space
178 System.out
179 .println("Free space on temp: "
180 + SizeFormatter.format(Paths.getTempPath()
181 .getUsableSpace(), 3));
182 System.out.println("Free space on Jar: "
183 + SizeFormatter.format(Paths.getInstallerPath()
184 .getUsableSpace(), 3));
185 System.out.println();
186
187 if (!OniSplit.isDotNETInstalled()) {
188 HTMLLinkLabel hll = new HTMLLinkLabel();
189 String dlUrl = "";
190 switch (Settings.getPlatform()) {
191 case WIN:
192 switch (Settings.getArchitecture()) {
193 case X86:
194 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
195 break;
196 case AMD64:
197 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
198 break;
199 }
200 break;
201 default:
202 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
203 }
204 hll.setText(globalBundle
205 .getString("dotNetMissing.text")
206 .replaceAll(
207 "%1",
208 String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
209 JOptionPane.showMessageDialog(null, hll,
210 globalBundle.getString("dotNetMissing.title"),
211 JOptionPane.ERROR_MESSAGE);
212 return;
213 }
214
215 if (!Installer.verifyRunningDirectory()) {
216 JOptionPane.showMessageDialog(null,
217 globalBundle.getString("invalidPath.text"),
218 globalBundle.getString("invalidPath.title"),
219 JOptionPane.ERROR_MESSAGE);
220 if (!Settings.isDebug()) {
221 return;
222 }
223 }
224
225 boolean offline = false;
226 for (String a : args)
227 if (a.equalsIgnoreCase("-offline"))
228 offline = true;
229 if (!offline) {
230 offline = !DepotManager.getInstance().checkConnection();
231 }
232 if (offline) {
233 JOptionPane.showMessageDialog(null,
234 globalBundle.getString("offlineModeStartup.text"),
235 globalBundle.getString("offlineModeStartup.title"),
236 JOptionPane.INFORMATION_MESSAGE);
237 }
238 Settings.getInstance().setOfflineMode(offline);
239
240 SwingUtilities.invokeLater(new Runnable() {
241 public void run() {
242 try {
243 MainWin mw = new MainWin();
244 if (app != null) {
245 app.addAboutMenuItem();
246 app.setEnabledAboutMenu(true);
247 app.addPreferencesMenuItem();
248 app.setEnabledPreferencesMenu(true);
249 app.addApplicationListener(mw);
250 }
251 mw.setVisible(true);
252 } catch (Exception e) {
253 e.printStackTrace();
254 }
255 }
256 });
257
258 }
259}
Note: See TracBrowser for help on using the repository browser.