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