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