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

Last change on this file since 734 was 730, checked in by alloc, 12 years ago

AEI2 0.99w:

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