[591] | 1 | package net.oni2.aeinstaller;
|
---|
| 2 |
|
---|
[593] | 3 | import java.awt.image.BufferedImage;
|
---|
[591] | 4 | import java.io.File;
|
---|
| 5 | import java.io.FileNotFoundException;
|
---|
[593] | 6 | import java.io.IOException;
|
---|
[651] | 7 | import java.lang.reflect.InvocationTargetException;
|
---|
| 8 | import java.lang.reflect.Method;
|
---|
| 9 | import java.net.MalformedURLException;
|
---|
[593] | 10 | import java.net.URL;
|
---|
[651] | 11 | import java.net.URLClassLoader;
|
---|
[886] | 12 | import java.text.SimpleDateFormat;
|
---|
| 13 | import java.util.Date;
|
---|
[592] | 14 | import java.util.ResourceBundle;
|
---|
[591] | 15 |
|
---|
[593] | 16 | import javax.imageio.ImageIO;
|
---|
[591] | 17 | import javax.swing.JFrame;
|
---|
[592] | 18 | import javax.swing.JOptionPane;
|
---|
[591] | 19 | import javax.swing.JToolBar;
|
---|
| 20 | import javax.swing.SwingUtilities;
|
---|
[1025] | 21 | import javax.swing.ToolTipManager;
|
---|
[591] | 22 | import javax.swing.UIManager;
|
---|
| 23 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
| 24 |
|
---|
[852] | 25 | import net.oni2.ProxySettings;
|
---|
[720] | 26 | import net.oni2.SettingsManager;
|
---|
[699] | 27 | import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
|
---|
[886] | 28 | import net.oni2.aeinstaller.backend.LogPrintStream;
|
---|
[596] | 29 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[852] | 30 | import net.oni2.aeinstaller.backend.RuntimeOptions;
|
---|
[599] | 31 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[596] | 32 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[749] | 33 | import net.oni2.aeinstaller.backend.oni.management.Installer;
|
---|
[591] | 34 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
[749] | 35 | import net.oni2.moddepot.DepotManager;
|
---|
[720] | 36 | import net.oni2.platformtools.PlatformInformation;
|
---|
| 37 | import net.oni2.platformtools.PlatformInformation.Platform;
|
---|
[730] | 38 | import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
|
---|
[720] | 39 | import net.oni2.platformtools.applicationinvoker.DotNet;
|
---|
[730] | 40 | import net.oni2.platformtools.applicationinvoker.EExeType;
|
---|
[840] | 41 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
---|
[730] | 42 | import net.oni2.svnaccess.SVN;
|
---|
[849] | 43 | import net.oni2.swingcomponents.HTMLLinkLabel;
|
---|
[591] | 44 |
|
---|
| 45 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 46 | import org.simplericity.macify.eawt.Application;
|
---|
| 47 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
[591] | 48 |
|
---|
| 49 | /**
|
---|
| 50 | * @author Christian Illy
|
---|
| 51 | */
|
---|
| 52 | public 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 | }
|
---|