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