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

Last change on this file since 721 was 720, checked in by alloc, 12 years ago

AEI2: Looooots of refactorings for breaking out independent features into libraries

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