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

Last change on this file since 693 was 672, checked in by alloc, 12 years ago

AEI2 0.99q:

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