[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;
|
---|
| 72 | for (String a : args)
|
---|
| 73 | if (a.equalsIgnoreCase("-debug"))
|
---|
| 74 | debug = true;
|
---|
| 75 | if (!debug) {
|
---|
| 76 | try {
|
---|
[634] | 77 | PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
|
---|
| 78 | "aei_output.log"));
|
---|
| 79 | System.setOut(ps);
|
---|
| 80 | System.setErr(ps);
|
---|
[591] | 81 | } catch (FileNotFoundException e1) {
|
---|
| 82 | e1.printStackTrace();
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[593] | 86 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 87 | initMacOS();
|
---|
| 88 |
|
---|
[637] | 89 | Settings.setDebug(debug);
|
---|
[591] | 90 | Settings.deserializeFromFile();
|
---|
| 91 | Settings.setDebug(debug);
|
---|
| 92 |
|
---|
[592] | 93 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
| 94 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
[640] | 95 | SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
|
---|
[591] | 96 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
|
---|
| 97 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
|
---|
| 98 | JToolBar.Separator.class);
|
---|
| 99 |
|
---|
| 100 | System.setProperty("networkaddress.cache.ttl", "5");
|
---|
| 101 | System.setProperty("networkaddress.cache.negative.ttl", "1");
|
---|
[596] | 102 |
|
---|
[591] | 103 | try {
|
---|
| 104 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
| 105 | (String) null);
|
---|
| 106 | if (laf == null) {
|
---|
[628] | 107 | if (Settings.getPlatform() != Platform.LINUX) {
|
---|
[593] | 108 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
| 109 | } else {
|
---|
| 110 | for (LookAndFeelInfo lafInfo : UIManager
|
---|
| 111 | .getInstalledLookAndFeels()) {
|
---|
| 112 | if (lafInfo.getName().equals("Nimbus"))
|
---|
| 113 | laf = lafInfo.getClassName();
|
---|
| 114 | }
|
---|
[591] | 115 | }
|
---|
| 116 | }
|
---|
| 117 | if (laf == null)
|
---|
| 118 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
| 119 | UIManager.setLookAndFeel(laf);
|
---|
| 120 | } catch (Exception e) {
|
---|
| 121 | e.printStackTrace();
|
---|
| 122 | }
|
---|
| 123 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
| 124 |
|
---|
[637] | 125 | System.out.println(basicBundle.getString("appname") + " "
|
---|
| 126 | + basicBundle.getString("appversion"));
|
---|
[596] | 127 | System.out.println("JarPath: " + Paths.getInstallerPath());
|
---|
| 128 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
| 129 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
| 130 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
| 131 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
[612] | 132 | System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
|
---|
[594] | 133 | System.out.println("Platform: " + Settings.getPlatform());
|
---|
| 134 | System.out.println("Architect: " + Settings.getArchitecture());
|
---|
| 135 | System.out.println(".NET: " + OniSplit.isDotNETInstalled());
|
---|
[602] | 136 | System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
|
---|
[596] | 137 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
[591] | 138 |
|
---|
[624] | 139 | // TODO: Check available space
|
---|
[600] | 140 | System.out
|
---|
| 141 | .println("Free space on temp: "
|
---|
| 142 | + SizeFormatter.format(Paths.getTempPath()
|
---|
| 143 | .getUsableSpace(), 3));
|
---|
| 144 | System.out.println("Free space on Jar: "
|
---|
| 145 | + SizeFormatter.format(Paths.getInstallerPath()
|
---|
| 146 | .getUsableSpace(), 3));
|
---|
[634] | 147 | System.out.println();
|
---|
[600] | 148 |
|
---|
[612] | 149 | if (!OniSplit.isDotNETInstalled()) {
|
---|
| 150 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
| 151 | String dlUrl = "";
|
---|
| 152 | switch (Settings.getPlatform()) {
|
---|
| 153 | case WIN:
|
---|
| 154 | switch (Settings.getArchitecture()) {
|
---|
| 155 | case X86:
|
---|
| 156 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
| 157 | break;
|
---|
| 158 | case AMD64:
|
---|
| 159 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
| 160 | break;
|
---|
| 161 | }
|
---|
| 162 | break;
|
---|
| 163 | default:
|
---|
| 164 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
| 165 | }
|
---|
[640] | 166 | hll.setText(globalBundle
|
---|
[634] | 167 | .getString("dotNetMissing.text")
|
---|
| 168 | .replaceAll(
|
---|
| 169 | "%1",
|
---|
| 170 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
[612] | 171 | JOptionPane.showMessageDialog(null, hll,
|
---|
[640] | 172 | globalBundle.getString("dotNetMissing.title"),
|
---|
[612] | 173 | JOptionPane.ERROR_MESSAGE);
|
---|
| 174 | return;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[603] | 177 | if (!Installer.verifyRunningDirectory()) {
|
---|
[592] | 178 | JOptionPane.showMessageDialog(null,
|
---|
[640] | 179 | globalBundle.getString("invalidPath.text"),
|
---|
| 180 | globalBundle.getString("invalidPath.title"),
|
---|
[592] | 181 | JOptionPane.ERROR_MESSAGE);
|
---|
[625] | 182 | if (!Settings.isDebug()) {
|
---|
[592] | 183 | return;
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[621] | 187 | boolean offline = !DepotManager.getInstance().checkConnection();
|
---|
| 188 | if (offline) {
|
---|
| 189 | JOptionPane.showMessageDialog(null,
|
---|
[640] | 190 | globalBundle.getString("offlineMode.text"),
|
---|
| 191 | globalBundle.getString("offlineMode.title"),
|
---|
[621] | 192 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 193 | }
|
---|
| 194 | Settings.getInstance().setOfflineMode(offline);
|
---|
| 195 |
|
---|
[591] | 196 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 197 | public void run() {
|
---|
| 198 | try {
|
---|
[593] | 199 | MainWin mw = new MainWin();
|
---|
| 200 | if (app != null) {
|
---|
| 201 | app.addAboutMenuItem();
|
---|
| 202 | app.setEnabledAboutMenu(true);
|
---|
| 203 | app.addPreferencesMenuItem();
|
---|
| 204 | app.setEnabledPreferencesMenu(true);
|
---|
| 205 | app.addApplicationListener(mw);
|
---|
| 206 | }
|
---|
| 207 | mw.setVisible(true);
|
---|
[591] | 208 | } catch (Exception e) {
|
---|
| 209 | e.printStackTrace();
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | });
|
---|
| 213 |
|
---|
| 214 | }
|
---|
| 215 | }
|
---|