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