[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 |
|
---|
[672] | 23 | import net.oni2.aeinstaller.backend.DotNet;
|
---|
[596] | 24 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 25 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[600] | 26 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[599] | 27 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[591] | 28 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
[596] | 29 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
| 30 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[612] | 31 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
---|
[591] | 32 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
| 33 |
|
---|
| 34 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 35 | import org.simplericity.macify.eawt.Application;
|
---|
| 36 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
[591] | 37 |
|
---|
| 38 | /**
|
---|
| 39 | * @author Christian Illy
|
---|
| 40 | */
|
---|
| 41 | public class AEInstaller2 {
|
---|
| 42 |
|
---|
[651] | 43 | private static ResourceBundle imagesBundle;
|
---|
| 44 | private static ResourceBundle basicBundle;
|
---|
| 45 | private static ResourceBundle globalBundle;
|
---|
[593] | 46 |
|
---|
| 47 | private static Application app = null;
|
---|
| 48 |
|
---|
| 49 | private static void initMacOS() {
|
---|
| 50 | System.setProperty("apple.laf.useScreenMenuBar", "true");
|
---|
| 51 | System.setProperty("com.apple.mrj.application.apple.menu.about.name",
|
---|
| 52 | basicBundle.getString("appname"));
|
---|
| 53 | app = new DefaultApplication();
|
---|
| 54 |
|
---|
[637] | 55 | URL icon = AEInstaller2.class.getResource(imagesBundle
|
---|
| 56 | .getString("img.ae"));
|
---|
[593] | 57 | try {
|
---|
| 58 | BufferedImage img = ImageIO.read(icon);
|
---|
| 59 | app.setApplicationIconImage(img);
|
---|
| 60 | } catch (IOException e) {
|
---|
| 61 | e.printStackTrace();
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
[653] | 64 |
|
---|
| 65 | private static void initBundles() {
|
---|
| 66 | File localesDir = new File(Paths.getInstallerPath(), "locales");
|
---|
| 67 | if (localesDir.isDirectory())
|
---|
| 68 | addClassPath(localesDir);
|
---|
| 69 | imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
|
---|
| 70 | basicBundle = ResourceBundle
|
---|
| 71 | .getBundle("net.oni2.aeinstaller.AEInstaller");
|
---|
| 72 | globalBundle = ResourceBundle
|
---|
| 73 | .getBundle("net.oni2.aeinstaller.localization.Global");
|
---|
| 74 | }
|
---|
[593] | 75 |
|
---|
[651] | 76 | private static void addClassPath(File dir) {
|
---|
| 77 | try {
|
---|
| 78 | URL u = dir.toURI().toURL();
|
---|
| 79 | URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader
|
---|
| 80 | .getSystemClassLoader();
|
---|
| 81 | Class<URLClassLoader> urlClass = URLClassLoader.class;
|
---|
| 82 | Method method = urlClass.getDeclaredMethod("addURL",
|
---|
| 83 | new Class[] { URL.class });
|
---|
| 84 | method.setAccessible(true);
|
---|
| 85 | method.invoke(urlClassLoader, new Object[] { u });
|
---|
| 86 | } catch (MalformedURLException e) {
|
---|
| 87 | } catch (SecurityException e) {
|
---|
| 88 | } catch (NoSuchMethodException e) {
|
---|
| 89 | } catch (IllegalArgumentException e) {
|
---|
| 90 | } catch (IllegalAccessException e) {
|
---|
| 91 | } catch (InvocationTargetException e) {
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[591] | 95 | /**
|
---|
| 96 | * @param args
|
---|
| 97 | * Command line arguments
|
---|
| 98 | */
|
---|
| 99 | public static void main(String[] args) {
|
---|
[596] | 100 | Paths.getPrefsPath().mkdirs();
|
---|
| 101 | Paths.getDownloadPath().mkdirs();
|
---|
[591] | 102 |
|
---|
| 103 | boolean debug = false;
|
---|
[649] | 104 | boolean noCacheUpdate = false;
|
---|
| 105 | for (String a : args) {
|
---|
[591] | 106 | if (a.equalsIgnoreCase("-debug"))
|
---|
| 107 | debug = true;
|
---|
[649] | 108 | if (a.equalsIgnoreCase("-nocacheupdate"))
|
---|
| 109 | noCacheUpdate = true;
|
---|
| 110 | }
|
---|
[591] | 111 | if (!debug) {
|
---|
| 112 | try {
|
---|
[634] | 113 | PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
|
---|
| 114 | "aei_output.log"));
|
---|
| 115 | System.setOut(ps);
|
---|
| 116 | System.setErr(ps);
|
---|
[591] | 117 | } catch (FileNotFoundException e1) {
|
---|
| 118 | e1.printStackTrace();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
[653] | 121 |
|
---|
| 122 | initBundles();
|
---|
[591] | 123 |
|
---|
[593] | 124 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 125 | initMacOS();
|
---|
| 126 |
|
---|
[637] | 127 | Settings.setDebug(debug);
|
---|
[591] | 128 | Settings.deserializeFromFile();
|
---|
| 129 | Settings.setDebug(debug);
|
---|
[649] | 130 | Settings.getInstance().setNoCacheUpdateMode(noCacheUpdate);
|
---|
[591] | 131 |
|
---|
[592] | 132 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
| 133 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
[640] | 134 | SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
|
---|
[591] | 135 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
|
---|
| 136 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
|
---|
| 137 | JToolBar.Separator.class);
|
---|
| 138 |
|
---|
| 139 | System.setProperty("networkaddress.cache.ttl", "5");
|
---|
| 140 | System.setProperty("networkaddress.cache.negative.ttl", "1");
|
---|
[596] | 141 |
|
---|
[591] | 142 | try {
|
---|
| 143 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
| 144 | (String) null);
|
---|
| 145 | if (laf == null) {
|
---|
[628] | 146 | if (Settings.getPlatform() != Platform.LINUX) {
|
---|
[593] | 147 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
| 148 | } else {
|
---|
| 149 | for (LookAndFeelInfo lafInfo : UIManager
|
---|
| 150 | .getInstalledLookAndFeels()) {
|
---|
| 151 | if (lafInfo.getName().equals("Nimbus"))
|
---|
| 152 | laf = lafInfo.getClassName();
|
---|
| 153 | }
|
---|
[591] | 154 | }
|
---|
| 155 | }
|
---|
| 156 | if (laf == null)
|
---|
| 157 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
| 158 | UIManager.setLookAndFeel(laf);
|
---|
| 159 | } catch (Exception e) {
|
---|
| 160 | e.printStackTrace();
|
---|
| 161 | }
|
---|
| 162 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
| 163 |
|
---|
[637] | 164 | System.out.println(basicBundle.getString("appname") + " "
|
---|
| 165 | + basicBundle.getString("appversion"));
|
---|
[596] | 166 | System.out.println("JarPath: " + Paths.getInstallerPath());
|
---|
| 167 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
| 168 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
| 169 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
| 170 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
[612] | 171 | System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
|
---|
[594] | 172 | System.out.println("Platform: " + Settings.getPlatform());
|
---|
| 173 | System.out.println("Architect: " + Settings.getArchitecture());
|
---|
[672] | 174 | System.out.println(".NET: " + DotNet.isInstalled());
|
---|
[602] | 175 | System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
|
---|
[596] | 176 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
[591] | 177 |
|
---|
[624] | 178 | // TODO: Check available space
|
---|
[600] | 179 | System.out
|
---|
| 180 | .println("Free space on temp: "
|
---|
| 181 | + SizeFormatter.format(Paths.getTempPath()
|
---|
| 182 | .getUsableSpace(), 3));
|
---|
| 183 | System.out.println("Free space on Jar: "
|
---|
| 184 | + SizeFormatter.format(Paths.getInstallerPath()
|
---|
| 185 | .getUsableSpace(), 3));
|
---|
[634] | 186 | System.out.println();
|
---|
[600] | 187 |
|
---|
[672] | 188 | if (!DotNet.isInstalled()) {
|
---|
[612] | 189 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
| 190 | String dlUrl = "";
|
---|
| 191 | switch (Settings.getPlatform()) {
|
---|
| 192 | case WIN:
|
---|
| 193 | switch (Settings.getArchitecture()) {
|
---|
| 194 | case X86:
|
---|
| 195 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
| 196 | break;
|
---|
| 197 | case AMD64:
|
---|
| 198 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
| 199 | break;
|
---|
| 200 | }
|
---|
| 201 | break;
|
---|
| 202 | default:
|
---|
| 203 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
| 204 | }
|
---|
[640] | 205 | hll.setText(globalBundle
|
---|
[634] | 206 | .getString("dotNetMissing.text")
|
---|
| 207 | .replaceAll(
|
---|
| 208 | "%1",
|
---|
| 209 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
[612] | 210 | JOptionPane.showMessageDialog(null, hll,
|
---|
[640] | 211 | globalBundle.getString("dotNetMissing.title"),
|
---|
[612] | 212 | JOptionPane.ERROR_MESSAGE);
|
---|
| 213 | return;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[603] | 216 | if (!Installer.verifyRunningDirectory()) {
|
---|
[592] | 217 | JOptionPane.showMessageDialog(null,
|
---|
[640] | 218 | globalBundle.getString("invalidPath.text"),
|
---|
| 219 | globalBundle.getString("invalidPath.title"),
|
---|
[592] | 220 | JOptionPane.ERROR_MESSAGE);
|
---|
[625] | 221 | if (!Settings.isDebug()) {
|
---|
[592] | 222 | return;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[649] | 226 | boolean offline = false;
|
---|
[648] | 227 | for (String a : args)
|
---|
| 228 | if (a.equalsIgnoreCase("-offline"))
|
---|
[649] | 229 | offline = true;
|
---|
| 230 | if (!offline) {
|
---|
| 231 | offline = !DepotManager.getInstance().checkConnection();
|
---|
| 232 | }
|
---|
| 233 | if (offline) {
|
---|
[621] | 234 | JOptionPane.showMessageDialog(null,
|
---|
[646] | 235 | globalBundle.getString("offlineModeStartup.text"),
|
---|
| 236 | globalBundle.getString("offlineModeStartup.title"),
|
---|
[621] | 237 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 238 | }
|
---|
[649] | 239 | Settings.getInstance().setOfflineMode(offline);
|
---|
[621] | 240 |
|
---|
[591] | 241 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 242 | public void run() {
|
---|
| 243 | try {
|
---|
[593] | 244 | MainWin mw = new MainWin();
|
---|
| 245 | if (app != null) {
|
---|
| 246 | app.addAboutMenuItem();
|
---|
| 247 | app.setEnabledAboutMenu(true);
|
---|
| 248 | app.addPreferencesMenuItem();
|
---|
| 249 | app.setEnabledPreferencesMenu(true);
|
---|
| 250 | app.addApplicationListener(mw);
|
---|
| 251 | }
|
---|
| 252 | mw.setVisible(true);
|
---|
[591] | 253 | } catch (Exception e) {
|
---|
| 254 | e.printStackTrace();
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 | });
|
---|
| 258 |
|
---|
| 259 | }
|
---|
| 260 | }
|
---|