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