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

Last change on this file since 1043 was 1032, checked in by alloc, 9 years ago

v.25: Added some debug information to mod installation, auto flush log, print detected platform

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