[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;
|
---|
[611] | 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;
|
---|
[592] | 95 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 96 |
|
---|
[600] | 97 | private JButton btnInstall;
|
---|
| 98 |
|
---|
[591] | 99 | /**
|
---|
| 100 | * Constructor of main window.
|
---|
| 101 | */
|
---|
| 102 | public MainWin() {
|
---|
[593] | 103 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 104 | + " - v"
|
---|
| 105 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 106 |
|
---|
[592] | 107 | contents.setDividerLocation(400);
|
---|
[593] | 108 |
|
---|
| 109 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 110 | mainMenu.setVisible(false);
|
---|
| 111 | }
|
---|
[600] | 112 |
|
---|
| 113 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 114 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[591] | 115 | }
|
---|
| 116 |
|
---|
| 117 | private void initModTypeBox() {
|
---|
[592] | 118 | cmbModTypes.removeAllItems();
|
---|
| 119 |
|
---|
[600] | 120 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
| 121 | for (Type t : ModManager.getInstance().getTypesWithContent()) {
|
---|
| 122 | types.put(t.getName(), t);
|
---|
[591] | 123 | }
|
---|
[600] | 124 | for (Type t : types.values()) {
|
---|
[591] | 125 | cmbModTypes.addItem(t);
|
---|
| 126 | }
|
---|
| 127 | cmbModTypes.setSelectedIndex(0);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | private void initTable() {
|
---|
| 131 | tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
[592] | 132 | tblMods.getSelectionModel().addListSelectionListener(
|
---|
| 133 | new ListSelectionListener() {
|
---|
| 134 | @Override
|
---|
| 135 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 136 | int viewRow = tblMods.getSelectedRow();
|
---|
| 137 | if (viewRow < 0) {
|
---|
| 138 | modSelection(null);
|
---|
| 139 | } else {
|
---|
| 140 | int modelRow = tblMods
|
---|
| 141 | .convertRowIndexToModel(viewRow);
|
---|
[600] | 142 | Mod mod = (Mod) model.getValueAt(modelRow, -1);
|
---|
[592] | 143 | modSelection(mod);
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 | });
|
---|
[608] | 147 | tblMods.addMouseListener(new MouseAdapter() {
|
---|
| 148 | private void common(MouseEvent e) {
|
---|
| 149 | int r = tblMods.rowAtPoint(e.getPoint());
|
---|
| 150 | if (r >= 0 && r < tblMods.getRowCount())
|
---|
| 151 | tblMods.setRowSelectionInterval(r, r);
|
---|
| 152 | else
|
---|
| 153 | tblMods.clearSelection();
|
---|
[592] | 154 |
|
---|
[608] | 155 | int rowindex = tblMods.getSelectedRow();
|
---|
| 156 | if (rowindex >= 0) {
|
---|
| 157 | if (e.isPopupTrigger()
|
---|
| 158 | && e.getComponent() instanceof JTable) {
|
---|
| 159 | int modelRow = tblMods.convertRowIndexToModel(rowindex);
|
---|
| 160 | final Mod mod = (Mod) model.getValueAt(modelRow, -1);
|
---|
| 161 |
|
---|
| 162 | if (mod.isLocalAvailable()) {
|
---|
| 163 | JPopupMenu popup = new JPopupMenu();
|
---|
| 164 | JMenuItem openModFolder = new JMenuItem(bundle
|
---|
| 165 | .getString("openModFolder.text"));
|
---|
| 166 | openModFolder
|
---|
| 167 | .addActionListener(new ActionListener() {
|
---|
| 168 | @Override
|
---|
| 169 | public void actionPerformed(
|
---|
| 170 | ActionEvent arg0) {
|
---|
| 171 | try {
|
---|
| 172 | Desktop.getDesktop().open(
|
---|
| 173 | mod.getLocalPath());
|
---|
| 174 | } catch (IOException e) {
|
---|
| 175 | e.printStackTrace();
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | });
|
---|
| 179 | popup.add(openModFolder);
|
---|
| 180 | popup.show(e.getComponent(), e.getX(), e.getY());
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | @Override
|
---|
| 187 | public void mousePressed(MouseEvent e) {
|
---|
| 188 | common(e);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | @Override
|
---|
| 192 | public void mouseReleased(MouseEvent e) {
|
---|
| 193 | common(e);
|
---|
| 194 | }
|
---|
| 195 | });
|
---|
[593] | 196 | // To get checkbox-cells with background of row
|
---|
| 197 | ((JComponent) tblMods.getDefaultRenderer(Boolean.class))
|
---|
| 198 | .setOpaque(true);
|
---|
| 199 |
|
---|
[591] | 200 | model = new ModTableModel();
|
---|
[600] | 201 | model.addDownloadSizeListener(this);
|
---|
[591] | 202 |
|
---|
| 203 | tblMods.setModel(model);
|
---|
| 204 |
|
---|
| 205 | sorter = new TableRowSorter<ModTableModel>(model);
|
---|
| 206 | tblMods.setRowSorter(sorter);
|
---|
| 207 |
|
---|
[600] | 208 | sorter.setRowFilter(new ModTableFilter(null));
|
---|
[591] | 209 |
|
---|
| 210 | List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
|
---|
[606] | 211 | sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
|
---|
[591] | 212 | sorter.setSortKeys(sortKeys);
|
---|
| 213 |
|
---|
| 214 | for (int i = 0; i < model.getColumnCount(); i++) {
|
---|
| 215 | model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i));
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | private void exit() {
|
---|
| 220 | dispose();
|
---|
[608] | 221 | System.exit(0);
|
---|
[591] | 222 | }
|
---|
| 223 |
|
---|
| 224 | private void saveLocalData() {
|
---|
| 225 | Settings.getInstance().serializeToFile();
|
---|
[596] | 226 | DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename());
|
---|
[591] | 227 | }
|
---|
| 228 |
|
---|
| 229 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 230 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
| 231 | try {
|
---|
| 232 | DepotManager.getInstance().updateInformation(false,
|
---|
| 233 | new DepotCacheUpdateProgressListener() {
|
---|
| 234 |
|
---|
| 235 | @Override
|
---|
| 236 | public void cacheUpdateProgress(String stepName,
|
---|
| 237 | int current, int total) {
|
---|
| 238 | evt.setProgressEnd(total);
|
---|
| 239 | evt.setProgressValue(current);
|
---|
| 240 | evt.setProgressMessage(stepName);
|
---|
| 241 | }
|
---|
| 242 | });
|
---|
[600] | 243 | ModManager.getInstance().init();
|
---|
| 244 | initTable();
|
---|
[592] | 245 | initModTypeBox();
|
---|
[600] | 246 |
|
---|
[592] | 247 | tblMods.setVisible(true);
|
---|
[591] | 248 | } catch (Exception e) {
|
---|
| 249 | e.printStackTrace();
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | @SuppressWarnings("unused")
|
---|
| 254 | private void checkUpdates() {
|
---|
| 255 | if (Settings.getInstance().get("notifyupdates", true)) {
|
---|
[608] | 256 | // TODO
|
---|
[591] | 257 | }
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | @SuppressWarnings("unused")
|
---|
| 261 | private void focus() {
|
---|
| 262 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 263 |
|
---|
| 264 | @Override
|
---|
| 265 | public void run() {
|
---|
| 266 | toFront();
|
---|
| 267 | repaint();
|
---|
| 268 | }
|
---|
| 269 | });
|
---|
| 270 |
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | private void showSettings() {
|
---|
[593] | 274 | new SettingsDialog().setVisible(true);
|
---|
[591] | 275 | }
|
---|
| 276 |
|
---|
[593] | 277 | private void showAbout() {
|
---|
| 278 | new AboutDialog().setVisible(true);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[604] | 281 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 282 | JFileChooser fc = new JFileChooser();
|
---|
| 283 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 284 | if (save)
|
---|
| 285 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 286 | else
|
---|
| 287 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 288 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 289 | fc.setFileFilter(new FileFilter() {
|
---|
| 290 | @Override
|
---|
| 291 | public String getDescription() {
|
---|
| 292 | return "XML files";
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | @Override
|
---|
| 296 | public boolean accept(File arg0) {
|
---|
| 297 | return (arg0.isDirectory())
|
---|
| 298 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 299 | }
|
---|
| 300 | });
|
---|
| 301 | fc.setMultiSelectionEnabled(false);
|
---|
| 302 | return fc;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
[593] | 305 | @SuppressWarnings("unused")
|
---|
| 306 | private void loadConfig() {
|
---|
[604] | 307 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 308 | int res = fc.showOpenDialog(this);
|
---|
| 309 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 310 | if (fc.getSelectedFile().exists())
|
---|
| 311 | model.reloadSelection(fc.getSelectedFile());
|
---|
| 312 | }
|
---|
[593] | 313 | }
|
---|
| 314 |
|
---|
| 315 | @SuppressWarnings("unused")
|
---|
| 316 | private void saveConfig() {
|
---|
[604] | 317 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 318 | int res = fc.showSaveDialog(this);
|
---|
| 319 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 320 | File f = fc.getSelectedFile();
|
---|
| 321 | if (!f.getName().endsWith(".xml"))
|
---|
| 322 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
| 323 | ModManager.getInstance().saveModSelection(f,
|
---|
| 324 | model.getSelectedMods());
|
---|
| 325 | }
|
---|
[593] | 326 | }
|
---|
| 327 |
|
---|
[600] | 328 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 329 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 330 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 331 | @Override
|
---|
| 332 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 333 | evt.setProgressEnd(total);
|
---|
| 334 | evt.setProgressValue(done);
|
---|
| 335 | evt.setProgressMessage(step);
|
---|
| 336 | }
|
---|
| 337 | });
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[593] | 340 | @SuppressWarnings("unused")
|
---|
[600] | 341 | private void tools() {
|
---|
| 342 | // TODO method stub
|
---|
| 343 | JOptionPane.showMessageDialog(this, "tools", "todo",
|
---|
[593] | 344 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 345 | }
|
---|
[596] | 346 |
|
---|
[593] | 347 | @SuppressWarnings("unused")
|
---|
| 348 | private void revertSelection() {
|
---|
[604] | 349 | model.revertSelection();
|
---|
[593] | 350 | }
|
---|
| 351 |
|
---|
[611] | 352 | @SuppressWarnings("unused")
|
---|
| 353 | private void checkDotNet() {
|
---|
| 354 | if (!OniSplit.isDotNETInstalled()) {
|
---|
| 355 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
| 356 | String dlUrl = "";
|
---|
| 357 | switch (Settings.getPlatform()) {
|
---|
| 358 | case WIN:
|
---|
| 359 | switch (Settings.getArchitecture()) {
|
---|
| 360 | case X86:
|
---|
| 361 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
| 362 | break;
|
---|
| 363 | case AMD64:
|
---|
| 364 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
| 365 | break;
|
---|
| 366 | }
|
---|
| 367 | break;
|
---|
| 368 | default:
|
---|
| 369 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
| 370 | }
|
---|
| 371 | hll.setText(bundle.getString("dotNetMissing.text").replaceAll("%1",
|
---|
| 372 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
| 373 | JOptionPane.showMessageDialog(this, hll,
|
---|
| 374 | bundle.getString("dotNetMissing.title"),
|
---|
| 375 | JOptionPane.ERROR_MESSAGE);
|
---|
| 376 | exit();
|
---|
| 377 | }
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[602] | 380 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
|
---|
| 381 | private void checkMandatoryFiles(final BackgroundEvent evt) {
|
---|
[604] | 382 | TreeSet<Mod> mand = new TreeSet<Mod>();
|
---|
[603] | 383 | for (Mod m : ModManager.getInstance().getMandatoryTools()) {
|
---|
[604] | 384 | if (m.isNewerAvailable()) {
|
---|
| 385 | mand.add(m);
|
---|
| 386 | }
|
---|
[602] | 387 | }
|
---|
[603] | 388 | for (Mod m : ModManager.getInstance().getMandatoryMods()) {
|
---|
[604] | 389 | if (m.isNewerAvailable()) {
|
---|
| 390 | mand.add(m);
|
---|
| 391 | }
|
---|
[602] | 392 | }
|
---|
[604] | 393 | if (mand.size() > 0) {
|
---|
| 394 | ModDownloader m = new ModDownloader(mand,
|
---|
| 395 | new ModDownloaderListener() {
|
---|
| 396 | @Override
|
---|
| 397 | public void updateStatus(ModDownloader source,
|
---|
| 398 | State state, int filesDown, int filesTotal,
|
---|
[605] | 399 | int bytesDown, int bytesTotal, int duration,
|
---|
| 400 | int remaining, int speed) {
|
---|
[604] | 401 | evt.setProgressEnd(filesTotal);
|
---|
| 402 | evt.setProgressValue(filesDown);
|
---|
| 403 | }
|
---|
| 404 | });
|
---|
| 405 | while (!m.isFinished()) {
|
---|
| 406 | try {
|
---|
[606] | 407 | Thread.sleep(10);
|
---|
[604] | 408 | } catch (InterruptedException e) {
|
---|
| 409 | // TODO Auto-generated catch block
|
---|
| 410 | e.printStackTrace();
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | evt.setProgressMessage(bundle.getString("mandatoryToolsInstall.title"));
|
---|
| 415 | Installer.installTools(ModManager.getInstance().getMandatoryTools());
|
---|
[602] | 416 | }
|
---|
| 417 |
|
---|
[600] | 418 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
| 419 | private void install(final BackgroundEvent evt) {
|
---|
| 420 | TreeSet<Mod> mods = new TreeSet<Mod>();
|
---|
[602] | 421 | mods.addAll(ModManager.getInstance().getMandatoryMods());
|
---|
[600] | 422 | mods.addAll(model.getSelectedMods());
|
---|
| 423 |
|
---|
[605] | 424 | boolean instReady = false;
|
---|
| 425 |
|
---|
| 426 | while (!instReady) {
|
---|
| 427 | System.out.println("Checking downloads:");
|
---|
| 428 | TreeSet<Mod> toDownload = new TreeSet<Mod>();
|
---|
| 429 | for (Mod m : mods) {
|
---|
| 430 | if (!m.isLocalAvailable())
|
---|
| 431 | toDownload.add(m);
|
---|
| 432 | }
|
---|
| 433 | if (toDownload.size() > 0) {
|
---|
| 434 | System.out.println("Download files: " + toDownload.toString());
|
---|
| 435 | Downloader dl = new Downloader(toDownload);
|
---|
| 436 | dl.setVisible(true);
|
---|
| 437 | if (!dl.isFinished())
|
---|
| 438 | break;
|
---|
| 439 | }
|
---|
| 440 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
|
---|
| 441 | .checkDependencies(mods);
|
---|
| 442 | if (dependencies.size() > 0) {
|
---|
| 443 | System.out.println("Unmet dependencies: "
|
---|
| 444 | + dependencies.toString());
|
---|
| 445 | for (Mod m : dependencies.keySet()) {
|
---|
| 446 | for (Mod mDep : dependencies.get(m))
|
---|
| 447 | mods.add(mDep);
|
---|
| 448 | }
|
---|
| 449 | } else {
|
---|
| 450 | HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
|
---|
[608] | 451 | .checkIncompabitilites(mods);
|
---|
[605] | 452 | if (conflicts.size() > 0) {
|
---|
[608] | 453 | System.err.println("Incompatible mods: "
|
---|
[605] | 454 | + conflicts.toString());
|
---|
| 455 | break;
|
---|
| 456 | } else {
|
---|
| 457 | instReady = true;
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
[600] | 460 | }
|
---|
| 461 |
|
---|
[605] | 462 | if (instReady) {
|
---|
[608] | 463 | System.out.println("Install mods: " + mods.toString());
|
---|
| 464 |
|
---|
[605] | 465 | Installer.install(mods, new InstallProgressListener() {
|
---|
| 466 | @Override
|
---|
| 467 | public void installProgressUpdate(int done, int total,
|
---|
| 468 | String step) {
|
---|
| 469 | evt.setProgressEnd(total);
|
---|
| 470 | evt.setProgressValue(done);
|
---|
| 471 | evt.setProgressMessage(step);
|
---|
| 472 | }
|
---|
| 473 | });
|
---|
[606] | 474 |
|
---|
| 475 | JOptionPane.showMessageDialog(this,
|
---|
| 476 | bundle.getString("installDone.text"),
|
---|
| 477 | bundle.getString("installDone.title"),
|
---|
| 478 | JOptionPane.INFORMATION_MESSAGE);
|
---|
[605] | 479 | }
|
---|
[600] | 480 | }
|
---|
| 481 |
|
---|
| 482 | private void modSelection(Mod m) {
|
---|
[592] | 483 | lblSubmitterVal.setText("");
|
---|
| 484 | lblCreatorVal.setText("");
|
---|
| 485 | lblDescriptionVal.setText("");
|
---|
[606] | 486 | lblTypesVal.setText("");
|
---|
| 487 | lblPlatformVal.setText("");
|
---|
[600] | 488 | if (m != null) {
|
---|
| 489 | lblSubmitterVal.setText(m.getName());
|
---|
| 490 | lblCreatorVal.setText(m.getCreator());
|
---|
| 491 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 492 |
|
---|
| 493 | String types = "";
|
---|
| 494 | for (Type t : m.getTypes()) {
|
---|
| 495 | if (types.length() > 0)
|
---|
| 496 | types += ", ";
|
---|
| 497 | types += t.getName();
|
---|
| 498 | }
|
---|
| 499 | lblTypesVal.setText(types);
|
---|
| 500 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[591] | 501 | }
|
---|
[592] | 502 | // TODO
|
---|
[591] | 503 | }
|
---|
| 504 |
|
---|
| 505 | @SuppressWarnings("unused")
|
---|
[592] | 506 | private void modTypeSelection() {
|
---|
[600] | 507 | Type t = (Type) cmbModTypes.getSelectedItem();
|
---|
[592] | 508 | if (t != null)
|
---|
[600] | 509 | sorter.setRowFilter(new ModTableFilter(t));
|
---|
[592] | 510 | else
|
---|
[600] | 511 | sorter.setRowFilter(new ModTableFilter(null));
|
---|
[591] | 512 | }
|
---|
[593] | 513 |
|
---|
| 514 | @Override
|
---|
[600] | 515 | public void downloadSizeChanged(int newSize) {
|
---|
| 516 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 520 | private void initialize(final BackgroundEvent evt) {
|
---|
| 521 | if (!Installer.isEditionInitialized()) {
|
---|
| 522 | int res = JOptionPane.showConfirmDialog(this,
|
---|
| 523 | bundle.getString("askInitialize.text"),
|
---|
| 524 | bundle.getString("askInitialize.title"),
|
---|
| 525 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
---|
| 526 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 527 | exit();
|
---|
| 528 | } else {
|
---|
| 529 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 530 | @Override
|
---|
| 531 | public void installProgressUpdate(int done, int total,
|
---|
| 532 | String step) {
|
---|
| 533 | evt.setProgressEnd(total);
|
---|
| 534 | evt.setProgressValue(done);
|
---|
| 535 | evt.setProgressMessage(step);
|
---|
| 536 | }
|
---|
| 537 | });
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
[606] | 541 |
|
---|
[605] | 542 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 543 | Vector<String> params = new Vector<String>();
|
---|
| 544 | switch (Settings.getPlatform()) {
|
---|
| 545 | case WIN:
|
---|
| 546 | params.add(new File(Paths.getEditionBasePath(), "Oni.exe")
|
---|
| 547 | .getPath());
|
---|
| 548 | break;
|
---|
| 549 | case MACOS:
|
---|
[608] | 550 | params.add(new File(Paths.getEditionBasePath(),
|
---|
| 551 | "Oni.app/Contents/MacOS/Oni").getPath());
|
---|
[605] | 552 | break;
|
---|
| 553 | case LINUX:
|
---|
| 554 | String wine = Settings.getWinePath();
|
---|
| 555 | if (wine != null) {
|
---|
| 556 | params.add(wine);
|
---|
| 557 | params.add(new File(Paths.getEditionBasePath(), "Oni.exe")
|
---|
| 558 | .getPath());
|
---|
| 559 | }
|
---|
| 560 | break;
|
---|
| 561 | default:
|
---|
| 562 | }
|
---|
| 563 | if (params.size() > 0) {
|
---|
| 564 | params.add("-debugfiles");
|
---|
| 565 | }
|
---|
| 566 | return params;
|
---|
| 567 | }
|
---|
[600] | 568 |
|
---|
[605] | 569 | @SuppressWarnings("unused")
|
---|
| 570 | private void oniFull() {
|
---|
| 571 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 572 | if (params.size() > 0) {
|
---|
| 573 | try {
|
---|
[606] | 574 | ProcessBuilder pb = new ProcessBuilder(params);
|
---|
| 575 | pb.directory(Paths.getEditionBasePath());
|
---|
| 576 | pb.start();
|
---|
[605] | 577 | } catch (IOException e) {
|
---|
| 578 | // TODO Auto-generated catch block
|
---|
| 579 | e.printStackTrace();
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | @SuppressWarnings("unused")
|
---|
| 585 | private void oniWin() {
|
---|
| 586 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 587 | if (params.size() > 0) {
|
---|
| 588 | params.add("-noswitch");
|
---|
| 589 | try {
|
---|
[606] | 590 | ProcessBuilder pb = new ProcessBuilder(params);
|
---|
| 591 | pb.directory(Paths.getEditionBasePath());
|
---|
| 592 | pb.start();
|
---|
[605] | 593 | } catch (IOException e) {
|
---|
| 594 | // TODO Auto-generated catch block
|
---|
| 595 | e.printStackTrace();
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[608] | 600 | @SuppressWarnings("unused")
|
---|
| 601 | private void openEditionFolder() {
|
---|
| 602 | try {
|
---|
| 603 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
| 604 | } catch (IOException e) {
|
---|
| 605 | e.printStackTrace();
|
---|
| 606 | }
|
---|
| 607 | }
|
---|
| 608 |
|
---|
[600] | 609 | @Override
|
---|
[593] | 610 | public void handleAbout(ApplicationEvent event) {
|
---|
| 611 | event.setHandled(true);
|
---|
| 612 | showAbout();
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | @Override
|
---|
| 616 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | @Override
|
---|
| 620 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | @Override
|
---|
| 624 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 625 | showSettings();
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | @Override
|
---|
| 629 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | @Override
|
---|
| 633 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 634 | event.setHandled(true);
|
---|
| 635 | saveLocalData();
|
---|
| 636 | exit();
|
---|
[593] | 637 | }
|
---|
| 638 |
|
---|
| 639 | @Override
|
---|
| 640 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 641 | }
|
---|
[600] | 642 |
|
---|
[592] | 643 | }
|
---|