[591] | 1 | package net.oni2.aeinstaller.gui;
|
---|
| 2 |
|
---|
[608] | 3 | import java.awt.Desktop;
|
---|
| 4 | import java.awt.event.ActionEvent;
|
---|
| 5 | import java.awt.event.ActionListener;
|
---|
| 6 | import java.awt.event.MouseAdapter;
|
---|
| 7 | import java.awt.event.MouseEvent;
|
---|
[604] | 8 | import java.io.File;
|
---|
[605] | 9 | import java.io.IOException;
|
---|
[623] | 10 | import java.net.URL;
|
---|
[591] | 11 | import java.util.ArrayList;
|
---|
[605] | 12 | import java.util.HashMap;
|
---|
| 13 | import java.util.HashSet;
|
---|
[591] | 14 | import java.util.List;
|
---|
| 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;
|
---|
[591] | 24 | import javax.swing.JComboBox;
|
---|
[593] | 25 | import javax.swing.JComponent;
|
---|
[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;
|
---|
[608] | 32 | import javax.swing.JPopupMenu;
|
---|
[592] | 33 | import javax.swing.JSplitPane;
|
---|
[591] | 34 | import javax.swing.JTable;
|
---|
| 35 | import javax.swing.ListSelectionModel;
|
---|
| 36 | import javax.swing.RowSorter;
|
---|
| 37 | import javax.swing.SortOrder;
|
---|
| 38 | import javax.swing.SwingUtilities;
|
---|
| 39 | import javax.swing.event.ListSelectionEvent;
|
---|
| 40 | import javax.swing.event.ListSelectionListener;
|
---|
[604] | 41 | import javax.swing.filechooser.FileFilter;
|
---|
[591] | 42 | import javax.swing.table.TableRowSorter;
|
---|
| 43 |
|
---|
[623] | 44 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
| 45 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[604] | 46 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 47 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[593] | 48 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[600] | 49 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[591] | 50 | import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener;
|
---|
| 51 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
[600] | 52 | import net.oni2.aeinstaller.backend.mods.Mod;
|
---|
| 53 | import net.oni2.aeinstaller.backend.mods.ModManager;
|
---|
| 54 | import net.oni2.aeinstaller.backend.mods.Type;
|
---|
[604] | 55 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
|
---|
| 56 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
|
---|
| 57 | import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
|
---|
[600] | 58 | import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
|
---|
| 59 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
[621] | 60 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[593] | 61 | import net.oni2.aeinstaller.gui.about.AboutDialog;
|
---|
[605] | 62 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[600] | 63 | import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
|
---|
[591] | 64 | import net.oni2.aeinstaller.gui.modtable.ModTableFilter;
|
---|
| 65 | import net.oni2.aeinstaller.gui.modtable.ModTableModel;
|
---|
| 66 | import net.oni2.aeinstaller.gui.settings.SettingsDialog;
|
---|
[625] | 67 | import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
|
---|
[591] | 68 |
|
---|
| 69 | import org.javabuilders.BuildResult;
|
---|
| 70 | import org.javabuilders.annotations.DoInBackground;
|
---|
| 71 | import org.javabuilders.event.BackgroundEvent;
|
---|
| 72 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 73 | import org.simplericity.macify.eawt.ApplicationEvent;
|
---|
| 74 | import org.simplericity.macify.eawt.ApplicationListener;
|
---|
[591] | 75 |
|
---|
| 76 | /**
|
---|
| 77 | * @author Christian Illy
|
---|
| 78 | */
|
---|
[600] | 79 | public class MainWin extends JFrame implements ApplicationListener,
|
---|
| 80 | DownloadSizeListener {
|
---|
[591] | 81 | private static final long serialVersionUID = -4027395051382659650L;
|
---|
| 82 |
|
---|
| 83 | private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
|
---|
| 84 | .getName());
|
---|
| 85 | @SuppressWarnings("unused")
|
---|
| 86 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 87 |
|
---|
[593] | 88 | private JMenu mainMenu;
|
---|
[623] | 89 | private JMenu toolsMenu;
|
---|
| 90 | private TreeSet<JMenuItem> toolsMenuItems = new TreeSet<JMenuItem>();
|
---|
[593] | 91 |
|
---|
[592] | 92 | private JSplitPane contents;
|
---|
| 93 |
|
---|
[591] | 94 | private JComboBox cmbModTypes;
|
---|
| 95 | private JTable tblMods;
|
---|
| 96 | private ModTableModel model;
|
---|
| 97 | private TableRowSorter<ModTableModel> sorter;
|
---|
[600] | 98 | private JLabel lblDownloadSizeVal;
|
---|
[591] | 99 |
|
---|
[592] | 100 | private JLabel lblSubmitterVal;
|
---|
| 101 | private JLabel lblCreatorVal;
|
---|
[606] | 102 | private JLabel lblTypesVal;
|
---|
| 103 | private JLabel lblPlatformVal;
|
---|
[621] | 104 | private JLabel lblPackageNumberVal;
|
---|
[592] | 105 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 106 |
|
---|
[600] | 107 | private JButton btnInstall;
|
---|
| 108 |
|
---|
[621] | 109 | private TreeSet<Mod> execUpdates = null;
|
---|
| 110 |
|
---|
| 111 | private enum EInstallResult {
|
---|
| 112 | DONE,
|
---|
| 113 | OFFLINE,
|
---|
| 114 | INCOMPATIBLE
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | private EInstallResult installDone = EInstallResult.DONE;
|
---|
| 118 |
|
---|
[591] | 119 | /**
|
---|
| 120 | * Constructor of main window.
|
---|
| 121 | */
|
---|
| 122 | public MainWin() {
|
---|
[593] | 123 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 124 | + " - v"
|
---|
| 125 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 126 |
|
---|
[592] | 127 | contents.setDividerLocation(400);
|
---|
[593] | 128 |
|
---|
| 129 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 130 | mainMenu.setVisible(false);
|
---|
| 131 | }
|
---|
[600] | 132 |
|
---|
| 133 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 134 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[591] | 135 | }
|
---|
| 136 |
|
---|
| 137 | private void initModTypeBox() {
|
---|
[592] | 138 | cmbModTypes.removeAllItems();
|
---|
| 139 |
|
---|
[600] | 140 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
| 141 | for (Type t : ModManager.getInstance().getTypesWithContent()) {
|
---|
| 142 | types.put(t.getName(), t);
|
---|
[591] | 143 | }
|
---|
[600] | 144 | for (Type t : types.values()) {
|
---|
[591] | 145 | cmbModTypes.addItem(t);
|
---|
| 146 | }
|
---|
| 147 | cmbModTypes.setSelectedIndex(0);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | private void initTable() {
|
---|
| 151 | tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
[592] | 152 | tblMods.getSelectionModel().addListSelectionListener(
|
---|
| 153 | new ListSelectionListener() {
|
---|
| 154 | @Override
|
---|
| 155 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 156 | int viewRow = tblMods.getSelectedRow();
|
---|
| 157 | if (viewRow < 0) {
|
---|
| 158 | modSelection(null);
|
---|
| 159 | } else {
|
---|
| 160 | int modelRow = tblMods
|
---|
| 161 | .convertRowIndexToModel(viewRow);
|
---|
[600] | 162 | Mod mod = (Mod) model.getValueAt(modelRow, -1);
|
---|
[592] | 163 | modSelection(mod);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | });
|
---|
[608] | 167 | tblMods.addMouseListener(new MouseAdapter() {
|
---|
| 168 | private void common(MouseEvent e) {
|
---|
| 169 | int r = tblMods.rowAtPoint(e.getPoint());
|
---|
| 170 | if (r >= 0 && r < tblMods.getRowCount())
|
---|
| 171 | tblMods.setRowSelectionInterval(r, r);
|
---|
| 172 | else
|
---|
| 173 | tblMods.clearSelection();
|
---|
[592] | 174 |
|
---|
[608] | 175 | int rowindex = tblMods.getSelectedRow();
|
---|
| 176 | if (rowindex >= 0) {
|
---|
| 177 | if (e.isPopupTrigger()
|
---|
| 178 | && e.getComponent() instanceof JTable) {
|
---|
| 179 | int modelRow = tblMods.convertRowIndexToModel(rowindex);
|
---|
| 180 | final Mod mod = (Mod) model.getValueAt(modelRow, -1);
|
---|
| 181 |
|
---|
| 182 | if (mod.isLocalAvailable()) {
|
---|
| 183 | JPopupMenu popup = new JPopupMenu();
|
---|
| 184 | JMenuItem openModFolder = new JMenuItem(bundle
|
---|
| 185 | .getString("openModFolder.text"));
|
---|
| 186 | openModFolder
|
---|
| 187 | .addActionListener(new ActionListener() {
|
---|
| 188 | @Override
|
---|
| 189 | public void actionPerformed(
|
---|
| 190 | ActionEvent arg0) {
|
---|
| 191 | try {
|
---|
| 192 | Desktop.getDesktop().open(
|
---|
| 193 | mod.getLocalPath());
|
---|
| 194 | } catch (IOException e) {
|
---|
| 195 | e.printStackTrace();
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | });
|
---|
| 199 | popup.add(openModFolder);
|
---|
| 200 | popup.show(e.getComponent(), e.getX(), e.getY());
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | @Override
|
---|
| 207 | public void mousePressed(MouseEvent e) {
|
---|
| 208 | common(e);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | @Override
|
---|
| 212 | public void mouseReleased(MouseEvent e) {
|
---|
| 213 | common(e);
|
---|
| 214 | }
|
---|
| 215 | });
|
---|
[593] | 216 | // To get checkbox-cells with background of row
|
---|
| 217 | ((JComponent) tblMods.getDefaultRenderer(Boolean.class))
|
---|
| 218 | .setOpaque(true);
|
---|
| 219 |
|
---|
[591] | 220 | model = new ModTableModel();
|
---|
[600] | 221 | model.addDownloadSizeListener(this);
|
---|
[591] | 222 |
|
---|
| 223 | tblMods.setModel(model);
|
---|
| 224 |
|
---|
| 225 | sorter = new TableRowSorter<ModTableModel>(model);
|
---|
| 226 | tblMods.setRowSorter(sorter);
|
---|
| 227 |
|
---|
[600] | 228 | sorter.setRowFilter(new ModTableFilter(null));
|
---|
[591] | 229 |
|
---|
| 230 | List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
|
---|
[606] | 231 | sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
|
---|
[591] | 232 | sorter.setSortKeys(sortKeys);
|
---|
| 233 |
|
---|
| 234 | for (int i = 0; i < model.getColumnCount(); i++) {
|
---|
| 235 | model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i));
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | private void exit() {
|
---|
| 240 | dispose();
|
---|
[608] | 241 | System.exit(0);
|
---|
[591] | 242 | }
|
---|
| 243 |
|
---|
| 244 | private void saveLocalData() {
|
---|
| 245 | Settings.getInstance().serializeToFile();
|
---|
[596] | 246 | DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename());
|
---|
[591] | 247 | }
|
---|
| 248 |
|
---|
| 249 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 250 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
[621] | 251 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
| 252 | try {
|
---|
| 253 | DepotManager.getInstance().updateInformation(false,
|
---|
| 254 | new DepotCacheUpdateProgressListener() {
|
---|
[591] | 255 |
|
---|
[621] | 256 | @Override
|
---|
| 257 | public void cacheUpdateProgress(String stepName,
|
---|
| 258 | int current, int total) {
|
---|
| 259 | evt.setProgressEnd(total);
|
---|
| 260 | evt.setProgressValue(current);
|
---|
| 261 | evt.setProgressMessage(stepName);
|
---|
| 262 | }
|
---|
| 263 | });
|
---|
| 264 | } catch (Exception e) {
|
---|
| 265 | e.printStackTrace();
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | ModManager.getInstance().init();
|
---|
| 269 | initTable();
|
---|
| 270 | initModTypeBox();
|
---|
[600] | 271 |
|
---|
[621] | 272 | tblMods.setVisible(true);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | @SuppressWarnings("unused")
|
---|
| 276 | private void checkUpdates(Object evtSource) {
|
---|
| 277 | if ((evtSource != this)
|
---|
| 278 | || Settings.getInstance().get("notifyupdates", true)) {
|
---|
| 279 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 280 | if (evtSource != this) {
|
---|
| 281 | JOptionPane.showMessageDialog(this,
|
---|
| 282 | bundle.getString("offlineMode.text"),
|
---|
| 283 | bundle.getString("offlineMode.title"),
|
---|
| 284 | JOptionPane.WARNING_MESSAGE);
|
---|
| 285 | }
|
---|
| 286 | } else {
|
---|
| 287 | TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
|
---|
| 288 | TreeSet<Mod> tools = ModManager.getInstance()
|
---|
| 289 | .getUpdatableTools();
|
---|
| 290 | int size = 0;
|
---|
| 291 | String strMods = "";
|
---|
| 292 | for (Mod m : mods) {
|
---|
| 293 | size += m.getZipSize();
|
---|
| 294 | if (strMods.length() > 0)
|
---|
| 295 | strMods += "<br>";
|
---|
| 296 | strMods += " - " + m.getName();
|
---|
| 297 | }
|
---|
| 298 | String strTools = "";
|
---|
| 299 | for (Mod m : tools) {
|
---|
| 300 | size += m.getZipSize();
|
---|
| 301 | if (strTools.length() > 0)
|
---|
| 302 | strTools += "<br>";
|
---|
| 303 | strTools += " - " + m.getName();
|
---|
| 304 | }
|
---|
[622] | 305 | if (size > 0) {
|
---|
| 306 | String message = "<html>";
|
---|
| 307 | message += String.format(
|
---|
| 308 | bundle.getString("updatesAvailable.text"), strMods,
|
---|
| 309 | strTools, SizeFormatter.format(size, 3));
|
---|
| 310 | message += "</html>";
|
---|
| 311 | int res = JOptionPane.showConfirmDialog(this, message,
|
---|
| 312 | bundle.getString("updatesAvailable.title"),
|
---|
| 313 | JOptionPane.YES_NO_OPTION,
|
---|
| 314 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 315 | if (res == JOptionPane.YES_OPTION) {
|
---|
| 316 | execUpdates = new TreeSet<Mod>();
|
---|
| 317 | execUpdates.addAll(mods);
|
---|
| 318 | execUpdates.addAll(tools);
|
---|
| 319 | }
|
---|
[621] | 320 | }
|
---|
| 321 | }
|
---|
[591] | 322 | }
|
---|
| 323 | }
|
---|
| 324 |
|
---|
[624] | 325 | @SuppressWarnings("unused")
|
---|
| 326 | private void doUpdate() {
|
---|
[621] | 327 | if (execUpdates != null) {
|
---|
[624] | 328 | Downloader dl = new Downloader(execUpdates);
|
---|
| 329 | try {
|
---|
| 330 | dl.setVisible(true);
|
---|
| 331 | if (dl.isFinished()) {
|
---|
| 332 | TreeSet<Integer> installed = Installer.getInstalledTools();
|
---|
| 333 | TreeSet<Mod> tools = new TreeSet<Mod>();
|
---|
| 334 | for (Mod m : execUpdates)
|
---|
| 335 | if (m.isTool()
|
---|
| 336 | && installed.contains(m.getPackageNumber()))
|
---|
| 337 | tools.add(m);
|
---|
| 338 | if (tools.size() > 0) {
|
---|
| 339 | Installer.installTools(tools);
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 | } finally {
|
---|
| 343 | dl.dispose();
|
---|
| 344 | }
|
---|
[591] | 345 | }
|
---|
[621] | 346 | execUpdates = null;
|
---|
[591] | 347 | }
|
---|
| 348 |
|
---|
| 349 | @SuppressWarnings("unused")
|
---|
| 350 | private void focus() {
|
---|
| 351 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 352 |
|
---|
| 353 | @Override
|
---|
| 354 | public void run() {
|
---|
| 355 | toFront();
|
---|
| 356 | repaint();
|
---|
| 357 | }
|
---|
| 358 | });
|
---|
| 359 |
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | private void showSettings() {
|
---|
[593] | 363 | new SettingsDialog().setVisible(true);
|
---|
[591] | 364 | }
|
---|
| 365 |
|
---|
[593] | 366 | private void showAbout() {
|
---|
| 367 | new AboutDialog().setVisible(true);
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[604] | 370 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 371 | JFileChooser fc = new JFileChooser();
|
---|
| 372 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 373 | if (save)
|
---|
| 374 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 375 | else
|
---|
| 376 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 377 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 378 | fc.setFileFilter(new FileFilter() {
|
---|
| 379 | @Override
|
---|
| 380 | public String getDescription() {
|
---|
| 381 | return "XML files";
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | @Override
|
---|
| 385 | public boolean accept(File arg0) {
|
---|
| 386 | return (arg0.isDirectory())
|
---|
| 387 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 388 | }
|
---|
| 389 | });
|
---|
| 390 | fc.setMultiSelectionEnabled(false);
|
---|
| 391 | return fc;
|
---|
| 392 | }
|
---|
| 393 |
|
---|
[593] | 394 | @SuppressWarnings("unused")
|
---|
| 395 | private void loadConfig() {
|
---|
[604] | 396 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 397 | int res = fc.showOpenDialog(this);
|
---|
| 398 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 399 | if (fc.getSelectedFile().exists())
|
---|
| 400 | model.reloadSelection(fc.getSelectedFile());
|
---|
| 401 | }
|
---|
[593] | 402 | }
|
---|
| 403 |
|
---|
| 404 | @SuppressWarnings("unused")
|
---|
| 405 | private void saveConfig() {
|
---|
[604] | 406 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 407 | int res = fc.showSaveDialog(this);
|
---|
| 408 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 409 | File f = fc.getSelectedFile();
|
---|
| 410 | if (!f.getName().endsWith(".xml"))
|
---|
| 411 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
| 412 | ModManager.getInstance().saveModSelection(f,
|
---|
| 413 | model.getSelectedMods());
|
---|
| 414 | }
|
---|
[593] | 415 | }
|
---|
| 416 |
|
---|
[600] | 417 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 418 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 419 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 420 | @Override
|
---|
| 421 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 422 | evt.setProgressEnd(total);
|
---|
| 423 | evt.setProgressValue(done);
|
---|
| 424 | evt.setProgressMessage(step);
|
---|
| 425 | }
|
---|
| 426 | });
|
---|
| 427 | }
|
---|
| 428 |
|
---|
[593] | 429 | @SuppressWarnings("unused")
|
---|
[600] | 430 | private void tools() {
|
---|
[625] | 431 | new ToolManager().setVisible(true);
|
---|
[593] | 432 | }
|
---|
[596] | 433 |
|
---|
[593] | 434 | @SuppressWarnings("unused")
|
---|
[623] | 435 | private void refreshToolsMenu() {
|
---|
| 436 | for (JMenuItem i : toolsMenuItems) {
|
---|
| 437 | toolsMenu.remove(i);
|
---|
| 438 | }
|
---|
| 439 | toolsMenuItems.clear();
|
---|
| 440 | for (Mod m : ModManager.getInstance().getInstalledTools()) {
|
---|
| 441 | if (m.getExeFile() != null && m.getExeFile().exists()) {
|
---|
| 442 | JMenuItem item = new JMenuItem();
|
---|
| 443 | final Vector<String> params = new Vector<String>();
|
---|
| 444 | params.add(m.getExeFile().getPath());
|
---|
| 445 | final File wd = m.getWorkingDir();
|
---|
| 446 | Icon ico = null;
|
---|
| 447 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 448 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 449 | } else {
|
---|
[624] | 450 | URL icon = AEInstaller2.class
|
---|
| 451 | .getResource("images/transparent.png");
|
---|
[623] | 452 | ico = new ImageIcon(icon);
|
---|
| 453 | }
|
---|
| 454 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 455 | private static final long serialVersionUID = 1L;
|
---|
| 456 |
|
---|
| 457 | @Override
|
---|
| 458 | public void actionPerformed(ActionEvent e) {
|
---|
| 459 | AppExecution.execute(params, wd);
|
---|
| 460 | }
|
---|
| 461 | });
|
---|
| 462 | toolsMenuItems.add(item);
|
---|
| 463 | toolsMenu.add(item);
|
---|
| 464 | }
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | @SuppressWarnings("unused")
|
---|
[593] | 469 | private void revertSelection() {
|
---|
[604] | 470 | model.revertSelection();
|
---|
[593] | 471 | }
|
---|
| 472 |
|
---|
[602] | 473 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
|
---|
| 474 | private void checkMandatoryFiles(final BackgroundEvent evt) {
|
---|
[621] | 475 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
| 476 | TreeSet<Mod> mand = new TreeSet<Mod>();
|
---|
| 477 | for (Mod m : ModManager.getInstance().getMandatoryTools()) {
|
---|
| 478 | if (m.isNewerAvailable()) {
|
---|
| 479 | mand.add(m);
|
---|
| 480 | }
|
---|
[604] | 481 | }
|
---|
[621] | 482 | for (Mod m : ModManager.getInstance().getMandatoryMods()) {
|
---|
| 483 | if (m.isNewerAvailable()) {
|
---|
| 484 | mand.add(m);
|
---|
| 485 | }
|
---|
[604] | 486 | }
|
---|
[621] | 487 | if (mand.size() > 0) {
|
---|
| 488 | ModDownloader m = new ModDownloader(mand,
|
---|
| 489 | new ModDownloaderListener() {
|
---|
| 490 | @Override
|
---|
| 491 | public void updateStatus(ModDownloader source,
|
---|
| 492 | State state, int filesDown, int filesTotal,
|
---|
| 493 | int bytesDown, int bytesTotal,
|
---|
| 494 | int duration, int remaining, int speed) {
|
---|
| 495 | evt.setProgressEnd(filesTotal);
|
---|
| 496 | evt.setProgressValue(filesDown);
|
---|
| 497 | }
|
---|
| 498 | });
|
---|
| 499 | while (!m.isFinished()) {
|
---|
| 500 | try {
|
---|
| 501 | Thread.sleep(10);
|
---|
| 502 | } catch (InterruptedException e) {
|
---|
| 503 | e.printStackTrace();
|
---|
| 504 | }
|
---|
[604] | 505 | }
|
---|
| 506 | }
|
---|
[621] | 507 | evt.setProgressMessage(bundle
|
---|
| 508 | .getString("mandatoryToolsInstall.title"));
|
---|
| 509 | Installer
|
---|
| 510 | .installTools(ModManager.getInstance().getMandatoryTools());
|
---|
[604] | 511 | }
|
---|
[602] | 512 | }
|
---|
| 513 |
|
---|
[600] | 514 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
[621] | 515 | private void install(final BackgroundEvent evt) {
|
---|
[600] | 516 | TreeSet<Mod> mods = new TreeSet<Mod>();
|
---|
[602] | 517 | mods.addAll(ModManager.getInstance().getMandatoryMods());
|
---|
[600] | 518 | mods.addAll(model.getSelectedMods());
|
---|
| 519 |
|
---|
[605] | 520 | boolean instReady = false;
|
---|
[621] | 521 | installDone = EInstallResult.DONE;
|
---|
[605] | 522 |
|
---|
| 523 | while (!instReady) {
|
---|
| 524 | TreeSet<Mod> toDownload = new TreeSet<Mod>();
|
---|
| 525 | for (Mod m : mods) {
|
---|
| 526 | if (!m.isLocalAvailable())
|
---|
| 527 | toDownload.add(m);
|
---|
| 528 | }
|
---|
[621] | 529 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 530 | installDone = EInstallResult.OFFLINE;
|
---|
| 531 | break;
|
---|
| 532 | }
|
---|
[605] | 533 | if (toDownload.size() > 0) {
|
---|
| 534 | Downloader dl = new Downloader(toDownload);
|
---|
[617] | 535 | try {
|
---|
| 536 | dl.setVisible(true);
|
---|
| 537 | if (!dl.isFinished())
|
---|
| 538 | break;
|
---|
| 539 | } finally {
|
---|
| 540 | dl.dispose();
|
---|
| 541 | }
|
---|
[605] | 542 | }
|
---|
| 543 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
|
---|
| 544 | .checkDependencies(mods);
|
---|
| 545 | if (dependencies.size() > 0) {
|
---|
| 546 | System.out.println("Unmet dependencies: "
|
---|
| 547 | + dependencies.toString());
|
---|
| 548 | for (Mod m : dependencies.keySet()) {
|
---|
| 549 | for (Mod mDep : dependencies.get(m))
|
---|
| 550 | mods.add(mDep);
|
---|
| 551 | }
|
---|
| 552 | } else {
|
---|
| 553 | HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
|
---|
[608] | 554 | .checkIncompabitilites(mods);
|
---|
[605] | 555 | if (conflicts.size() > 0) {
|
---|
[621] | 556 | installDone = EInstallResult.INCOMPATIBLE;
|
---|
[608] | 557 | System.err.println("Incompatible mods: "
|
---|
[605] | 558 | + conflicts.toString());
|
---|
| 559 | break;
|
---|
| 560 | } else {
|
---|
| 561 | instReady = true;
|
---|
| 562 | }
|
---|
| 563 | }
|
---|
[600] | 564 | }
|
---|
[618] | 565 |
|
---|
[605] | 566 | if (instReady) {
|
---|
[623] | 567 | TreeSet<Mod> actuallyMods = new TreeSet<Mod>();
|
---|
| 568 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 569 |
|
---|
| 570 | for (Mod m : mods) {
|
---|
| 571 | if (m.isTool())
|
---|
| 572 | actuallyTools.add(m);
|
---|
| 573 | else
|
---|
| 574 | actuallyMods.add(m);
|
---|
| 575 | }
|
---|
| 576 |
|
---|
| 577 | if (actuallyTools.size() > 0) {
|
---|
| 578 | Installer.installTools(actuallyTools);
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | Installer.install(actuallyMods, new InstallProgressListener() {
|
---|
[605] | 582 | @Override
|
---|
| 583 | public void installProgressUpdate(int done, int total,
|
---|
| 584 | String step) {
|
---|
| 585 | evt.setProgressEnd(total);
|
---|
| 586 | evt.setProgressValue(done);
|
---|
| 587 | evt.setProgressMessage(step);
|
---|
| 588 | }
|
---|
| 589 | });
|
---|
[621] | 590 | installDone = EInstallResult.DONE;
|
---|
[605] | 591 | }
|
---|
[600] | 592 | }
|
---|
[618] | 593 |
|
---|
[617] | 594 | @SuppressWarnings("unused")
|
---|
| 595 | private void installDone() {
|
---|
[621] | 596 | switch (installDone) {
|
---|
| 597 | case DONE:
|
---|
| 598 | JOptionPane.showMessageDialog(this,
|
---|
| 599 | bundle.getString("installDone.text"),
|
---|
| 600 | bundle.getString("installDone.title"),
|
---|
| 601 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 602 | break;
|
---|
| 603 | case OFFLINE:
|
---|
| 604 | JOptionPane.showMessageDialog(this,
|
---|
| 605 | bundle.getString("offlineMode.text"),
|
---|
| 606 | bundle.getString("offlineMode.title"),
|
---|
| 607 | JOptionPane.WARNING_MESSAGE);
|
---|
| 608 | break;
|
---|
| 609 | case INCOMPATIBLE:
|
---|
| 610 | break;
|
---|
| 611 | }
|
---|
[617] | 612 | }
|
---|
[600] | 613 |
|
---|
| 614 | private void modSelection(Mod m) {
|
---|
[592] | 615 | lblSubmitterVal.setText("");
|
---|
| 616 | lblCreatorVal.setText("");
|
---|
| 617 | lblDescriptionVal.setText("");
|
---|
[606] | 618 | lblTypesVal.setText("");
|
---|
| 619 | lblPlatformVal.setText("");
|
---|
[621] | 620 | lblPackageNumberVal.setText("");
|
---|
[600] | 621 | if (m != null) {
|
---|
| 622 | lblSubmitterVal.setText(m.getName());
|
---|
| 623 | lblCreatorVal.setText(m.getCreator());
|
---|
| 624 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 625 |
|
---|
| 626 | String types = "";
|
---|
| 627 | for (Type t : m.getTypes()) {
|
---|
| 628 | if (types.length() > 0)
|
---|
| 629 | types += ", ";
|
---|
| 630 | types += t.getName();
|
---|
| 631 | }
|
---|
| 632 | lblTypesVal.setText(types);
|
---|
| 633 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 634 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[591] | 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | @SuppressWarnings("unused")
|
---|
[592] | 639 | private void modTypeSelection() {
|
---|
[600] | 640 | Type t = (Type) cmbModTypes.getSelectedItem();
|
---|
[592] | 641 | if (t != null)
|
---|
[600] | 642 | sorter.setRowFilter(new ModTableFilter(t));
|
---|
[592] | 643 | else
|
---|
[600] | 644 | sorter.setRowFilter(new ModTableFilter(null));
|
---|
[591] | 645 | }
|
---|
[593] | 646 |
|
---|
| 647 | @Override
|
---|
[600] | 648 | public void downloadSizeChanged(int newSize) {
|
---|
| 649 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 650 | }
|
---|
| 651 |
|
---|
[616] | 652 | @SuppressWarnings("unused")
|
---|
| 653 | private void checkInitialize() {
|
---|
[600] | 654 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 655 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 656 | JOptionPane.showMessageDialog(this,
|
---|
| 657 | bundle.getString("noOniSplit.text"),
|
---|
| 658 | bundle.getString("noOniSplit.title"),
|
---|
| 659 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 660 | exit();
|
---|
[621] | 661 | } else {
|
---|
| 662 | int res = JOptionPane
|
---|
| 663 | .showConfirmDialog(this,
|
---|
| 664 | bundle.getString("askInitialize.text"),
|
---|
| 665 | bundle.getString("askInitialize.title"),
|
---|
| 666 | JOptionPane.YES_NO_OPTION,
|
---|
| 667 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 668 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 669 | saveLocalData();
|
---|
| 670 | exit();
|
---|
| 671 | }
|
---|
[600] | 672 | }
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
[606] | 675 |
|
---|
[616] | 676 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 677 | private void initialize(final BackgroundEvent evt) {
|
---|
| 678 | if (!Installer.isEditionInitialized()) {
|
---|
| 679 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 680 | @Override
|
---|
| 681 | public void installProgressUpdate(int done, int total,
|
---|
| 682 | String step) {
|
---|
| 683 | evt.setProgressEnd(total);
|
---|
| 684 | evt.setProgressValue(done);
|
---|
| 685 | evt.setProgressMessage(step);
|
---|
| 686 | }
|
---|
| 687 | });
|
---|
| 688 | }
|
---|
| 689 | }
|
---|
| 690 |
|
---|
[605] | 691 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 692 | Vector<String> params = new Vector<String>();
|
---|
[618] | 693 | File exe = null;
|
---|
[605] | 694 | switch (Settings.getPlatform()) {
|
---|
| 695 | case WIN:
|
---|
[618] | 696 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 697 | if (exe.exists())
|
---|
| 698 | params.add(exe.getPath());
|
---|
[605] | 699 | break;
|
---|
| 700 | case MACOS:
|
---|
[618] | 701 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 702 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 703 | if (exe.exists())
|
---|
| 704 | params.add(exe.getPath());
|
---|
[605] | 705 | break;
|
---|
| 706 | case LINUX:
|
---|
| 707 | String wine = Settings.getWinePath();
|
---|
[618] | 708 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 709 | if (exe.exists()) {
|
---|
| 710 | if (wine != null) {
|
---|
| 711 | params.add(wine);
|
---|
| 712 | params.add(exe.getPath());
|
---|
| 713 | }
|
---|
[605] | 714 | }
|
---|
| 715 | break;
|
---|
| 716 | default:
|
---|
| 717 | }
|
---|
| 718 | if (params.size() > 0) {
|
---|
| 719 | params.add("-debugfiles");
|
---|
| 720 | }
|
---|
| 721 | return params;
|
---|
| 722 | }
|
---|
[600] | 723 |
|
---|
[605] | 724 | @SuppressWarnings("unused")
|
---|
| 725 | private void oniFull() {
|
---|
| 726 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 727 | if (params.size() > 0) {
|
---|
[623] | 728 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 729 | }
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | @SuppressWarnings("unused")
|
---|
| 733 | private void oniWin() {
|
---|
| 734 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 735 | if (params.size() > 0) {
|
---|
| 736 | params.add("-noswitch");
|
---|
[623] | 737 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 738 | }
|
---|
| 739 | }
|
---|
| 740 |
|
---|
[608] | 741 | @SuppressWarnings("unused")
|
---|
| 742 | private void openEditionFolder() {
|
---|
| 743 | try {
|
---|
| 744 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
| 745 | } catch (IOException e) {
|
---|
| 746 | e.printStackTrace();
|
---|
| 747 | }
|
---|
| 748 | }
|
---|
| 749 |
|
---|
[600] | 750 | @Override
|
---|
[593] | 751 | public void handleAbout(ApplicationEvent event) {
|
---|
| 752 | event.setHandled(true);
|
---|
| 753 | showAbout();
|
---|
| 754 | }
|
---|
| 755 |
|
---|
| 756 | @Override
|
---|
| 757 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 758 | }
|
---|
| 759 |
|
---|
| 760 | @Override
|
---|
| 761 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | @Override
|
---|
| 765 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 766 | showSettings();
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | @Override
|
---|
| 770 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 | @Override
|
---|
| 774 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 775 | event.setHandled(true);
|
---|
| 776 | saveLocalData();
|
---|
| 777 | exit();
|
---|
[593] | 778 | }
|
---|
| 779 |
|
---|
| 780 | @Override
|
---|
| 781 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 782 | }
|
---|
[600] | 783 |
|
---|
[592] | 784 | }
|
---|