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