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