[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;
|
---|
[591] | 7 | import java.io.PrintStream;
|
---|
[651] | 8 | import java.lang.reflect.InvocationTargetException;
|
---|
| 9 | import java.lang.reflect.Method;
|
---|
| 10 | import java.net.MalformedURLException;
|
---|
[593] | 11 | import java.net.URL;
|
---|
[651] | 12 | import java.net.URLClassLoader;
|
---|
[592] | 13 | import java.util.ResourceBundle;
|
---|
[591] | 14 |
|
---|
[593] | 15 | import javax.imageio.ImageIO;
|
---|
[591] | 16 | import javax.swing.JFrame;
|
---|
[592] | 17 | import javax.swing.JOptionPane;
|
---|
[591] | 18 | import javax.swing.JToolBar;
|
---|
| 19 | import javax.swing.SwingUtilities;
|
---|
| 20 | import javax.swing.UIManager;
|
---|
| 21 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
| 22 |
|
---|
[720] | 23 | import net.oni2.SettingsManager;
|
---|
[699] | 24 | import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
|
---|
[596] | 25 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[599] | 26 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[596] | 27 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[749] | 28 | import net.oni2.aeinstaller.backend.oni.management.Installer;
|
---|
[612] | 29 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
---|
[591] | 30 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
[749] | 31 | import net.oni2.moddepot.DepotManager;
|
---|
[720] | 32 | import net.oni2.platformtools.PlatformInformation;
|
---|
| 33 | import net.oni2.platformtools.PlatformInformation.Platform;
|
---|
[730] | 34 | import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
|
---|
[720] | 35 | import net.oni2.platformtools.applicationinvoker.DotNet;
|
---|
[730] | 36 | import net.oni2.platformtools.applicationinvoker.EExeType;
|
---|
| 37 | import net.oni2.svnaccess.SVN;
|
---|
[591] | 38 |
|
---|
| 39 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 40 | import org.simplericity.macify.eawt.Application;
|
---|
| 41 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
[591] | 42 |
|
---|
| 43 | /**
|
---|
| 44 | * @author Christian Illy
|
---|
| 45 | */
|
---|
| 46 | public 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);
|
---|
[735] | 75 | else {
|
---|
| 76 | File localesSubDir = CaseInsensitiveFile.getCaseInsensitiveFile(
|
---|
| 77 | CaseInsensitiveFile.getCaseInsensitiveFile(
|
---|
| 78 | Paths.getInstallerPath(), "bin"), "locales");
|
---|
| 79 | if (localesSubDir.isDirectory()) {
|
---|
| 80 | addClassPath(localesSubDir);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
[653] | 83 | imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
|
---|
| 84 | basicBundle = ResourceBundle
|
---|
| 85 | .getBundle("net.oni2.aeinstaller.AEInstaller");
|
---|
| 86 | globalBundle = ResourceBundle
|
---|
| 87 | .getBundle("net.oni2.aeinstaller.localization.Global");
|
---|
| 88 | }
|
---|
[593] | 89 |
|
---|
[651] | 90 | private static void addClassPath(File dir) {
|
---|
| 91 | try {
|
---|
| 92 | URL u = dir.toURI().toURL();
|
---|
| 93 | URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader
|
---|
| 94 | .getSystemClassLoader();
|
---|
| 95 | Class<URLClassLoader> urlClass = URLClassLoader.class;
|
---|
| 96 | Method method = urlClass.getDeclaredMethod("addURL",
|
---|
| 97 | new Class[] { URL.class });
|
---|
| 98 | method.setAccessible(true);
|
---|
| 99 | method.invoke(urlClassLoader, new Object[] { u });
|
---|
| 100 | } catch (MalformedURLException e) {
|
---|
| 101 | } catch (SecurityException e) {
|
---|
| 102 | } catch (NoSuchMethodException e) {
|
---|
| 103 | } catch (IllegalArgumentException e) {
|
---|
| 104 | } catch (IllegalAccessException e) {
|
---|
| 105 | } catch (InvocationTargetException e) {
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[591] | 109 | /**
|
---|
| 110 | * @param args
|
---|
| 111 | * Command line arguments
|
---|
| 112 | */
|
---|
| 113 | public static void main(String[] args) {
|
---|
[596] | 114 | Paths.getPrefsPath().mkdirs();
|
---|
| 115 | Paths.getDownloadPath().mkdirs();
|
---|
[591] | 116 |
|
---|
| 117 | boolean debug = false;
|
---|
[776] | 118 | boolean useWd = false;
|
---|
[649] | 119 | boolean noCacheUpdate = false;
|
---|
[749] | 120 | boolean offline = false;
|
---|
[649] | 121 | for (String a : args) {
|
---|
[591] | 122 | if (a.equalsIgnoreCase("-debug"))
|
---|
| 123 | debug = true;
|
---|
[649] | 124 | if (a.equalsIgnoreCase("-nocacheupdate"))
|
---|
| 125 | noCacheUpdate = true;
|
---|
[749] | 126 | if (a.equalsIgnoreCase("-offline"))
|
---|
| 127 | offline = true;
|
---|
[776] | 128 | if (a.equalsIgnoreCase("-usewd"))
|
---|
| 129 | useWd = true;
|
---|
[649] | 130 | }
|
---|
[591] | 131 | if (!debug) {
|
---|
| 132 | try {
|
---|
[634] | 133 | PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
|
---|
| 134 | "aei_output.log"));
|
---|
| 135 | System.setOut(ps);
|
---|
| 136 | System.setErr(ps);
|
---|
[591] | 137 | } catch (FileNotFoundException e1) {
|
---|
| 138 | e1.printStackTrace();
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
[730] | 141 |
|
---|
[753] | 142 | SettingsManager.setDebug(debug);
|
---|
| 143 | SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
|
---|
| 144 | SettingsManager.setDebug(debug);
|
---|
[776] | 145 | SettingsManager.setUseWorkingDir(useWd);
|
---|
[753] | 146 | SettingsManager.getInstance().setNoCacheUpdateMode(noCacheUpdate);
|
---|
| 147 |
|
---|
[653] | 148 | initBundles();
|
---|
[591] | 149 |
|
---|
[720] | 150 | if (PlatformInformation.getPlatform() == Platform.MACOS)
|
---|
[593] | 151 | initMacOS();
|
---|
| 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 |
|
---|
[772] | 185 | System.out.println(basicBundle.getString("appname")
|
---|
[637] | 186 | + basicBundle.getString("appversion"));
|
---|
[778] | 187 | System.out.println("JarPath: " + Paths.getJarPath());
|
---|
[596] | 188 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
| 189 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
| 190 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
| 191 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
[612] | 192 | System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
|
---|
[720] | 193 | System.out.println("Platform: " + PlatformInformation.getPlatform());
|
---|
[730] | 194 | System.out.println("Architect: "
|
---|
| 195 | + PlatformInformation.getArchitecture());
|
---|
[672] | 196 | System.out.println(".NET: " + DotNet.isInstalled());
|
---|
[602] | 197 | System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
|
---|
[596] | 198 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
[591] | 199 |
|
---|
[624] | 200 | // TODO: Check available space
|
---|
[600] | 201 | System.out
|
---|
| 202 | .println("Free space on temp: "
|
---|
| 203 | + SizeFormatter.format(Paths.getTempPath()
|
---|
| 204 | .getUsableSpace(), 3));
|
---|
| 205 | System.out.println("Free space on Jar: "
|
---|
| 206 | + SizeFormatter.format(Paths.getInstallerPath()
|
---|
| 207 | .getUsableSpace(), 3));
|
---|
[634] | 208 | System.out.println();
|
---|
[600] | 209 |
|
---|
[672] | 210 | if (!DotNet.isInstalled()) {
|
---|
[612] | 211 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
| 212 | String dlUrl = "";
|
---|
[720] | 213 | switch (PlatformInformation.getPlatform()) {
|
---|
[612] | 214 | case WIN:
|
---|
[720] | 215 | switch (PlatformInformation.getArchitecture()) {
|
---|
[612] | 216 | case X86:
|
---|
| 217 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
| 218 | break;
|
---|
| 219 | case AMD64:
|
---|
| 220 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
| 221 | break;
|
---|
| 222 | }
|
---|
| 223 | break;
|
---|
| 224 | default:
|
---|
| 225 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
| 226 | }
|
---|
[640] | 227 | hll.setText(globalBundle
|
---|
[634] | 228 | .getString("dotNetMissing.text")
|
---|
| 229 | .replaceAll(
|
---|
| 230 | "%1",
|
---|
| 231 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
[612] | 232 | JOptionPane.showMessageDialog(null, hll,
|
---|
[640] | 233 | globalBundle.getString("dotNetMissing.title"),
|
---|
[612] | 234 | JOptionPane.ERROR_MESSAGE);
|
---|
| 235 | return;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
[603] | 238 | if (!Installer.verifyRunningDirectory()) {
|
---|
[592] | 239 | JOptionPane.showMessageDialog(null,
|
---|
[640] | 240 | globalBundle.getString("invalidPath.text"),
|
---|
| 241 | globalBundle.getString("invalidPath.title"),
|
---|
[592] | 242 | JOptionPane.ERROR_MESSAGE);
|
---|
[720] | 243 | if (!SettingsManager.isDebug()) {
|
---|
[592] | 244 | return;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[649] | 248 | if (!offline) {
|
---|
| 249 | offline = !DepotManager.getInstance().checkConnection();
|
---|
| 250 | }
|
---|
| 251 | if (offline) {
|
---|
[621] | 252 | JOptionPane.showMessageDialog(null,
|
---|
[646] | 253 | globalBundle.getString("offlineModeStartup.text"),
|
---|
| 254 | globalBundle.getString("offlineModeStartup.title"),
|
---|
[621] | 255 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 256 | }
|
---|
[720] | 257 | SettingsManager.getInstance().setOfflineMode(offline);
|
---|
[621] | 258 |
|
---|
[730] | 259 | if (!offline) {
|
---|
| 260 | SVN svn = new SVN();
|
---|
| 261 | try {
|
---|
| 262 | int x = svn.checkSVN("http://svn.aei.oni2.net",
|
---|
[776] | 263 | Paths.getJarPath());
|
---|
[730] | 264 | if (x > 0) {
|
---|
[766] | 265 | // Update available or missing files
|
---|
[730] | 266 | int res = JOptionPane.showConfirmDialog(null,
|
---|
| 267 | globalBundle.getString("aeiUpdateAvailable.text"),
|
---|
| 268 | globalBundle.getString("aeiUpdateAvailable.title"),
|
---|
| 269 | JOptionPane.YES_NO_OPTION,
|
---|
| 270 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 271 | if (res == JOptionPane.YES_OPTION) {
|
---|
| 272 | File updater = new File(Paths.getInstallerPath(),
|
---|
| 273 | "AEInstaller2Updater.jar");
|
---|
| 274 | ApplicationInvoker.execute(EExeType.JAR, null, updater,
|
---|
[767] | 275 | null, false);
|
---|
[730] | 276 | return;
|
---|
| 277 | }
|
---|
| 278 | } else if (x == 0) {
|
---|
| 279 | // Up to date
|
---|
| 280 | } else if (x < 0) {
|
---|
| 281 | // No WC at given path
|
---|
| 282 | }
|
---|
| 283 | } catch (Exception e) {
|
---|
| 284 | e.printStackTrace();
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[591] | 288 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 289 | public void run() {
|
---|
| 290 | try {
|
---|
[593] | 291 | MainWin mw = new MainWin();
|
---|
| 292 | if (app != null) {
|
---|
| 293 | app.addAboutMenuItem();
|
---|
| 294 | app.setEnabledAboutMenu(true);
|
---|
| 295 | app.addPreferencesMenuItem();
|
---|
| 296 | app.setEnabledPreferencesMenu(true);
|
---|
| 297 | app.addApplicationListener(mw);
|
---|
| 298 | }
|
---|
| 299 | mw.setVisible(true);
|
---|
[591] | 300 | } catch (Exception e) {
|
---|
| 301 | e.printStackTrace();
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 | });
|
---|
| 305 |
|
---|
| 306 | }
|
---|
| 307 | }
|
---|