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

Last change on this file since 927 was 886, checked in by alloc, 11 years ago

AEI2.16:

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