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

Last change on this file since 704 was 699, checked in by alloc, 12 years ago

AEI2 0.99t:

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