| 1 | package net.oni2.aeinstaller; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | import java.awt.image.BufferedImage; | 
 
 
 
 
 | 4 | import java.io.File; | 
 
 
 
 
 | 5 | import java.io.FileNotFoundException; | 
 
 
 
 
 | 6 | import java.io.IOException; | 
 
 
 
 
 | 7 | import java.io.PrintStream; | 
 
 
 
 
 | 8 | import java.net.URL; | 
 
 
 
 
 | 9 | import java.util.ResourceBundle; | 
 
 
 
 
 | 10 | import java.util.TreeSet; | 
 
 
 
 
 | 11 |  | 
 
 
 
 
 | 12 | import javax.imageio.ImageIO; | 
 
 
 
 
 | 13 | import javax.swing.JFrame; | 
 
 
 
 
 | 14 | import javax.swing.JOptionPane; | 
 
 
 
 
 | 15 | import javax.swing.JToolBar; | 
 
 
 
 
 | 16 | import javax.swing.SwingUtilities; | 
 
 
 
 
 | 17 | import javax.swing.UIManager; | 
 
 
 
 
 | 18 | import javax.swing.UIManager.LookAndFeelInfo; | 
 
 
 
 
 | 19 |  | 
 
 
 
 
 | 20 | import net.oni2.aeinstaller.backend.Paths; | 
 
 
 
 
 | 21 | import net.oni2.aeinstaller.backend.Settings; | 
 
 
 
 
 | 22 | import net.oni2.aeinstaller.backend.SizeFormatter; | 
 
 
 
 
 | 23 | import net.oni2.aeinstaller.backend.Settings.Platform; | 
 
 
 
 
 | 24 | import net.oni2.aeinstaller.backend.StuffToRefactorLater; | 
 
 
 
 
 | 25 | import net.oni2.aeinstaller.backend.depot.DepotManager; | 
 
 
 
 
 | 26 | import net.oni2.aeinstaller.backend.mods.Mod; | 
 
 
 
 
 | 27 | import net.oni2.aeinstaller.backend.oni.Installer; | 
 
 
 
 
 | 28 | import net.oni2.aeinstaller.backend.oni.OniSplit; | 
 
 
 
 
 | 29 | import net.oni2.aeinstaller.gui.MainWin; | 
 
 
 
 
 | 30 |  | 
 
 
 
 
 | 31 | import org.javabuilders.swing.SwingJavaBuilder; | 
 
 
 
 
 | 32 | import org.simplericity.macify.eawt.Application; | 
 
 
 
 
 | 33 | import org.simplericity.macify.eawt.DefaultApplication; | 
 
 
 
 
 | 34 |  | 
 
 
 
 
 | 35 | /** | 
 
 
 
 
 | 36 | * @author Christian Illy | 
 
 
 
 
 | 37 | */ | 
 
 
 
 
 | 38 | public class AEInstaller2 { | 
 
 
 
 
 | 39 |  | 
 
 
 
 
 | 40 | private static ResourceBundle imagesBundle = ResourceBundle | 
 
 
 
 
 | 41 | .getBundle(AEInstaller2.class.getPackage().getName() + ".Images"); | 
 
 
 
 
 | 42 | private static ResourceBundle basicBundle = ResourceBundle | 
 
 
 
 
 | 43 | .getBundle(AEInstaller2.class.getPackage().getName() | 
 
 
 
 
 | 44 | + ".AEInstaller"); | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 54 | URL icon = AEInstaller2.class.getResource("images/AElogo.png"); | 
 
 
 
 
 | 55 | try { | 
 
 
 
 
 | 56 | BufferedImage img = ImageIO.read(icon); | 
 
 
 
 
 | 57 | app.setApplicationIconImage(img); | 
 
 
 
 
 | 58 | } catch (IOException e) { | 
 
 
 
 
 | 59 | // TODO Auto-generated catch block | 
 
 
 
 
 | 60 | e.printStackTrace(); | 
 
 
 
 
 | 61 | } | 
 
 
 
 
 | 62 | } | 
 
 
 
 
 | 63 |  | 
 
 
 
 
 | 64 | /** | 
 
 
 
 
 | 65 | * @param args | 
 
 
 
 
 | 66 | *            Command line arguments | 
 
 
 
 
 | 67 | */ | 
 
 
 
 
 | 68 | public static void main(String[] args) { | 
 
 
 
 
 | 69 | Paths.getPrefsPath().mkdirs(); | 
 
 
 
 
 | 70 | Paths.getDownloadPath().mkdirs(); | 
 
 
 
 
 | 71 |  | 
 
 
 
 
 | 72 | boolean debug = false; | 
 
 
 
 
 | 73 | for (String a : args) | 
 
 
 
 
 | 74 | if (a.equalsIgnoreCase("-debug")) | 
 
 
 
 
 | 75 | debug = true; | 
 
 
 
 
 | 76 | if (!debug) { | 
 
 
 
 
 | 77 | try { | 
 
 
 
 
 | 78 | System.setOut(new PrintStream(new File(Paths.getPrefsPath(), | 
 
 
 
 
 | 79 | "aei_output.log"))); | 
 
 
 
 
 | 80 | System.setErr(new PrintStream(new File(Paths.getPrefsPath(), | 
 
 
 
 
 | 81 | "aei_error.log"))); | 
 
 
 
 
 | 82 | } catch (FileNotFoundException e1) { | 
 
 
 
 
 | 83 | e1.printStackTrace(); | 
 
 
 
 
 | 84 | } | 
 
 
 
 
 | 85 | } | 
 
 
 
 
 | 86 |  | 
 
 
 
 
 | 87 | if (Settings.getPlatform() == Platform.MACOS) | 
 
 
 
 
 | 88 | initMacOS(); | 
 
 
 
 
 | 89 |  | 
 
 
 
 
 | 90 | Settings.deserializeFromFile(); | 
 
 
 
 
 | 91 | Settings.setDebug(debug); | 
 
 
 
 
 | 92 | DepotManager.getInstance().loadFromFile( | 
 
 
 
 
 | 93 | Settings.getDepotCacheFilename()); | 
 
 
 
 
 | 94 |  | 
 
 
 
 
 | 95 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle); | 
 
 
 
 
 | 96 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle); | 
 
 
 
 
 | 97 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true); | 
 
 
 
 
 | 98 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator", | 
 
 
 
 
 | 99 | JToolBar.Separator.class); | 
 
 
 
 
 | 100 |  | 
 
 
 
 
 | 101 | System.setProperty("networkaddress.cache.ttl", "5"); | 
 
 
 
 
 | 102 | System.setProperty("networkaddress.cache.negative.ttl", "1"); | 
 
 
 
 
 | 103 |  | 
 
 
 
 
 | 104 | try { | 
 
 
 
 
 | 105 | String laf = Settings.getInstance().get("lookandfeel", | 
 
 
 
 
 | 106 | (String) null); | 
 
 
 
 
 | 107 | if (laf == null) { | 
 
 
 
 
 | 108 | if (Settings.getPlatform() == Platform.MACOS) { | 
 
 
 
 
 | 109 | laf = UIManager.getSystemLookAndFeelClassName(); | 
 
 
 
 
 | 110 | } else { | 
 
 
 
 
 | 111 | for (LookAndFeelInfo lafInfo : UIManager | 
 
 
 
 
 | 112 | .getInstalledLookAndFeels()) { | 
 
 
 
 
 | 113 | if (lafInfo.getName().equals("Nimbus")) | 
 
 
 
 
 | 114 | laf = lafInfo.getClassName(); | 
 
 
 
 
 | 115 | } | 
 
 
 
 
 | 116 | } | 
 
 
 
 
 | 117 | } | 
 
 
 
 
 | 118 | if (laf == null) | 
 
 
 
 
 | 119 | laf = UIManager.getSystemLookAndFeelClassName(); | 
 
 
 
 
 | 120 | UIManager.setLookAndFeel(laf); | 
 
 
 
 
 | 121 | } catch (Exception e) { | 
 
 
 
 
 | 122 | e.printStackTrace(); | 
 
 
 
 
 | 123 | } | 
 
 
 
 
 | 124 | JFrame.setDefaultLookAndFeelDecorated(true); | 
 
 
 
 
 | 125 |  | 
 
 
 
 
 | 126 | // TODO | 
 
 
 
 
 | 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()); | 
 
 
 
 
 | 132 | System.out.println("ValidPath: " | 
 
 
 
 
 | 133 | + StuffToRefactorLater.verifyRunningDirectory()); | 
 
 
 
 
 | 134 | System.out.println("Platform:  " + Settings.getPlatform()); | 
 
 
 
 
 | 135 | System.out.println("Architect: " + Settings.getArchitecture()); | 
 
 
 
 
 | 136 | System.out.println(".NET:      " + OniSplit.isDotNETInstalled()); | 
 
 
 
 
 | 137 | System.out.println("Globalized:" + Installer.isEditionInitialized()); | 
 
 
 
 
 | 138 |  | 
 
 
 
 
 | 139 | System.out.println("Free space on temp: " + SizeFormatter.format(Paths.getTempPath().getUsableSpace(), 3)); | 
 
 
 
 
 | 140 | System.out.println("Free space on Jar:  " + SizeFormatter.format(Paths.getInstallerPath().getUsableSpace(), 3)); | 
 
 
 
 
 | 141 |  | 
 
 
 
 
 | 142 | if (!StuffToRefactorLater.verifyRunningDirectory()) { | 
 
 
 
 
 | 143 | JOptionPane.showMessageDialog(null, | 
 
 
 
 
 | 144 | basicBundle.getString("invalidPath.text"), | 
 
 
 
 
 | 145 | basicBundle.getString("invalidPath.title"), | 
 
 
 
 
 | 146 | JOptionPane.ERROR_MESSAGE); | 
 
 
 
 
 | 147 | if (!Settings.getDebug()) { | 
 
 
 
 
 | 148 | return; | 
 
 
 
 
 | 149 | } | 
 
 
 
 
 | 150 | } else { | 
 
 
 
 
 | 151 | Installer.initializeEdition(); | 
 
 
 
 
 | 152 | Installer.install(new TreeSet<Mod>()); | 
 
 
 
 
 | 153 | } | 
 
 
 
 
 | 154 |  | 
 
 
 
 
 | 155 | SwingUtilities.invokeLater(new Runnable() { | 
 
 
 
 
 | 156 |  | 
 
 
 
 
 | 157 | public void run() { | 
 
 
 
 
 | 158 | try { | 
 
 
 
 
 | 159 | MainWin mw = new MainWin(); | 
 
 
 
 
 | 160 | if (app != null) { | 
 
 
 
 
 | 161 | app.addAboutMenuItem(); | 
 
 
 
 
 | 162 | app.setEnabledAboutMenu(true); | 
 
 
 
 
 | 163 | app.addPreferencesMenuItem(); | 
 
 
 
 
 | 164 | app.setEnabledPreferencesMenu(true); | 
 
 
 
 
 | 165 | app.addApplicationListener(mw); | 
 
 
 
 
 | 166 | } | 
 
 
 
 
 | 167 | mw.setVisible(true); | 
 
 
 
 
 | 168 | } catch (Exception e) { | 
 
 
 
 
 | 169 | e.printStackTrace(); | 
 
 
 
 
 | 170 | } | 
 
 
 
 
 | 171 | } | 
 
 
 
 
 | 172 | }); | 
 
 
 
 
 | 173 |  | 
 
 
 
 
 | 174 | } | 
 
 
 
 
 | 175 | } |