[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;
|
---|
[598] | 10 | import java.util.TreeSet;
|
---|
[591] | 11 |
|
---|
[593] | 12 | import javax.imageio.ImageIO;
|
---|
[591] | 13 | import javax.swing.JFrame;
|
---|
[592] | 14 | import javax.swing.JOptionPane;
|
---|
[591] | 15 | import javax.swing.JToolBar;
|
---|
| 16 | import javax.swing.SwingUtilities;
|
---|
| 17 | import javax.swing.UIManager;
|
---|
| 18 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
| 19 |
|
---|
[596] | 20 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 21 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[593] | 22 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[591] | 23 | import net.oni2.aeinstaller.backend.StuffToRefactorLater;
|
---|
| 24 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
[598] | 25 | import net.oni2.aeinstaller.backend.mods.Mod;
|
---|
[596] | 26 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
| 27 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[591] | 28 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
| 29 |
|
---|
| 30 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 31 | import org.simplericity.macify.eawt.Application;
|
---|
| 32 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
[591] | 33 |
|
---|
| 34 | /**
|
---|
| 35 | * @author Christian Illy
|
---|
| 36 | */
|
---|
| 37 | public class AEInstaller2 {
|
---|
| 38 |
|
---|
[593] | 39 | private static ResourceBundle imagesBundle = ResourceBundle
|
---|
| 40 | .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
|
---|
| 41 | private static ResourceBundle basicBundle = ResourceBundle
|
---|
| 42 | .getBundle(AEInstaller2.class.getPackage().getName()
|
---|
| 43 | + ".AEInstaller");
|
---|
| 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 |
|
---|
| 53 | URL icon = AEInstaller2.class.getResource("images/AElogo.png");
|
---|
| 54 | try {
|
---|
| 55 | BufferedImage img = ImageIO.read(icon);
|
---|
| 56 | app.setApplicationIconImage(img);
|
---|
| 57 | } catch (IOException e) {
|
---|
| 58 | // TODO Auto-generated catch block
|
---|
| 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 {
|
---|
[596] | 77 | System.setOut(new PrintStream(new File(Paths.getPrefsPath(),
|
---|
| 78 | "aei_output.log")));
|
---|
| 79 | System.setErr(new PrintStream(new File(Paths.getPrefsPath(),
|
---|
| 80 | "aei_error.log")));
|
---|
[591] | 81 | } catch (FileNotFoundException e1) {
|
---|
| 82 | e1.printStackTrace();
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[593] | 86 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 87 | initMacOS();
|
---|
| 88 |
|
---|
[591] | 89 | Settings.deserializeFromFile();
|
---|
| 90 | Settings.setDebug(debug);
|
---|
| 91 | DepotManager.getInstance().loadFromFile(
|
---|
[596] | 92 | Settings.getDepotCacheFilename());
|
---|
[591] | 93 |
|
---|
[592] | 94 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
| 95 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
[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) {
|
---|
[593] | 107 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 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 |
|
---|
| 125 | // TODO
|
---|
[596] | 126 | System.out.println("JarPath: " + Paths.getInstallerPath());
|
---|
| 127 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
| 128 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
| 129 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
| 130 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
[591] | 131 | System.out.println("ValidPath: "
|
---|
| 132 | + StuffToRefactorLater.verifyRunningDirectory());
|
---|
[594] | 133 | System.out.println("Platform: " + Settings.getPlatform());
|
---|
| 134 | System.out.println("Architect: " + Settings.getArchitecture());
|
---|
| 135 | System.out.println(".NET: " + OniSplit.isDotNETInstalled());
|
---|
[596] | 136 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
[591] | 137 |
|
---|
[592] | 138 | if (!StuffToRefactorLater.verifyRunningDirectory()) {
|
---|
| 139 | JOptionPane.showMessageDialog(null,
|
---|
| 140 | basicBundle.getString("invalidPath.text"),
|
---|
| 141 | basicBundle.getString("invalidPath.title"),
|
---|
| 142 | JOptionPane.ERROR_MESSAGE);
|
---|
| 143 | if (!Settings.getDebug()) {
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
[596] | 146 | } else {
|
---|
[598] | 147 | // Installer.initializeEdition();
|
---|
| 148 | Installer.install(new TreeSet<Mod>());
|
---|
[592] | 149 | }
|
---|
| 150 |
|
---|
[591] | 151 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 152 |
|
---|
| 153 | public void run() {
|
---|
| 154 | try {
|
---|
[593] | 155 | MainWin mw = new MainWin();
|
---|
| 156 | if (app != null) {
|
---|
| 157 | app.addAboutMenuItem();
|
---|
| 158 | app.setEnabledAboutMenu(true);
|
---|
| 159 | app.addPreferencesMenuItem();
|
---|
| 160 | app.setEnabledPreferencesMenu(true);
|
---|
| 161 | app.addApplicationListener(mw);
|
---|
| 162 | }
|
---|
| 163 | mw.setVisible(true);
|
---|
[591] | 164 | } catch (Exception e) {
|
---|
| 165 | e.printStackTrace();
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | });
|
---|
| 169 |
|
---|
| 170 | }
|
---|
| 171 | }
|
---|