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

Last change on this file since 738 was 735, checked in by alloc, 12 years ago

AEI2 0.99w:

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