[591] | 1 | package net.oni2.aeinstaller.gui;
|
---|
| 2 |
|
---|
[627] | 3 | import java.awt.BorderLayout;
|
---|
[608] | 4 | import java.awt.Desktop;
|
---|
[632] | 5 | import java.awt.GridLayout;
|
---|
[608] | 6 | import java.awt.event.ActionEvent;
|
---|
[627] | 7 | import java.awt.event.ItemEvent;
|
---|
| 8 | import java.awt.event.ItemListener;
|
---|
[604] | 9 | import java.io.File;
|
---|
[605] | 10 | import java.io.IOException;
|
---|
[623] | 11 | import java.net.URL;
|
---|
[634] | 12 | import java.util.Date;
|
---|
[605] | 13 | import java.util.HashMap;
|
---|
| 14 | import java.util.HashSet;
|
---|
[591] | 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;
|
---|
[627] | 24 | import javax.swing.JCheckBox;
|
---|
[591] | 25 | import javax.swing.JComboBox;
|
---|
[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;
|
---|
[627] | 32 | import javax.swing.JPanel;
|
---|
[630] | 33 | import javax.swing.JRadioButton;
|
---|
[592] | 34 | import javax.swing.JSplitPane;
|
---|
[591] | 35 | import javax.swing.SwingUtilities;
|
---|
[631] | 36 | import javax.swing.ToolTipManager;
|
---|
[604] | 37 | import javax.swing.filechooser.FileFilter;
|
---|
[591] | 38 |
|
---|
[623] | 39 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
| 40 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[604] | 41 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 42 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[593] | 43 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[600] | 44 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[591] | 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;
|
---|
[631] | 58 | import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
|
---|
| 59 | import net.oni2.aeinstaller.gui.modtable.ModTable;
|
---|
[591] | 60 | import net.oni2.aeinstaller.gui.settings.SettingsDialog;
|
---|
[625] | 61 | import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
|
---|
[591] | 62 |
|
---|
| 63 | import org.javabuilders.BuildResult;
|
---|
| 64 | import org.javabuilders.annotations.DoInBackground;
|
---|
| 65 | import org.javabuilders.event.BackgroundEvent;
|
---|
| 66 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 67 | import org.simplericity.macify.eawt.ApplicationEvent;
|
---|
| 68 | import org.simplericity.macify.eawt.ApplicationListener;
|
---|
[591] | 69 |
|
---|
| 70 | /**
|
---|
| 71 | * @author Christian Illy
|
---|
| 72 | */
|
---|
[600] | 73 | public class MainWin extends JFrame implements ApplicationListener,
|
---|
[631] | 74 | DownloadSizeListener, ModSelectionListener {
|
---|
[591] | 75 | private static final long serialVersionUID = -4027395051382659650L;
|
---|
| 76 |
|
---|
[629] | 77 | private ResourceBundle bundle = ResourceBundle
|
---|
| 78 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 79 | + getClass().getSimpleName());
|
---|
[591] | 80 | @SuppressWarnings("unused")
|
---|
| 81 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 82 |
|
---|
[593] | 83 | private JMenu mainMenu;
|
---|
[623] | 84 | private JMenu toolsMenu;
|
---|
| 85 | private TreeSet<JMenuItem> toolsMenuItems = new TreeSet<JMenuItem>();
|
---|
[593] | 86 |
|
---|
[592] | 87 | private JSplitPane contents;
|
---|
| 88 |
|
---|
[591] | 89 | private JComboBox cmbModTypes;
|
---|
[630] | 90 | private JRadioButton radAll;
|
---|
| 91 | private JRadioButton radOnline;
|
---|
| 92 | private JRadioButton radLocal;
|
---|
[631] | 93 | private ModTable tblMods;
|
---|
[600] | 94 | private JLabel lblDownloadSizeVal;
|
---|
[591] | 95 |
|
---|
[592] | 96 | private JLabel lblSubmitterVal;
|
---|
| 97 | private JLabel lblCreatorVal;
|
---|
[606] | 98 | private JLabel lblTypesVal;
|
---|
| 99 | private JLabel lblPlatformVal;
|
---|
[621] | 100 | private JLabel lblPackageNumberVal;
|
---|
[592] | 101 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 102 |
|
---|
[600] | 103 | private JButton btnInstall;
|
---|
| 104 |
|
---|
[621] | 105 | private TreeSet<Mod> execUpdates = null;
|
---|
| 106 |
|
---|
| 107 | private enum EInstallResult {
|
---|
| 108 | DONE,
|
---|
| 109 | OFFLINE,
|
---|
| 110 | INCOMPATIBLE
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 | private EInstallResult installDone = EInstallResult.DONE;
|
---|
| 114 |
|
---|
[591] | 115 | /**
|
---|
| 116 | * Constructor of main window.
|
---|
| 117 | */
|
---|
| 118 | public MainWin() {
|
---|
[593] | 119 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 120 | + " - v"
|
---|
| 121 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 122 |
|
---|
[592] | 123 | contents.setDividerLocation(400);
|
---|
[631] | 124 | contents.setResizeWeight(0.4);
|
---|
[593] | 125 |
|
---|
| 126 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 127 | mainMenu.setVisible(false);
|
---|
| 128 | }
|
---|
[600] | 129 |
|
---|
[631] | 130 | ToolTipManager.sharedInstance().setInitialDelay(250);
|
---|
| 131 |
|
---|
[600] | 132 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 133 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[630] | 134 | radAll.setSelected(true);
|
---|
[631] | 135 |
|
---|
| 136 | tblMods.addModSelectionListener(this);
|
---|
| 137 | tblMods.addDownloadSizeListener(this);
|
---|
[591] | 138 | }
|
---|
| 139 |
|
---|
| 140 | private void initModTypeBox() {
|
---|
[592] | 141 | cmbModTypes.removeAllItems();
|
---|
| 142 |
|
---|
[600] | 143 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
| 144 | for (Type t : ModManager.getInstance().getTypesWithContent()) {
|
---|
| 145 | types.put(t.getName(), t);
|
---|
[591] | 146 | }
|
---|
[630] | 147 | cmbModTypes.addItem("-All-");
|
---|
[600] | 148 | for (Type t : types.values()) {
|
---|
[591] | 149 | cmbModTypes.addItem(t);
|
---|
| 150 | }
|
---|
| 151 | cmbModTypes.setSelectedIndex(0);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | private void exit() {
|
---|
| 155 | dispose();
|
---|
[608] | 156 | System.exit(0);
|
---|
[591] | 157 | }
|
---|
| 158 |
|
---|
| 159 | private void saveLocalData() {
|
---|
| 160 | Settings.getInstance().serializeToFile();
|
---|
[596] | 161 | DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename());
|
---|
[591] | 162 | }
|
---|
| 163 |
|
---|
| 164 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 165 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
[621] | 166 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
[634] | 167 | long start = new Date().getTime();
|
---|
| 168 |
|
---|
[621] | 169 | try {
|
---|
[634] | 170 | DepotManager.getInstance().updateInformation(false);
|
---|
[621] | 171 | } catch (Exception e) {
|
---|
| 172 | e.printStackTrace();
|
---|
| 173 | }
|
---|
[634] | 174 |
|
---|
| 175 | System.out.println("Took: " + (new Date().getTime() - start)
|
---|
| 176 | + " msec");
|
---|
[621] | 177 | }
|
---|
[633] | 178 |
|
---|
[621] | 179 | ModManager.getInstance().init();
|
---|
[631] | 180 | tblMods.reloadData();
|
---|
[621] | 181 | initModTypeBox();
|
---|
[600] | 182 |
|
---|
[621] | 183 | tblMods.setVisible(true);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | @SuppressWarnings("unused")
|
---|
| 187 | private void checkUpdates(Object evtSource) {
|
---|
| 188 | if ((evtSource != this)
|
---|
| 189 | || Settings.getInstance().get("notifyupdates", true)) {
|
---|
| 190 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 191 | if (evtSource != this) {
|
---|
| 192 | JOptionPane.showMessageDialog(this,
|
---|
| 193 | bundle.getString("offlineMode.text"),
|
---|
| 194 | bundle.getString("offlineMode.title"),
|
---|
| 195 | JOptionPane.WARNING_MESSAGE);
|
---|
| 196 | }
|
---|
| 197 | } else {
|
---|
| 198 | TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
|
---|
| 199 | TreeSet<Mod> tools = ModManager.getInstance()
|
---|
| 200 | .getUpdatableTools();
|
---|
| 201 | int size = 0;
|
---|
[632] | 202 | JPanel panPackages = new JPanel(new GridLayout(0, 1));
|
---|
| 203 | execUpdates = new TreeSet<Mod>();
|
---|
| 204 | execUpdates.addAll(mods);
|
---|
| 205 | execUpdates.addAll(tools);
|
---|
| 206 | for (final Mod m : mods) {
|
---|
[621] | 207 | size += m.getZipSize();
|
---|
[632] | 208 | JCheckBox check = new JCheckBox("Mod: " + m.getName());
|
---|
| 209 | check.setSelected(true);
|
---|
| 210 | check.addItemListener(new ItemListener() {
|
---|
| 211 | @Override
|
---|
| 212 | public void itemStateChanged(ItemEvent e) {
|
---|
| 213 | if (e.getStateChange() == ItemEvent.SELECTED)
|
---|
| 214 | execUpdates.add(m);
|
---|
| 215 | else
|
---|
| 216 | execUpdates.remove(m);
|
---|
| 217 | }
|
---|
| 218 | });
|
---|
| 219 | panPackages.add(check);
|
---|
[621] | 220 | }
|
---|
[632] | 221 | for (final Mod m : tools) {
|
---|
[621] | 222 | size += m.getZipSize();
|
---|
[632] | 223 | JCheckBox check = new JCheckBox("Tool: " + m.getName());
|
---|
| 224 | check.setSelected(true);
|
---|
| 225 | panPackages.add(check);
|
---|
[621] | 226 | }
|
---|
[622] | 227 | if (size > 0) {
|
---|
[627] | 228 | // Build info dialog content
|
---|
[632] | 229 | JPanel packages = new JPanel(new BorderLayout(0, 7));
|
---|
| 230 | JLabel lblIntro = new JLabel("<html>"
|
---|
| 231 | + bundle.getString("updatesAvailable.text")
|
---|
| 232 | + "</html>");
|
---|
| 233 | JLabel lblSize = new JLabel("<html>"
|
---|
| 234 | + String.format(bundle
|
---|
| 235 | .getString("updatesAvailableSize.text"),
|
---|
| 236 | SizeFormatter.format(size, 3)) + "</html>");
|
---|
| 237 | packages.add(lblIntro, BorderLayout.NORTH);
|
---|
| 238 | packages.add(panPackages, BorderLayout.CENTER);
|
---|
| 239 | packages.add(lblSize, BorderLayout.SOUTH);
|
---|
[627] | 240 |
|
---|
[632] | 241 | JPanel pan = new JPanel(new BorderLayout(0, 25));
|
---|
| 242 | pan.add(packages, BorderLayout.CENTER);
|
---|
[627] | 243 | JCheckBox checkFutureUpdates = new JCheckBox(
|
---|
| 244 | bundle.getString("checkOnStartup.text"));
|
---|
| 245 | checkFutureUpdates.setSelected(Settings.getInstance().get(
|
---|
| 246 | "notifyupdates", true));
|
---|
| 247 | checkFutureUpdates.addItemListener(new ItemListener() {
|
---|
| 248 | @Override
|
---|
| 249 | public void itemStateChanged(ItemEvent evt) {
|
---|
| 250 | Settings.getInstance().put("notifyupdates",
|
---|
| 251 | evt.getStateChange() == ItemEvent.SELECTED);
|
---|
| 252 | }
|
---|
| 253 | });
|
---|
| 254 | pan.add(checkFutureUpdates, BorderLayout.SOUTH);
|
---|
| 255 |
|
---|
| 256 | // Show dialog
|
---|
| 257 | int res = JOptionPane.showConfirmDialog(this, pan,
|
---|
[622] | 258 | bundle.getString("updatesAvailable.title"),
|
---|
| 259 | JOptionPane.YES_NO_OPTION,
|
---|
| 260 | JOptionPane.QUESTION_MESSAGE);
|
---|
[632] | 261 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 262 | execUpdates = null;
|
---|
[622] | 263 | }
|
---|
[621] | 264 | }
|
---|
| 265 | }
|
---|
[591] | 266 | }
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[624] | 269 | @SuppressWarnings("unused")
|
---|
| 270 | private void doUpdate() {
|
---|
[632] | 271 | if (execUpdates != null && execUpdates.size() > 0) {
|
---|
[624] | 272 | Downloader dl = new Downloader(execUpdates);
|
---|
| 273 | try {
|
---|
| 274 | dl.setVisible(true);
|
---|
| 275 | if (dl.isFinished()) {
|
---|
| 276 | TreeSet<Integer> installed = Installer.getInstalledTools();
|
---|
| 277 | TreeSet<Mod> tools = new TreeSet<Mod>();
|
---|
| 278 | for (Mod m : execUpdates)
|
---|
| 279 | if (m.isTool()
|
---|
| 280 | && installed.contains(m.getPackageNumber()))
|
---|
| 281 | tools.add(m);
|
---|
| 282 | if (tools.size() > 0) {
|
---|
| 283 | Installer.installTools(tools);
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | } finally {
|
---|
| 287 | dl.dispose();
|
---|
| 288 | }
|
---|
[591] | 289 | }
|
---|
[621] | 290 | execUpdates = null;
|
---|
[591] | 291 | }
|
---|
| 292 |
|
---|
| 293 | @SuppressWarnings("unused")
|
---|
| 294 | private void focus() {
|
---|
| 295 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 296 |
|
---|
| 297 | @Override
|
---|
| 298 | public void run() {
|
---|
| 299 | toFront();
|
---|
| 300 | repaint();
|
---|
| 301 | }
|
---|
| 302 | });
|
---|
| 303 |
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | private void showSettings() {
|
---|
[593] | 307 | new SettingsDialog().setVisible(true);
|
---|
[591] | 308 | }
|
---|
| 309 |
|
---|
[593] | 310 | private void showAbout() {
|
---|
| 311 | new AboutDialog().setVisible(true);
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[604] | 314 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 315 | JFileChooser fc = new JFileChooser();
|
---|
| 316 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 317 | if (save)
|
---|
| 318 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 319 | else
|
---|
| 320 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 321 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 322 | fc.setFileFilter(new FileFilter() {
|
---|
| 323 | @Override
|
---|
| 324 | public String getDescription() {
|
---|
| 325 | return "XML files";
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | @Override
|
---|
| 329 | public boolean accept(File arg0) {
|
---|
| 330 | return (arg0.isDirectory())
|
---|
| 331 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 332 | }
|
---|
| 333 | });
|
---|
| 334 | fc.setMultiSelectionEnabled(false);
|
---|
| 335 | return fc;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[593] | 338 | @SuppressWarnings("unused")
|
---|
| 339 | private void loadConfig() {
|
---|
[604] | 340 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 341 | int res = fc.showOpenDialog(this);
|
---|
| 342 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 343 | if (fc.getSelectedFile().exists())
|
---|
[631] | 344 | tblMods.reloadSelection(fc.getSelectedFile());
|
---|
[604] | 345 | }
|
---|
[593] | 346 | }
|
---|
| 347 |
|
---|
| 348 | @SuppressWarnings("unused")
|
---|
| 349 | private void saveConfig() {
|
---|
[604] | 350 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 351 | int res = fc.showSaveDialog(this);
|
---|
| 352 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 353 | File f = fc.getSelectedFile();
|
---|
| 354 | if (!f.getName().endsWith(".xml"))
|
---|
| 355 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
| 356 | ModManager.getInstance().saveModSelection(f,
|
---|
[631] | 357 | tblMods.getSelectedMods());
|
---|
[604] | 358 | }
|
---|
[593] | 359 | }
|
---|
| 360 |
|
---|
[600] | 361 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 362 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 363 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 364 | @Override
|
---|
| 365 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 366 | evt.setProgressEnd(total);
|
---|
| 367 | evt.setProgressValue(done);
|
---|
| 368 | evt.setProgressMessage(step);
|
---|
| 369 | }
|
---|
| 370 | });
|
---|
| 371 | }
|
---|
| 372 |
|
---|
[593] | 373 | @SuppressWarnings("unused")
|
---|
[600] | 374 | private void tools() {
|
---|
[625] | 375 | new ToolManager().setVisible(true);
|
---|
[593] | 376 | }
|
---|
[596] | 377 |
|
---|
[593] | 378 | @SuppressWarnings("unused")
|
---|
[623] | 379 | private void refreshToolsMenu() {
|
---|
| 380 | for (JMenuItem i : toolsMenuItems) {
|
---|
| 381 | toolsMenu.remove(i);
|
---|
| 382 | }
|
---|
| 383 | toolsMenuItems.clear();
|
---|
| 384 | for (Mod m : ModManager.getInstance().getInstalledTools()) {
|
---|
| 385 | if (m.getExeFile() != null && m.getExeFile().exists()) {
|
---|
| 386 | JMenuItem item = new JMenuItem();
|
---|
| 387 | final Vector<String> params = new Vector<String>();
|
---|
| 388 | params.add(m.getExeFile().getPath());
|
---|
| 389 | final File wd = m.getWorkingDir();
|
---|
| 390 | Icon ico = null;
|
---|
| 391 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 392 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 393 | } else {
|
---|
[624] | 394 | URL icon = AEInstaller2.class
|
---|
| 395 | .getResource("images/transparent.png");
|
---|
[623] | 396 | ico = new ImageIcon(icon);
|
---|
| 397 | }
|
---|
| 398 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 399 | private static final long serialVersionUID = 1L;
|
---|
| 400 |
|
---|
| 401 | @Override
|
---|
| 402 | public void actionPerformed(ActionEvent e) {
|
---|
| 403 | AppExecution.execute(params, wd);
|
---|
| 404 | }
|
---|
| 405 | });
|
---|
| 406 | toolsMenuItems.add(item);
|
---|
| 407 | toolsMenu.add(item);
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | @SuppressWarnings("unused")
|
---|
[593] | 413 | private void revertSelection() {
|
---|
[631] | 414 | tblMods.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());
|
---|
[631] | 462 | mods.addAll(tblMods.getSelectedMods());
|
---|
[600] | 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) {
|
---|
[623] | 511 | TreeSet<Mod> actuallyMods = new TreeSet<Mod>();
|
---|
| 512 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 513 |
|
---|
| 514 | for (Mod m : mods) {
|
---|
| 515 | if (m.isTool())
|
---|
| 516 | actuallyTools.add(m);
|
---|
| 517 | else
|
---|
| 518 | actuallyMods.add(m);
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | if (actuallyTools.size() > 0) {
|
---|
| 522 | Installer.installTools(actuallyTools);
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | Installer.install(actuallyMods, new InstallProgressListener() {
|
---|
[605] | 526 | @Override
|
---|
| 527 | public void installProgressUpdate(int done, int total,
|
---|
| 528 | String step) {
|
---|
| 529 | evt.setProgressEnd(total);
|
---|
| 530 | evt.setProgressValue(done);
|
---|
| 531 | evt.setProgressMessage(step);
|
---|
| 532 | }
|
---|
| 533 | });
|
---|
[621] | 534 | installDone = EInstallResult.DONE;
|
---|
[605] | 535 | }
|
---|
[600] | 536 | }
|
---|
[618] | 537 |
|
---|
[617] | 538 | @SuppressWarnings("unused")
|
---|
| 539 | private void installDone() {
|
---|
[621] | 540 | switch (installDone) {
|
---|
| 541 | case DONE:
|
---|
| 542 | JOptionPane.showMessageDialog(this,
|
---|
| 543 | bundle.getString("installDone.text"),
|
---|
| 544 | bundle.getString("installDone.title"),
|
---|
| 545 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 546 | break;
|
---|
| 547 | case OFFLINE:
|
---|
| 548 | JOptionPane.showMessageDialog(this,
|
---|
| 549 | bundle.getString("offlineMode.text"),
|
---|
| 550 | bundle.getString("offlineMode.title"),
|
---|
| 551 | JOptionPane.WARNING_MESSAGE);
|
---|
| 552 | break;
|
---|
| 553 | case INCOMPATIBLE:
|
---|
| 554 | break;
|
---|
| 555 | }
|
---|
[617] | 556 | }
|
---|
[600] | 557 |
|
---|
[631] | 558 | @Override
|
---|
| 559 | public void modSelectionChanged(ModTable source, Mod m) {
|
---|
[592] | 560 | lblSubmitterVal.setText("");
|
---|
| 561 | lblCreatorVal.setText("");
|
---|
| 562 | lblDescriptionVal.setText("");
|
---|
[606] | 563 | lblTypesVal.setText("");
|
---|
| 564 | lblPlatformVal.setText("");
|
---|
[621] | 565 | lblPackageNumberVal.setText("");
|
---|
[600] | 566 | if (m != null) {
|
---|
| 567 | lblSubmitterVal.setText(m.getName());
|
---|
| 568 | lblCreatorVal.setText(m.getCreator());
|
---|
| 569 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 570 |
|
---|
| 571 | String types = "";
|
---|
| 572 | for (Type t : m.getTypes()) {
|
---|
| 573 | if (types.length() > 0)
|
---|
| 574 | types += ", ";
|
---|
| 575 | types += t.getName();
|
---|
| 576 | }
|
---|
| 577 | lblTypesVal.setText(types);
|
---|
| 578 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 579 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[591] | 580 | }
|
---|
| 581 | }
|
---|
| 582 |
|
---|
[630] | 583 | private void updateTableFilter() {
|
---|
| 584 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 585 | Type t = null;
|
---|
| 586 | if (o instanceof Type)
|
---|
| 587 | t = (Type) o;
|
---|
| 588 | int downloadState = 0;
|
---|
| 589 | if (radOnline.isSelected())
|
---|
| 590 | downloadState = 1;
|
---|
| 591 | if (radLocal.isSelected())
|
---|
| 592 | downloadState = 2;
|
---|
[631] | 593 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 594 | }
|
---|
| 595 |
|
---|
[591] | 596 | @SuppressWarnings("unused")
|
---|
[592] | 597 | private void modTypeSelection() {
|
---|
[630] | 598 | updateTableFilter();
|
---|
[591] | 599 | }
|
---|
[593] | 600 |
|
---|
[630] | 601 | @SuppressWarnings("unused")
|
---|
| 602 | private void showTypeSelection() {
|
---|
| 603 | updateTableFilter();
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[593] | 606 | @Override
|
---|
[600] | 607 | public void downloadSizeChanged(int newSize) {
|
---|
| 608 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 609 | }
|
---|
| 610 |
|
---|
[616] | 611 | @SuppressWarnings("unused")
|
---|
| 612 | private void checkInitialize() {
|
---|
[600] | 613 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 614 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 615 | JOptionPane.showMessageDialog(this,
|
---|
| 616 | bundle.getString("noOniSplit.text"),
|
---|
| 617 | bundle.getString("noOniSplit.title"),
|
---|
| 618 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 619 | exit();
|
---|
[621] | 620 | } else {
|
---|
| 621 | int res = JOptionPane
|
---|
| 622 | .showConfirmDialog(this,
|
---|
| 623 | bundle.getString("askInitialize.text"),
|
---|
| 624 | bundle.getString("askInitialize.title"),
|
---|
| 625 | JOptionPane.YES_NO_OPTION,
|
---|
| 626 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 627 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 628 | saveLocalData();
|
---|
| 629 | exit();
|
---|
| 630 | }
|
---|
[600] | 631 | }
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
[606] | 634 |
|
---|
[616] | 635 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 636 | private void initialize(final BackgroundEvent evt) {
|
---|
| 637 | if (!Installer.isEditionInitialized()) {
|
---|
| 638 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 639 | @Override
|
---|
| 640 | public void installProgressUpdate(int done, int total,
|
---|
| 641 | String step) {
|
---|
| 642 | evt.setProgressEnd(total);
|
---|
| 643 | evt.setProgressValue(done);
|
---|
| 644 | evt.setProgressMessage(step);
|
---|
| 645 | }
|
---|
| 646 | });
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 |
|
---|
[605] | 650 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 651 | Vector<String> params = new Vector<String>();
|
---|
[618] | 652 | File exe = null;
|
---|
[605] | 653 | switch (Settings.getPlatform()) {
|
---|
| 654 | case WIN:
|
---|
[618] | 655 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 656 | if (exe.exists())
|
---|
| 657 | params.add(exe.getPath());
|
---|
[605] | 658 | break;
|
---|
| 659 | case MACOS:
|
---|
[618] | 660 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 661 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 662 | if (exe.exists())
|
---|
| 663 | params.add(exe.getPath());
|
---|
[605] | 664 | break;
|
---|
| 665 | case LINUX:
|
---|
| 666 | String wine = Settings.getWinePath();
|
---|
[618] | 667 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 668 | if (exe.exists()) {
|
---|
| 669 | if (wine != null) {
|
---|
| 670 | params.add(wine);
|
---|
| 671 | params.add(exe.getPath());
|
---|
| 672 | }
|
---|
[605] | 673 | }
|
---|
| 674 | break;
|
---|
| 675 | default:
|
---|
| 676 | }
|
---|
| 677 | if (params.size() > 0) {
|
---|
| 678 | params.add("-debugfiles");
|
---|
| 679 | }
|
---|
| 680 | return params;
|
---|
| 681 | }
|
---|
[600] | 682 |
|
---|
[605] | 683 | @SuppressWarnings("unused")
|
---|
| 684 | private void oniFull() {
|
---|
| 685 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 686 | if (params.size() > 0) {
|
---|
[623] | 687 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 688 | }
|
---|
| 689 | }
|
---|
| 690 |
|
---|
| 691 | @SuppressWarnings("unused")
|
---|
| 692 | private void oniWin() {
|
---|
| 693 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 694 | if (params.size() > 0) {
|
---|
| 695 | params.add("-noswitch");
|
---|
[623] | 696 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 697 | }
|
---|
| 698 | }
|
---|
| 699 |
|
---|
[608] | 700 | @SuppressWarnings("unused")
|
---|
| 701 | private void openEditionFolder() {
|
---|
| 702 | try {
|
---|
| 703 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
| 704 | } catch (IOException e) {
|
---|
| 705 | e.printStackTrace();
|
---|
| 706 | }
|
---|
| 707 | }
|
---|
| 708 |
|
---|
[600] | 709 | @Override
|
---|
[593] | 710 | public void handleAbout(ApplicationEvent event) {
|
---|
| 711 | event.setHandled(true);
|
---|
| 712 | showAbout();
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | @Override
|
---|
| 716 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | @Override
|
---|
| 720 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | @Override
|
---|
| 724 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 725 | showSettings();
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | @Override
|
---|
| 729 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | @Override
|
---|
| 733 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 734 | event.setHandled(true);
|
---|
| 735 | saveLocalData();
|
---|
| 736 | exit();
|
---|
[593] | 737 | }
|
---|
| 738 |
|
---|
| 739 | @Override
|
---|
| 740 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 741 | }
|
---|
[600] | 742 |
|
---|
[592] | 743 | }
|
---|