[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;
|
---|
| 21 | import javax.swing.UIManager;
|
---|
| 22 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
| 23 |
|
---|
[852] | 24 | import net.oni2.ProxySettings;
|
---|
[720] | 25 | import net.oni2.SettingsManager;
|
---|
[699] | 26 | import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
|
---|
[886] | 27 | import net.oni2.aeinstaller.backend.LogPrintStream;
|
---|
[596] | 28 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[852] | 29 | import net.oni2.aeinstaller.backend.RuntimeOptions;
|
---|
[599] | 30 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[596] | 31 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[749] | 32 | import net.oni2.aeinstaller.backend.oni.management.Installer;
|
---|
[591] | 33 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
[749] | 34 | import net.oni2.moddepot.DepotManager;
|
---|
[720] | 35 | import net.oni2.platformtools.PlatformInformation;
|
---|
| 36 | import net.oni2.platformtools.PlatformInformation.Platform;
|
---|
[730] | 37 | import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
|
---|
[720] | 38 | import net.oni2.platformtools.applicationinvoker.DotNet;
|
---|
[730] | 39 | import net.oni2.platformtools.applicationinvoker.EExeType;
|
---|
[840] | 40 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
---|
[730] | 41 | import net.oni2.svnaccess.SVN;
|
---|
[849] | 42 | import net.oni2.swingcomponents.HTMLLinkLabel;
|
---|
[591] | 43 |
|
---|
| 44 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 45 | import org.simplericity.macify.eawt.Application;
|
---|
| 46 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
[591] | 47 |
|
---|
| 48 | /**
|
---|
| 49 | * @author Christian Illy
|
---|
| 50 | */
|
---|
| 51 | public 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) {
|
---|
[988] | 118 | if (PlatformInformation.getPlatform() == Platform.MACOS)
|
---|
| 119 | initMacOS();
|
---|
| 120 |
|
---|
[596] | 121 | Paths.getPrefsPath().mkdirs();
|
---|
| 122 | Paths.getDownloadPath().mkdirs();
|
---|
[591] | 123 |
|
---|
[649] | 124 | for (String a : args) {
|
---|
[591] | 125 | if (a.equalsIgnoreCase("-debug"))
|
---|
[852] | 126 | RuntimeOptions.setDebug(true);
|
---|
[649] | 127 | if (a.equalsIgnoreCase("-nocacheupdate"))
|
---|
[852] | 128 | RuntimeOptions.setNoCacheUpdateMode(true);
|
---|
[749] | 129 | if (a.equalsIgnoreCase("-offline"))
|
---|
[852] | 130 | RuntimeOptions.setOfflineMode(true);
|
---|
[776] | 131 | if (a.equalsIgnoreCase("-usewd"))
|
---|
[852] | 132 | RuntimeOptions.setUseWorkingDir(true);
|
---|
[649] | 133 | }
|
---|
[886] | 134 | LogPrintStream lps = LogPrintStream.getInstance();
|
---|
[852] | 135 | if (!RuntimeOptions.isDebug()) {
|
---|
[591] | 136 | try {
|
---|
[886] | 137 | lps.setFile(new File(Paths.getPrefsPath(), "aei_output.log"));
|
---|
[591] | 138 | } catch (FileNotFoundException e1) {
|
---|
| 139 | e1.printStackTrace();
|
---|
[886] | 140 | } catch (IOException e) {
|
---|
| 141 | e.printStackTrace();
|
---|
[591] | 142 | }
|
---|
| 143 | }
|
---|
[730] | 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 | }
|
---|