[591] | 1 | package net.oni2.aeinstaller.gui;
|
---|
| 2 |
|
---|
[627] | 3 | import java.awt.BorderLayout;
|
---|
[608] | 4 | import java.awt.Desktop;
|
---|
[632] | 5 | import java.awt.GridLayout;
|
---|
[608] | 6 | import java.awt.event.ActionEvent;
|
---|
[627] | 7 | import java.awt.event.ItemEvent;
|
---|
| 8 | import java.awt.event.ItemListener;
|
---|
[604] | 9 | import java.io.File;
|
---|
[623] | 10 | import java.net.URL;
|
---|
[634] | 11 | import java.util.Date;
|
---|
[605] | 12 | import java.util.HashMap;
|
---|
| 13 | import java.util.HashSet;
|
---|
[591] | 14 | import java.util.ResourceBundle;
|
---|
| 15 | import java.util.TreeMap;
|
---|
[600] | 16 | import java.util.TreeSet;
|
---|
[605] | 17 | import java.util.Vector;
|
---|
[591] | 18 |
|
---|
[623] | 19 | import javax.swing.AbstractAction;
|
---|
| 20 | import javax.swing.Icon;
|
---|
| 21 | import javax.swing.ImageIcon;
|
---|
[600] | 22 | import javax.swing.JButton;
|
---|
[627] | 23 | import javax.swing.JCheckBox;
|
---|
[591] | 24 | import javax.swing.JComboBox;
|
---|
[604] | 25 | import javax.swing.JFileChooser;
|
---|
[591] | 26 | import javax.swing.JFrame;
|
---|
[592] | 27 | import javax.swing.JLabel;
|
---|
[593] | 28 | import javax.swing.JMenu;
|
---|
[608] | 29 | import javax.swing.JMenuItem;
|
---|
[593] | 30 | import javax.swing.JOptionPane;
|
---|
[627] | 31 | import javax.swing.JPanel;
|
---|
[630] | 32 | import javax.swing.JRadioButton;
|
---|
[592] | 33 | import javax.swing.JSplitPane;
|
---|
[591] | 34 | import javax.swing.SwingUtilities;
|
---|
[631] | 35 | import javax.swing.ToolTipManager;
|
---|
[604] | 36 | import javax.swing.filechooser.FileFilter;
|
---|
[591] | 37 |
|
---|
[623] | 38 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
| 39 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[604] | 40 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 41 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[593] | 42 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[600] | 43 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[591] | 44 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
[600] | 45 | import net.oni2.aeinstaller.backend.mods.Mod;
|
---|
| 46 | import net.oni2.aeinstaller.backend.mods.ModManager;
|
---|
| 47 | import net.oni2.aeinstaller.backend.mods.Type;
|
---|
[604] | 48 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
|
---|
| 49 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
|
---|
| 50 | import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
|
---|
[600] | 51 | import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
|
---|
| 52 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
[621] | 53 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[593] | 54 | import net.oni2.aeinstaller.gui.about.AboutDialog;
|
---|
[605] | 55 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[646] | 56 | import net.oni2.aeinstaller.gui.mandatorypackages.MandatoryPackagesDialog;
|
---|
[600] | 57 | import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
|
---|
[631] | 58 | import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
|
---|
| 59 | import net.oni2.aeinstaller.gui.modtable.ModTable;
|
---|
[591] | 60 | import net.oni2.aeinstaller.gui.settings.SettingsDialog;
|
---|
[625] | 61 | import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
|
---|
[591] | 62 |
|
---|
| 63 | import org.javabuilders.BuildResult;
|
---|
| 64 | import org.javabuilders.annotations.DoInBackground;
|
---|
| 65 | import org.javabuilders.event.BackgroundEvent;
|
---|
| 66 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 67 | import org.simplericity.macify.eawt.ApplicationEvent;
|
---|
| 68 | import org.simplericity.macify.eawt.ApplicationListener;
|
---|
[591] | 69 |
|
---|
| 70 | /**
|
---|
| 71 | * @author Christian Illy
|
---|
| 72 | */
|
---|
[600] | 73 | public class MainWin extends JFrame implements ApplicationListener,
|
---|
[631] | 74 | DownloadSizeListener, ModSelectionListener {
|
---|
[591] | 75 | private static final long serialVersionUID = -4027395051382659650L;
|
---|
| 76 |
|
---|
[629] | 77 | private ResourceBundle bundle = ResourceBundle
|
---|
| 78 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 79 | + getClass().getSimpleName());
|
---|
[591] | 80 | @SuppressWarnings("unused")
|
---|
| 81 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 82 |
|
---|
[593] | 83 | private JMenu mainMenu;
|
---|
[623] | 84 | private JMenu toolsMenu;
|
---|
[641] | 85 | private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
|
---|
[593] | 86 |
|
---|
[592] | 87 | private JSplitPane contents;
|
---|
| 88 |
|
---|
[591] | 89 | private JComboBox cmbModTypes;
|
---|
[630] | 90 | private JRadioButton radAll;
|
---|
| 91 | private JRadioButton radOnline;
|
---|
| 92 | private JRadioButton radLocal;
|
---|
[631] | 93 | private ModTable tblMods;
|
---|
[600] | 94 | private JLabel lblDownloadSizeVal;
|
---|
[591] | 95 |
|
---|
[639] | 96 | private JLabel lblTitleVal;
|
---|
[592] | 97 | private JLabel lblCreatorVal;
|
---|
[606] | 98 | private JLabel lblTypesVal;
|
---|
| 99 | private JLabel lblPlatformVal;
|
---|
[621] | 100 | private JLabel lblPackageNumberVal;
|
---|
[638] | 101 | private JLabel lblVersionNumberVal;
|
---|
[592] | 102 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 103 |
|
---|
[600] | 104 | private JButton btnInstall;
|
---|
| 105 |
|
---|
[645] | 106 | private TreeSet<Mod> execMandatoryUpdates = new TreeSet<Mod>();
|
---|
[621] | 107 | private TreeSet<Mod> execUpdates = null;
|
---|
| 108 |
|
---|
[641] | 109 | private enum EInstallState {
|
---|
[621] | 110 | DONE,
|
---|
[641] | 111 | READY,
|
---|
| 112 | ABORTED,
|
---|
[621] | 113 | OFFLINE,
|
---|
[641] | 114 | INCOMPATIBLE,
|
---|
| 115 | CHECKING
|
---|
[621] | 116 | };
|
---|
| 117 |
|
---|
[641] | 118 | private EInstallState installState = EInstallState.DONE;
|
---|
| 119 | private TreeSet<Mod> installMods = null;
|
---|
[646] | 120 | private TreeSet<Mod> installDeps = null;
|
---|
[621] | 121 |
|
---|
[591] | 122 | /**
|
---|
| 123 | * Constructor of main window.
|
---|
| 124 | */
|
---|
| 125 | public MainWin() {
|
---|
[593] | 126 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 127 | + " - v"
|
---|
| 128 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 129 |
|
---|
[640] | 130 | setSize(getWidth() + 150, getHeight());
|
---|
[637] | 131 | contents.setDividerLocation(500);
|
---|
[631] | 132 | contents.setResizeWeight(0.4);
|
---|
[593] | 133 |
|
---|
| 134 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 135 | mainMenu.setVisible(false);
|
---|
| 136 | }
|
---|
[600] | 137 |
|
---|
[631] | 138 | ToolTipManager.sharedInstance().setInitialDelay(250);
|
---|
| 139 |
|
---|
[600] | 140 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 141 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[630] | 142 | radAll.setSelected(true);
|
---|
[631] | 143 |
|
---|
| 144 | tblMods.addModSelectionListener(this);
|
---|
| 145 | tblMods.addDownloadSizeListener(this);
|
---|
[591] | 146 | }
|
---|
| 147 |
|
---|
| 148 | private void initModTypeBox() {
|
---|
[592] | 149 | cmbModTypes.removeAllItems();
|
---|
| 150 |
|
---|
[600] | 151 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
| 152 | for (Type t : ModManager.getInstance().getTypesWithContent()) {
|
---|
| 153 | types.put(t.getName(), t);
|
---|
[591] | 154 | }
|
---|
[630] | 155 | cmbModTypes.addItem("-All-");
|
---|
[600] | 156 | for (Type t : types.values()) {
|
---|
[591] | 157 | cmbModTypes.addItem(t);
|
---|
| 158 | }
|
---|
| 159 | cmbModTypes.setSelectedIndex(0);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | private void exit() {
|
---|
| 163 | dispose();
|
---|
[608] | 164 | System.exit(0);
|
---|
[591] | 165 | }
|
---|
| 166 |
|
---|
| 167 | private void saveLocalData() {
|
---|
| 168 | Settings.getInstance().serializeToFile();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 172 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
[621] | 173 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
[634] | 174 | long start = new Date().getTime();
|
---|
| 175 |
|
---|
[621] | 176 | try {
|
---|
[634] | 177 | DepotManager.getInstance().updateInformation(false);
|
---|
[621] | 178 | } catch (Exception e) {
|
---|
| 179 | e.printStackTrace();
|
---|
| 180 | }
|
---|
[634] | 181 |
|
---|
| 182 | System.out.println("Took: " + (new Date().getTime() - start)
|
---|
| 183 | + " msec");
|
---|
[621] | 184 | }
|
---|
[633] | 185 |
|
---|
[621] | 186 | ModManager.getInstance().init();
|
---|
[631] | 187 | tblMods.reloadData();
|
---|
[621] | 188 | initModTypeBox();
|
---|
[600] | 189 |
|
---|
[621] | 190 | tblMods.setVisible(true);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | @SuppressWarnings("unused")
|
---|
| 194 | private void checkUpdates(Object evtSource) {
|
---|
| 195 | if ((evtSource != this)
|
---|
| 196 | || Settings.getInstance().get("notifyupdates", true)) {
|
---|
| 197 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 198 | if (evtSource != this) {
|
---|
| 199 | JOptionPane.showMessageDialog(this,
|
---|
| 200 | bundle.getString("offlineMode.text"),
|
---|
| 201 | bundle.getString("offlineMode.title"),
|
---|
| 202 | JOptionPane.WARNING_MESSAGE);
|
---|
| 203 | }
|
---|
| 204 | } else {
|
---|
| 205 | TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
|
---|
| 206 | TreeSet<Mod> tools = ModManager.getInstance()
|
---|
| 207 | .getUpdatableTools();
|
---|
| 208 | int size = 0;
|
---|
[632] | 209 | JPanel panPackages = new JPanel(new GridLayout(0, 1));
|
---|
| 210 | execUpdates = new TreeSet<Mod>();
|
---|
| 211 | execUpdates.addAll(mods);
|
---|
| 212 | execUpdates.addAll(tools);
|
---|
| 213 | for (final Mod m : mods) {
|
---|
[621] | 214 | size += m.getZipSize();
|
---|
[632] | 215 | JCheckBox check = new JCheckBox("Mod: " + m.getName());
|
---|
| 216 | check.setSelected(true);
|
---|
| 217 | check.addItemListener(new ItemListener() {
|
---|
| 218 | @Override
|
---|
| 219 | public void itemStateChanged(ItemEvent e) {
|
---|
| 220 | if (e.getStateChange() == ItemEvent.SELECTED)
|
---|
| 221 | execUpdates.add(m);
|
---|
| 222 | else
|
---|
| 223 | execUpdates.remove(m);
|
---|
| 224 | }
|
---|
| 225 | });
|
---|
| 226 | panPackages.add(check);
|
---|
[621] | 227 | }
|
---|
[632] | 228 | for (final Mod m : tools) {
|
---|
[621] | 229 | size += m.getZipSize();
|
---|
[632] | 230 | JCheckBox check = new JCheckBox("Tool: " + m.getName());
|
---|
| 231 | check.setSelected(true);
|
---|
| 232 | panPackages.add(check);
|
---|
[621] | 233 | }
|
---|
[622] | 234 | if (size > 0) {
|
---|
[627] | 235 | // Build info dialog content
|
---|
[632] | 236 | JPanel packages = new JPanel(new BorderLayout(0, 7));
|
---|
| 237 | JLabel lblIntro = new JLabel("<html>"
|
---|
| 238 | + bundle.getString("updatesAvailable.text")
|
---|
| 239 | + "</html>");
|
---|
| 240 | JLabel lblSize = new JLabel("<html>"
|
---|
| 241 | + String.format(bundle
|
---|
| 242 | .getString("updatesAvailableSize.text"),
|
---|
| 243 | SizeFormatter.format(size, 3)) + "</html>");
|
---|
| 244 | packages.add(lblIntro, BorderLayout.NORTH);
|
---|
| 245 | packages.add(panPackages, BorderLayout.CENTER);
|
---|
| 246 | packages.add(lblSize, BorderLayout.SOUTH);
|
---|
[627] | 247 |
|
---|
[632] | 248 | JPanel pan = new JPanel(new BorderLayout(0, 25));
|
---|
| 249 | pan.add(packages, BorderLayout.CENTER);
|
---|
[627] | 250 | JCheckBox checkFutureUpdates = new JCheckBox(
|
---|
| 251 | bundle.getString("checkOnStartup.text"));
|
---|
| 252 | checkFutureUpdates.setSelected(Settings.getInstance().get(
|
---|
| 253 | "notifyupdates", true));
|
---|
| 254 | checkFutureUpdates.addItemListener(new ItemListener() {
|
---|
| 255 | @Override
|
---|
| 256 | public void itemStateChanged(ItemEvent evt) {
|
---|
| 257 | Settings.getInstance().put("notifyupdates",
|
---|
| 258 | evt.getStateChange() == ItemEvent.SELECTED);
|
---|
| 259 | }
|
---|
| 260 | });
|
---|
| 261 | pan.add(checkFutureUpdates, BorderLayout.SOUTH);
|
---|
| 262 |
|
---|
| 263 | // Show dialog
|
---|
| 264 | int res = JOptionPane.showConfirmDialog(this, pan,
|
---|
[622] | 265 | bundle.getString("updatesAvailable.title"),
|
---|
| 266 | JOptionPane.YES_NO_OPTION,
|
---|
| 267 | JOptionPane.QUESTION_MESSAGE);
|
---|
[632] | 268 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 269 | execUpdates = null;
|
---|
[622] | 270 | }
|
---|
[621] | 271 | }
|
---|
| 272 | }
|
---|
[591] | 273 | }
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[624] | 276 | @SuppressWarnings("unused")
|
---|
| 277 | private void doUpdate() {
|
---|
[632] | 278 | if (execUpdates != null && execUpdates.size() > 0) {
|
---|
[646] | 279 | Downloader dl = new Downloader(execUpdates, null);
|
---|
[624] | 280 | try {
|
---|
| 281 | dl.setVisible(true);
|
---|
| 282 | if (dl.isFinished()) {
|
---|
| 283 | TreeSet<Integer> installed = Installer.getInstalledTools();
|
---|
| 284 | TreeSet<Mod> tools = new TreeSet<Mod>();
|
---|
| 285 | for (Mod m : execUpdates)
|
---|
| 286 | if (m.isTool()
|
---|
| 287 | && installed.contains(m.getPackageNumber()))
|
---|
| 288 | tools.add(m);
|
---|
| 289 | if (tools.size() > 0) {
|
---|
| 290 | Installer.installTools(tools);
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 | } finally {
|
---|
| 294 | dl.dispose();
|
---|
| 295 | }
|
---|
[591] | 296 | }
|
---|
[621] | 297 | execUpdates = null;
|
---|
[591] | 298 | }
|
---|
| 299 |
|
---|
| 300 | @SuppressWarnings("unused")
|
---|
| 301 | private void focus() {
|
---|
| 302 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 303 |
|
---|
| 304 | @Override
|
---|
| 305 | public void run() {
|
---|
| 306 | toFront();
|
---|
| 307 | repaint();
|
---|
| 308 | }
|
---|
| 309 | });
|
---|
| 310 |
|
---|
| 311 | }
|
---|
[646] | 312 |
|
---|
[645] | 313 | @SuppressWarnings("unused")
|
---|
| 314 | private void showMandatoryPackagesDialog() {
|
---|
[646] | 315 | new MandatoryPackagesDialog().setVisible(true);
|
---|
[645] | 316 | }
|
---|
[591] | 317 |
|
---|
| 318 | private void showSettings() {
|
---|
[593] | 319 | new SettingsDialog().setVisible(true);
|
---|
[591] | 320 | }
|
---|
| 321 |
|
---|
[593] | 322 | private void showAbout() {
|
---|
| 323 | new AboutDialog().setVisible(true);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[604] | 326 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 327 | JFileChooser fc = new JFileChooser();
|
---|
| 328 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 329 | if (save)
|
---|
| 330 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 331 | else
|
---|
| 332 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 333 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 334 | fc.setFileFilter(new FileFilter() {
|
---|
| 335 | @Override
|
---|
| 336 | public String getDescription() {
|
---|
| 337 | return "XML files";
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | @Override
|
---|
| 341 | public boolean accept(File arg0) {
|
---|
| 342 | return (arg0.isDirectory())
|
---|
| 343 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 344 | }
|
---|
| 345 | });
|
---|
| 346 | fc.setMultiSelectionEnabled(false);
|
---|
| 347 | return fc;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[593] | 350 | @SuppressWarnings("unused")
|
---|
| 351 | private void loadConfig() {
|
---|
[604] | 352 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 353 | int res = fc.showOpenDialog(this);
|
---|
| 354 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 355 | if (fc.getSelectedFile().exists())
|
---|
[631] | 356 | tblMods.reloadSelection(fc.getSelectedFile());
|
---|
[604] | 357 | }
|
---|
[593] | 358 | }
|
---|
| 359 |
|
---|
| 360 | @SuppressWarnings("unused")
|
---|
| 361 | private void saveConfig() {
|
---|
[604] | 362 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 363 | int res = fc.showSaveDialog(this);
|
---|
| 364 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 365 | File f = fc.getSelectedFile();
|
---|
| 366 | if (!f.getName().endsWith(".xml"))
|
---|
| 367 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
| 368 | ModManager.getInstance().saveModSelection(f,
|
---|
[631] | 369 | tblMods.getSelectedMods());
|
---|
[604] | 370 | }
|
---|
[593] | 371 | }
|
---|
| 372 |
|
---|
[600] | 373 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 374 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 375 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 376 | @Override
|
---|
| 377 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 378 | evt.setProgressEnd(total);
|
---|
| 379 | evt.setProgressValue(done);
|
---|
| 380 | evt.setProgressMessage(step);
|
---|
| 381 | }
|
---|
| 382 | });
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[593] | 385 | @SuppressWarnings("unused")
|
---|
[600] | 386 | private void tools() {
|
---|
[625] | 387 | new ToolManager().setVisible(true);
|
---|
[593] | 388 | }
|
---|
[596] | 389 |
|
---|
[593] | 390 | @SuppressWarnings("unused")
|
---|
[623] | 391 | private void refreshToolsMenu() {
|
---|
| 392 | for (JMenuItem i : toolsMenuItems) {
|
---|
| 393 | toolsMenu.remove(i);
|
---|
| 394 | }
|
---|
| 395 | toolsMenuItems.clear();
|
---|
| 396 | for (Mod m : ModManager.getInstance().getInstalledTools()) {
|
---|
[640] | 397 | File exe = m.getExeFile();
|
---|
| 398 | if (exe != null && exe.exists()) {
|
---|
[623] | 399 | JMenuItem item = new JMenuItem();
|
---|
| 400 | final Vector<String> params = new Vector<String>();
|
---|
[640] | 401 | if (exe.getName().toLowerCase().endsWith(".jar")) {
|
---|
| 402 | File jre = null;
|
---|
| 403 | if (Settings.getPlatform() == Platform.WIN)
|
---|
| 404 | jre = new File(System.getProperties().getProperty(
|
---|
| 405 | "java.home"), "bin/javaw.exe");
|
---|
| 406 | else
|
---|
| 407 | jre = new File(System.getProperties().getProperty(
|
---|
| 408 | "java.home"), "bin/java");
|
---|
| 409 | params.add(jre.getPath());
|
---|
| 410 | params.add("-jar");
|
---|
| 411 | }
|
---|
| 412 | params.add(exe.getPath());
|
---|
[623] | 413 | final File wd = m.getWorkingDir();
|
---|
| 414 | Icon ico = null;
|
---|
| 415 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 416 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 417 | } else {
|
---|
[624] | 418 | URL icon = AEInstaller2.class
|
---|
| 419 | .getResource("images/transparent.png");
|
---|
[623] | 420 | ico = new ImageIcon(icon);
|
---|
| 421 | }
|
---|
| 422 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 423 | private static final long serialVersionUID = 1L;
|
---|
| 424 |
|
---|
| 425 | @Override
|
---|
| 426 | public void actionPerformed(ActionEvent e) {
|
---|
| 427 | AppExecution.execute(params, wd);
|
---|
| 428 | }
|
---|
| 429 | });
|
---|
| 430 | toolsMenuItems.add(item);
|
---|
| 431 | toolsMenu.add(item);
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[593] | 436 | private void revertSelection() {
|
---|
[631] | 437 | tblMods.revertSelection();
|
---|
[593] | 438 | }
|
---|
| 439 |
|
---|
[602] | 440 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
|
---|
| 441 | private void checkMandatoryFiles(final BackgroundEvent evt) {
|
---|
[621] | 442 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
| 443 | for (Mod m : ModManager.getInstance().getMandatoryTools()) {
|
---|
| 444 | if (m.isNewerAvailable()) {
|
---|
[645] | 445 | execMandatoryUpdates.add(m);
|
---|
[621] | 446 | }
|
---|
[604] | 447 | }
|
---|
[621] | 448 | for (Mod m : ModManager.getInstance().getMandatoryMods()) {
|
---|
| 449 | if (m.isNewerAvailable()) {
|
---|
[645] | 450 | execMandatoryUpdates.add(m);
|
---|
[621] | 451 | }
|
---|
[604] | 452 | }
|
---|
[645] | 453 | if (execMandatoryUpdates.size() > 0) {
|
---|
| 454 | ModDownloader m = new ModDownloader(execMandatoryUpdates,
|
---|
[621] | 455 | new ModDownloaderListener() {
|
---|
| 456 | @Override
|
---|
| 457 | public void updateStatus(ModDownloader source,
|
---|
[646] | 458 | Mod currentDownload, State state,
|
---|
| 459 | int filesDown, int filesTotal,
|
---|
[621] | 460 | int bytesDown, int bytesTotal,
|
---|
| 461 | int duration, int remaining, int speed) {
|
---|
| 462 | evt.setProgressEnd(filesTotal);
|
---|
| 463 | evt.setProgressValue(filesDown);
|
---|
| 464 | }
|
---|
| 465 | });
|
---|
| 466 | while (!m.isFinished()) {
|
---|
| 467 | try {
|
---|
| 468 | Thread.sleep(10);
|
---|
| 469 | } catch (InterruptedException e) {
|
---|
| 470 | e.printStackTrace();
|
---|
| 471 | }
|
---|
[604] | 472 | }
|
---|
| 473 | }
|
---|
[621] | 474 | evt.setProgressMessage(bundle
|
---|
| 475 | .getString("mandatoryToolsInstall.title"));
|
---|
| 476 | Installer
|
---|
| 477 | .installTools(ModManager.getInstance().getMandatoryTools());
|
---|
[604] | 478 | }
|
---|
[602] | 479 | }
|
---|
| 480 |
|
---|
[641] | 481 | @SuppressWarnings("unused")
|
---|
[645] | 482 | private void infoMandatoryFiles() {
|
---|
| 483 | if (execMandatoryUpdates.size() > 0) {
|
---|
| 484 | String packages = "";
|
---|
| 485 | for (Mod m : execMandatoryUpdates) {
|
---|
| 486 | packages += String.format("\n - %s (%s)", m.getName(),
|
---|
| 487 | m.getVersion());
|
---|
| 488 | }
|
---|
| 489 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 490 | bundle.getString("mandatoryFilesUpdated.text"), packages),
|
---|
| 491 | bundle.getString("mandatoryFilesUpdated.title"),
|
---|
| 492 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | @SuppressWarnings("unused")
|
---|
[641] | 497 | private void install() {
|
---|
[600] | 498 | TreeSet<Mod> mods = new TreeSet<Mod>();
|
---|
[602] | 499 | mods.addAll(ModManager.getInstance().getMandatoryMods());
|
---|
[631] | 500 | mods.addAll(tblMods.getSelectedMods());
|
---|
[600] | 501 |
|
---|
[646] | 502 | installDeps = new TreeSet<Mod>();
|
---|
| 503 |
|
---|
[641] | 504 | installState = EInstallState.CHECKING;
|
---|
[605] | 505 |
|
---|
[641] | 506 | while (installState == EInstallState.CHECKING) {
|
---|
[605] | 507 | TreeSet<Mod> toDownload = new TreeSet<Mod>();
|
---|
| 508 | for (Mod m : mods) {
|
---|
| 509 | if (!m.isLocalAvailable())
|
---|
| 510 | toDownload.add(m);
|
---|
| 511 | }
|
---|
[621] | 512 | if (Settings.getInstance().isOfflineMode()) {
|
---|
[641] | 513 | installState = EInstallState.OFFLINE;
|
---|
[621] | 514 | break;
|
---|
| 515 | }
|
---|
[605] | 516 | if (toDownload.size() > 0) {
|
---|
[646] | 517 | Downloader dl = new Downloader(toDownload, installDeps);
|
---|
[617] | 518 | try {
|
---|
| 519 | dl.setVisible(true);
|
---|
[641] | 520 | if (!dl.isFinished()) {
|
---|
| 521 | installState = EInstallState.ABORTED;
|
---|
[617] | 522 | break;
|
---|
[641] | 523 | }
|
---|
[617] | 524 | } finally {
|
---|
| 525 | dl.dispose();
|
---|
| 526 | }
|
---|
[605] | 527 | }
|
---|
| 528 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
|
---|
| 529 | .checkDependencies(mods);
|
---|
| 530 | if (dependencies.size() > 0) {
|
---|
[646] | 531 | for (HashSet<Mod> hm : dependencies.values()) {
|
---|
| 532 | installDeps.addAll(hm);
|
---|
| 533 | for (Mod mDep : hm) {
|
---|
| 534 | if (!mods.contains(mDep))
|
---|
[641] | 535 | mods.add(mDep);
|
---|
[646] | 536 | }
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | if (!Settings.getInstance()
|
---|
| 540 | .get("notifyDepsAfterInstall", false)) {
|
---|
| 541 | int size = 0;
|
---|
| 542 | String depsLocalString = "";
|
---|
| 543 | String depsDownloadString = "";
|
---|
| 544 | for (Mod m : dependencies.keySet()) {
|
---|
| 545 | for (Mod mDep : dependencies.get(m)) {
|
---|
| 546 | if (!mods.contains(mDep)) {
|
---|
| 547 | mods.add(mDep);
|
---|
| 548 | if (!mDep.isLocalAvailable()) {
|
---|
| 549 | size += mDep.getZipSize();
|
---|
| 550 | if (depsDownloadString.length() > 0)
|
---|
| 551 | depsDownloadString += "\n";
|
---|
| 552 | depsDownloadString += " - "
|
---|
| 553 | + mDep.getName();
|
---|
| 554 | } else {
|
---|
| 555 | if (depsLocalString.length() > 0)
|
---|
| 556 | depsLocalString += "\n";
|
---|
| 557 | depsLocalString += " - " + mDep.getName();
|
---|
| 558 | }
|
---|
[641] | 559 | }
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
[646] | 562 | if (depsLocalString.length() == 0)
|
---|
| 563 | depsLocalString = bundle
|
---|
| 564 | .getString("installDependencies.none");
|
---|
| 565 | if (depsDownloadString.length() == 0)
|
---|
| 566 | depsDownloadString = bundle
|
---|
| 567 | .getString("installDependencies.none");
|
---|
[641] | 568 |
|
---|
[646] | 569 | int res = JOptionPane.showConfirmDialog(this, String
|
---|
| 570 | .format(bundle
|
---|
| 571 | .getString("installDependencies.text"),
|
---|
| 572 | depsLocalString, depsDownloadString,
|
---|
| 573 | SizeFormatter.format(size, 3)), bundle
|
---|
| 574 | .getString("installDependencies.title"),
|
---|
| 575 | JOptionPane.YES_NO_OPTION,
|
---|
| 576 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 577 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 578 | installState = EInstallState.ABORTED;
|
---|
| 579 | break;
|
---|
| 580 | }
|
---|
[641] | 581 | }
|
---|
[605] | 582 | } else {
|
---|
[645] | 583 | HashMap<Mod, HashSet<Mod>> incompatibilities = ModManager
|
---|
| 584 | .getInstance().checkIncompabitilites(mods);
|
---|
[643] | 585 | if (incompatibilities.size() > 0) {
|
---|
[641] | 586 | installState = EInstallState.INCOMPATIBLE;
|
---|
[643] | 587 |
|
---|
| 588 | String incompatString = "";
|
---|
| 589 | for (Mod m : incompatibilities.keySet()) {
|
---|
| 590 | if (incompatString.length() > 0)
|
---|
| 591 | incompatString += "\n";
|
---|
| 592 | incompatString += m.getName() + ": ";
|
---|
| 593 | String confMods = "";
|
---|
| 594 | for (Mod mConf : incompatibilities.get(m)) {
|
---|
| 595 | if (confMods.length() > 0)
|
---|
| 596 | confMods += ", ";
|
---|
| 597 | confMods += mConf.getName();
|
---|
| 598 | }
|
---|
| 599 | incompatString += confMods;
|
---|
| 600 | }
|
---|
| 601 |
|
---|
| 602 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 603 | bundle.getString("installIncompatibilities.text"),
|
---|
| 604 | incompatString), bundle
|
---|
| 605 | .getString("installIncompatibilities.title"),
|
---|
| 606 | JOptionPane.ERROR_MESSAGE);
|
---|
[605] | 607 | break;
|
---|
| 608 | } else {
|
---|
[641] | 609 | installState = EInstallState.READY;
|
---|
[605] | 610 | }
|
---|
| 611 | }
|
---|
[600] | 612 | }
|
---|
[618] | 613 |
|
---|
[641] | 614 | if (installState == EInstallState.READY) {
|
---|
| 615 | installMods = new TreeSet<Mod>();
|
---|
[623] | 616 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 617 |
|
---|
| 618 | for (Mod m : mods) {
|
---|
| 619 | if (m.isTool())
|
---|
| 620 | actuallyTools.add(m);
|
---|
| 621 | else
|
---|
[641] | 622 | installMods.add(m);
|
---|
[623] | 623 | }
|
---|
| 624 |
|
---|
| 625 | if (actuallyTools.size() > 0) {
|
---|
| 626 | Installer.installTools(actuallyTools);
|
---|
| 627 | }
|
---|
[641] | 628 | }
|
---|
[623] | 629 |
|
---|
[641] | 630 | }
|
---|
| 631 |
|
---|
| 632 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
| 633 | private void installExec(final BackgroundEvent evt) {
|
---|
| 634 | if (installState == EInstallState.READY) {
|
---|
| 635 | Installer.install(installMods, new InstallProgressListener() {
|
---|
[605] | 636 | @Override
|
---|
| 637 | public void installProgressUpdate(int done, int total,
|
---|
| 638 | String step) {
|
---|
| 639 | evt.setProgressEnd(total);
|
---|
| 640 | evt.setProgressValue(done);
|
---|
| 641 | evt.setProgressMessage(step);
|
---|
| 642 | }
|
---|
| 643 | });
|
---|
[641] | 644 | installState = EInstallState.DONE;
|
---|
[605] | 645 | }
|
---|
[641] | 646 | installMods = null;
|
---|
[600] | 647 | }
|
---|
[618] | 648 |
|
---|
[617] | 649 | @SuppressWarnings("unused")
|
---|
| 650 | private void installDone() {
|
---|
[637] | 651 | ModManager.getInstance().updateInstalledMods();
|
---|
[641] | 652 | switch (installState) {
|
---|
[621] | 653 | case DONE:
|
---|
[641] | 654 | revertSelection();
|
---|
[646] | 655 | if (installDeps.size() > 0
|
---|
| 656 | && Settings.getInstance().get("notifyDepsAfterInstall",
|
---|
| 657 | false)) {
|
---|
| 658 | String installedDeps = "";
|
---|
| 659 | for (Mod m : installDeps) {
|
---|
| 660 | if (installedDeps.length() > 0)
|
---|
| 661 | installedDeps += "\n";
|
---|
| 662 | installedDeps += " - " + m.getName();
|
---|
| 663 | }
|
---|
| 664 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 665 | bundle.getString("installDoneDeps.text"),
|
---|
| 666 | installedDeps), bundle
|
---|
| 667 | .getString("installDone.title"),
|
---|
| 668 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 669 | } else {
|
---|
| 670 | JOptionPane.showMessageDialog(this,
|
---|
| 671 | bundle.getString("installDone.text"),
|
---|
| 672 | bundle.getString("installDone.title"),
|
---|
| 673 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 674 | }
|
---|
[621] | 675 | break;
|
---|
| 676 | case OFFLINE:
|
---|
| 677 | JOptionPane.showMessageDialog(this,
|
---|
| 678 | bundle.getString("offlineMode.text"),
|
---|
| 679 | bundle.getString("offlineMode.title"),
|
---|
| 680 | JOptionPane.WARNING_MESSAGE);
|
---|
| 681 | break;
|
---|
[641] | 682 | default:
|
---|
[621] | 683 | break;
|
---|
| 684 | }
|
---|
[646] | 685 | installDeps = null;
|
---|
[617] | 686 | }
|
---|
[600] | 687 |
|
---|
[631] | 688 | @Override
|
---|
| 689 | public void modSelectionChanged(ModTable source, Mod m) {
|
---|
[639] | 690 | lblTitleVal.setText("");
|
---|
[592] | 691 | lblCreatorVal.setText("");
|
---|
| 692 | lblDescriptionVal.setText("");
|
---|
[606] | 693 | lblTypesVal.setText("");
|
---|
| 694 | lblPlatformVal.setText("");
|
---|
[621] | 695 | lblPackageNumberVal.setText("");
|
---|
[638] | 696 | lblVersionNumberVal.setText("");
|
---|
[600] | 697 | if (m != null) {
|
---|
[639] | 698 | lblTitleVal.setText(m.getName());
|
---|
[600] | 699 | lblCreatorVal.setText(m.getCreator());
|
---|
| 700 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 701 |
|
---|
| 702 | String types = "";
|
---|
| 703 | for (Type t : m.getTypes()) {
|
---|
| 704 | if (types.length() > 0)
|
---|
| 705 | types += ", ";
|
---|
| 706 | types += t.getName();
|
---|
| 707 | }
|
---|
| 708 | lblTypesVal.setText(types);
|
---|
| 709 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 710 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[638] | 711 | lblVersionNumberVal.setText(m.getVersion());
|
---|
[591] | 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[630] | 715 | private void updateTableFilter() {
|
---|
| 716 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 717 | Type t = null;
|
---|
| 718 | if (o instanceof Type)
|
---|
| 719 | t = (Type) o;
|
---|
| 720 | int downloadState = 0;
|
---|
| 721 | if (radOnline.isSelected())
|
---|
| 722 | downloadState = 1;
|
---|
| 723 | if (radLocal.isSelected())
|
---|
| 724 | downloadState = 2;
|
---|
[631] | 725 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 726 | }
|
---|
| 727 |
|
---|
[591] | 728 | @SuppressWarnings("unused")
|
---|
[592] | 729 | private void modTypeSelection() {
|
---|
[630] | 730 | updateTableFilter();
|
---|
[591] | 731 | }
|
---|
[593] | 732 |
|
---|
[630] | 733 | @SuppressWarnings("unused")
|
---|
| 734 | private void showTypeSelection() {
|
---|
| 735 | updateTableFilter();
|
---|
| 736 | }
|
---|
| 737 |
|
---|
[593] | 738 | @Override
|
---|
[600] | 739 | public void downloadSizeChanged(int newSize) {
|
---|
| 740 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[616] | 743 | @SuppressWarnings("unused")
|
---|
| 744 | private void checkInitialize() {
|
---|
[600] | 745 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 746 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 747 | JOptionPane.showMessageDialog(this,
|
---|
| 748 | bundle.getString("noOniSplit.text"),
|
---|
| 749 | bundle.getString("noOniSplit.title"),
|
---|
| 750 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 751 | exit();
|
---|
[621] | 752 | } else {
|
---|
| 753 | int res = JOptionPane
|
---|
| 754 | .showConfirmDialog(this,
|
---|
| 755 | bundle.getString("askInitialize.text"),
|
---|
| 756 | bundle.getString("askInitialize.title"),
|
---|
| 757 | JOptionPane.YES_NO_OPTION,
|
---|
| 758 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 759 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 760 | saveLocalData();
|
---|
| 761 | exit();
|
---|
| 762 | }
|
---|
[600] | 763 | }
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
[606] | 766 |
|
---|
[616] | 767 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 768 | private void initialize(final BackgroundEvent evt) {
|
---|
| 769 | if (!Installer.isEditionInitialized()) {
|
---|
| 770 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 771 | @Override
|
---|
| 772 | public void installProgressUpdate(int done, int total,
|
---|
| 773 | String step) {
|
---|
| 774 | evt.setProgressEnd(total);
|
---|
| 775 | evt.setProgressValue(done);
|
---|
| 776 | evt.setProgressMessage(step);
|
---|
| 777 | }
|
---|
| 778 | });
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 |
|
---|
[605] | 782 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 783 | Vector<String> params = new Vector<String>();
|
---|
[618] | 784 | File exe = null;
|
---|
[605] | 785 | switch (Settings.getPlatform()) {
|
---|
| 786 | case WIN:
|
---|
[618] | 787 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 788 | if (exe.exists())
|
---|
| 789 | params.add(exe.getPath());
|
---|
[605] | 790 | break;
|
---|
| 791 | case MACOS:
|
---|
[618] | 792 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 793 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 794 | if (exe.exists())
|
---|
| 795 | params.add(exe.getPath());
|
---|
[605] | 796 | break;
|
---|
| 797 | case LINUX:
|
---|
| 798 | String wine = Settings.getWinePath();
|
---|
[618] | 799 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 800 | if (exe.exists()) {
|
---|
| 801 | if (wine != null) {
|
---|
| 802 | params.add(wine);
|
---|
| 803 | params.add(exe.getPath());
|
---|
| 804 | }
|
---|
[605] | 805 | }
|
---|
| 806 | break;
|
---|
| 807 | default:
|
---|
| 808 | }
|
---|
| 809 | if (params.size() > 0) {
|
---|
| 810 | params.add("-debugfiles");
|
---|
| 811 | }
|
---|
| 812 | return params;
|
---|
| 813 | }
|
---|
[600] | 814 |
|
---|
[605] | 815 | @SuppressWarnings("unused")
|
---|
| 816 | private void oniFull() {
|
---|
| 817 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 818 | if (params.size() > 0) {
|
---|
[623] | 819 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 820 | }
|
---|
| 821 | }
|
---|
| 822 |
|
---|
| 823 | @SuppressWarnings("unused")
|
---|
| 824 | private void oniWin() {
|
---|
| 825 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 826 | if (params.size() > 0) {
|
---|
| 827 | params.add("-noswitch");
|
---|
[623] | 828 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 829 | }
|
---|
| 830 | }
|
---|
| 831 |
|
---|
[608] | 832 | @SuppressWarnings("unused")
|
---|
| 833 | private void openEditionFolder() {
|
---|
| 834 | try {
|
---|
| 835 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
[639] | 836 | } catch (Exception e) {
|
---|
[608] | 837 | e.printStackTrace();
|
---|
| 838 | }
|
---|
| 839 | }
|
---|
| 840 |
|
---|
[600] | 841 | @Override
|
---|
[593] | 842 | public void handleAbout(ApplicationEvent event) {
|
---|
| 843 | event.setHandled(true);
|
---|
| 844 | showAbout();
|
---|
| 845 | }
|
---|
| 846 |
|
---|
| 847 | @Override
|
---|
| 848 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 849 | }
|
---|
| 850 |
|
---|
| 851 | @Override
|
---|
| 852 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 853 | }
|
---|
| 854 |
|
---|
| 855 | @Override
|
---|
| 856 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 857 | showSettings();
|
---|
| 858 | }
|
---|
| 859 |
|
---|
| 860 | @Override
|
---|
| 861 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 862 | }
|
---|
| 863 |
|
---|
| 864 | @Override
|
---|
| 865 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 866 | event.setHandled(true);
|
---|
| 867 | saveLocalData();
|
---|
| 868 | exit();
|
---|
[593] | 869 | }
|
---|
| 870 |
|
---|
| 871 | @Override
|
---|
| 872 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 873 | }
|
---|
[600] | 874 |
|
---|
[592] | 875 | }
|
---|