[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;
|
---|
[605] | 12 | import java.util.HashMap;
|
---|
| 13 | import java.util.HashSet;
|
---|
[591] | 14 | import java.util.ResourceBundle;
|
---|
| 15 | import java.util.TreeMap;
|
---|
[600] | 16 | import java.util.TreeSet;
|
---|
[605] | 17 | import java.util.Vector;
|
---|
[591] | 18 |
|
---|
[623] | 19 | import javax.swing.AbstractAction;
|
---|
| 20 | import javax.swing.Icon;
|
---|
| 21 | import javax.swing.ImageIcon;
|
---|
[600] | 22 | import javax.swing.JButton;
|
---|
[627] | 23 | import javax.swing.JCheckBox;
|
---|
[591] | 24 | import javax.swing.JComboBox;
|
---|
[604] | 25 | import javax.swing.JFileChooser;
|
---|
[591] | 26 | import javax.swing.JFrame;
|
---|
[592] | 27 | import javax.swing.JLabel;
|
---|
[593] | 28 | import javax.swing.JMenu;
|
---|
[608] | 29 | import javax.swing.JMenuItem;
|
---|
[593] | 30 | import javax.swing.JOptionPane;
|
---|
[627] | 31 | import javax.swing.JPanel;
|
---|
[630] | 32 | import javax.swing.JRadioButton;
|
---|
[592] | 33 | import javax.swing.JSplitPane;
|
---|
[591] | 34 | import javax.swing.SwingUtilities;
|
---|
[631] | 35 | import javax.swing.ToolTipManager;
|
---|
[604] | 36 | import javax.swing.filechooser.FileFilter;
|
---|
[591] | 37 |
|
---|
[623] | 38 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
| 39 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[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;
|
---|
[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()) {
|
---|
| 167 | try {
|
---|
| 168 | DepotManager.getInstance().updateInformation(false,
|
---|
| 169 | new DepotCacheUpdateProgressListener() {
|
---|
[591] | 170 |
|
---|
[621] | 171 | @Override
|
---|
| 172 | public void cacheUpdateProgress(String stepName,
|
---|
| 173 | int current, int total) {
|
---|
| 174 | evt.setProgressEnd(total);
|
---|
| 175 | evt.setProgressValue(current);
|
---|
| 176 | evt.setProgressMessage(stepName);
|
---|
| 177 | }
|
---|
| 178 | });
|
---|
| 179 | } catch (Exception e) {
|
---|
| 180 | e.printStackTrace();
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | ModManager.getInstance().init();
|
---|
[631] | 184 | tblMods.reloadData();
|
---|
[621] | 185 | initModTypeBox();
|
---|
[600] | 186 |
|
---|
[621] | 187 | tblMods.setVisible(true);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | @SuppressWarnings("unused")
|
---|
| 191 | private void checkUpdates(Object evtSource) {
|
---|
| 192 | if ((evtSource != this)
|
---|
| 193 | || Settings.getInstance().get("notifyupdates", true)) {
|
---|
| 194 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 195 | if (evtSource != this) {
|
---|
| 196 | JOptionPane.showMessageDialog(this,
|
---|
| 197 | bundle.getString("offlineMode.text"),
|
---|
| 198 | bundle.getString("offlineMode.title"),
|
---|
| 199 | JOptionPane.WARNING_MESSAGE);
|
---|
| 200 | }
|
---|
| 201 | } else {
|
---|
| 202 | TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
|
---|
| 203 | TreeSet<Mod> tools = ModManager.getInstance()
|
---|
| 204 | .getUpdatableTools();
|
---|
| 205 | int size = 0;
|
---|
[632] | 206 | JPanel panPackages = new JPanel(new GridLayout(0, 1));
|
---|
| 207 | execUpdates = new TreeSet<Mod>();
|
---|
| 208 | execUpdates.addAll(mods);
|
---|
| 209 | execUpdates.addAll(tools);
|
---|
| 210 | for (final Mod m : mods) {
|
---|
[621] | 211 | size += m.getZipSize();
|
---|
[632] | 212 | JCheckBox check = new JCheckBox("Mod: " + m.getName());
|
---|
| 213 | check.setSelected(true);
|
---|
| 214 | check.addItemListener(new ItemListener() {
|
---|
| 215 | @Override
|
---|
| 216 | public void itemStateChanged(ItemEvent e) {
|
---|
| 217 | if (e.getStateChange() == ItemEvent.SELECTED)
|
---|
| 218 | execUpdates.add(m);
|
---|
| 219 | else
|
---|
| 220 | execUpdates.remove(m);
|
---|
| 221 | }
|
---|
| 222 | });
|
---|
| 223 | panPackages.add(check);
|
---|
[621] | 224 | }
|
---|
[632] | 225 | for (final Mod m : tools) {
|
---|
[621] | 226 | size += m.getZipSize();
|
---|
[632] | 227 | JCheckBox check = new JCheckBox("Tool: " + m.getName());
|
---|
| 228 | check.setSelected(true);
|
---|
| 229 | panPackages.add(check);
|
---|
[621] | 230 | }
|
---|
[622] | 231 | if (size > 0) {
|
---|
[627] | 232 | // Build info dialog content
|
---|
[632] | 233 | JPanel packages = new JPanel(new BorderLayout(0, 7));
|
---|
| 234 | JLabel lblIntro = new JLabel("<html>"
|
---|
| 235 | + bundle.getString("updatesAvailable.text")
|
---|
| 236 | + "</html>");
|
---|
| 237 | JLabel lblSize = new JLabel("<html>"
|
---|
| 238 | + String.format(bundle
|
---|
| 239 | .getString("updatesAvailableSize.text"),
|
---|
| 240 | SizeFormatter.format(size, 3)) + "</html>");
|
---|
| 241 | packages.add(lblIntro, BorderLayout.NORTH);
|
---|
| 242 | packages.add(panPackages, BorderLayout.CENTER);
|
---|
| 243 | packages.add(lblSize, BorderLayout.SOUTH);
|
---|
[627] | 244 |
|
---|
[632] | 245 | JPanel pan = new JPanel(new BorderLayout(0, 25));
|
---|
| 246 | pan.add(packages, BorderLayout.CENTER);
|
---|
[627] | 247 | JCheckBox checkFutureUpdates = new JCheckBox(
|
---|
| 248 | bundle.getString("checkOnStartup.text"));
|
---|
| 249 | checkFutureUpdates.setSelected(Settings.getInstance().get(
|
---|
| 250 | "notifyupdates", true));
|
---|
| 251 | checkFutureUpdates.addItemListener(new ItemListener() {
|
---|
| 252 | @Override
|
---|
| 253 | public void itemStateChanged(ItemEvent evt) {
|
---|
| 254 | Settings.getInstance().put("notifyupdates",
|
---|
| 255 | evt.getStateChange() == ItemEvent.SELECTED);
|
---|
| 256 | }
|
---|
| 257 | });
|
---|
| 258 | pan.add(checkFutureUpdates, BorderLayout.SOUTH);
|
---|
| 259 |
|
---|
| 260 | // Show dialog
|
---|
| 261 | int res = JOptionPane.showConfirmDialog(this, pan,
|
---|
[622] | 262 | bundle.getString("updatesAvailable.title"),
|
---|
| 263 | JOptionPane.YES_NO_OPTION,
|
---|
| 264 | JOptionPane.QUESTION_MESSAGE);
|
---|
[632] | 265 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 266 | execUpdates = null;
|
---|
[622] | 267 | }
|
---|
[621] | 268 | }
|
---|
| 269 | }
|
---|
[591] | 270 | }
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[624] | 273 | @SuppressWarnings("unused")
|
---|
| 274 | private void doUpdate() {
|
---|
[632] | 275 | if (execUpdates != null && execUpdates.size() > 0) {
|
---|
[624] | 276 | Downloader dl = new Downloader(execUpdates);
|
---|
| 277 | try {
|
---|
| 278 | dl.setVisible(true);
|
---|
| 279 | if (dl.isFinished()) {
|
---|
| 280 | TreeSet<Integer> installed = Installer.getInstalledTools();
|
---|
| 281 | TreeSet<Mod> tools = new TreeSet<Mod>();
|
---|
| 282 | for (Mod m : execUpdates)
|
---|
| 283 | if (m.isTool()
|
---|
| 284 | && installed.contains(m.getPackageNumber()))
|
---|
| 285 | tools.add(m);
|
---|
| 286 | if (tools.size() > 0) {
|
---|
| 287 | Installer.installTools(tools);
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 | } finally {
|
---|
| 291 | dl.dispose();
|
---|
| 292 | }
|
---|
[591] | 293 | }
|
---|
[621] | 294 | execUpdates = null;
|
---|
[591] | 295 | }
|
---|
| 296 |
|
---|
| 297 | @SuppressWarnings("unused")
|
---|
| 298 | private void focus() {
|
---|
| 299 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 300 |
|
---|
| 301 | @Override
|
---|
| 302 | public void run() {
|
---|
| 303 | toFront();
|
---|
| 304 | repaint();
|
---|
| 305 | }
|
---|
| 306 | });
|
---|
| 307 |
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | private void showSettings() {
|
---|
[593] | 311 | new SettingsDialog().setVisible(true);
|
---|
[591] | 312 | }
|
---|
| 313 |
|
---|
[593] | 314 | private void showAbout() {
|
---|
| 315 | new AboutDialog().setVisible(true);
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[604] | 318 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 319 | JFileChooser fc = new JFileChooser();
|
---|
| 320 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 321 | if (save)
|
---|
| 322 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 323 | else
|
---|
| 324 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 325 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 326 | fc.setFileFilter(new FileFilter() {
|
---|
| 327 | @Override
|
---|
| 328 | public String getDescription() {
|
---|
| 329 | return "XML files";
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | @Override
|
---|
| 333 | public boolean accept(File arg0) {
|
---|
| 334 | return (arg0.isDirectory())
|
---|
| 335 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 336 | }
|
---|
| 337 | });
|
---|
| 338 | fc.setMultiSelectionEnabled(false);
|
---|
| 339 | return fc;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[593] | 342 | @SuppressWarnings("unused")
|
---|
| 343 | private void loadConfig() {
|
---|
[604] | 344 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 345 | int res = fc.showOpenDialog(this);
|
---|
| 346 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 347 | if (fc.getSelectedFile().exists())
|
---|
[631] | 348 | tblMods.reloadSelection(fc.getSelectedFile());
|
---|
[604] | 349 | }
|
---|
[593] | 350 | }
|
---|
| 351 |
|
---|
| 352 | @SuppressWarnings("unused")
|
---|
| 353 | private void saveConfig() {
|
---|
[604] | 354 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 355 | int res = fc.showSaveDialog(this);
|
---|
| 356 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 357 | File f = fc.getSelectedFile();
|
---|
| 358 | if (!f.getName().endsWith(".xml"))
|
---|
| 359 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
| 360 | ModManager.getInstance().saveModSelection(f,
|
---|
[631] | 361 | tblMods.getSelectedMods());
|
---|
[604] | 362 | }
|
---|
[593] | 363 | }
|
---|
| 364 |
|
---|
[600] | 365 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 366 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 367 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 368 | @Override
|
---|
| 369 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 370 | evt.setProgressEnd(total);
|
---|
| 371 | evt.setProgressValue(done);
|
---|
| 372 | evt.setProgressMessage(step);
|
---|
| 373 | }
|
---|
| 374 | });
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[593] | 377 | @SuppressWarnings("unused")
|
---|
[600] | 378 | private void tools() {
|
---|
[625] | 379 | new ToolManager().setVisible(true);
|
---|
[593] | 380 | }
|
---|
[596] | 381 |
|
---|
[593] | 382 | @SuppressWarnings("unused")
|
---|
[623] | 383 | private void refreshToolsMenu() {
|
---|
| 384 | for (JMenuItem i : toolsMenuItems) {
|
---|
| 385 | toolsMenu.remove(i);
|
---|
| 386 | }
|
---|
| 387 | toolsMenuItems.clear();
|
---|
| 388 | for (Mod m : ModManager.getInstance().getInstalledTools()) {
|
---|
| 389 | if (m.getExeFile() != null && m.getExeFile().exists()) {
|
---|
| 390 | JMenuItem item = new JMenuItem();
|
---|
| 391 | final Vector<String> params = new Vector<String>();
|
---|
| 392 | params.add(m.getExeFile().getPath());
|
---|
| 393 | final File wd = m.getWorkingDir();
|
---|
| 394 | Icon ico = null;
|
---|
| 395 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 396 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 397 | } else {
|
---|
[624] | 398 | URL icon = AEInstaller2.class
|
---|
| 399 | .getResource("images/transparent.png");
|
---|
[623] | 400 | ico = new ImageIcon(icon);
|
---|
| 401 | }
|
---|
| 402 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 403 | private static final long serialVersionUID = 1L;
|
---|
| 404 |
|
---|
| 405 | @Override
|
---|
| 406 | public void actionPerformed(ActionEvent e) {
|
---|
| 407 | AppExecution.execute(params, wd);
|
---|
| 408 | }
|
---|
| 409 | });
|
---|
| 410 | toolsMenuItems.add(item);
|
---|
| 411 | toolsMenu.add(item);
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | @SuppressWarnings("unused")
|
---|
[593] | 417 | private void revertSelection() {
|
---|
[631] | 418 | tblMods.revertSelection();
|
---|
[593] | 419 | }
|
---|
| 420 |
|
---|
[602] | 421 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
|
---|
| 422 | private void checkMandatoryFiles(final BackgroundEvent evt) {
|
---|
[621] | 423 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
| 424 | TreeSet<Mod> mand = new TreeSet<Mod>();
|
---|
| 425 | for (Mod m : ModManager.getInstance().getMandatoryTools()) {
|
---|
| 426 | if (m.isNewerAvailable()) {
|
---|
| 427 | mand.add(m);
|
---|
| 428 | }
|
---|
[604] | 429 | }
|
---|
[621] | 430 | for (Mod m : ModManager.getInstance().getMandatoryMods()) {
|
---|
| 431 | if (m.isNewerAvailable()) {
|
---|
| 432 | mand.add(m);
|
---|
| 433 | }
|
---|
[604] | 434 | }
|
---|
[621] | 435 | if (mand.size() > 0) {
|
---|
| 436 | ModDownloader m = new ModDownloader(mand,
|
---|
| 437 | new ModDownloaderListener() {
|
---|
| 438 | @Override
|
---|
| 439 | public void updateStatus(ModDownloader source,
|
---|
| 440 | State state, int filesDown, int filesTotal,
|
---|
| 441 | int bytesDown, int bytesTotal,
|
---|
| 442 | int duration, int remaining, int speed) {
|
---|
| 443 | evt.setProgressEnd(filesTotal);
|
---|
| 444 | evt.setProgressValue(filesDown);
|
---|
| 445 | }
|
---|
| 446 | });
|
---|
| 447 | while (!m.isFinished()) {
|
---|
| 448 | try {
|
---|
| 449 | Thread.sleep(10);
|
---|
| 450 | } catch (InterruptedException e) {
|
---|
| 451 | e.printStackTrace();
|
---|
| 452 | }
|
---|
[604] | 453 | }
|
---|
| 454 | }
|
---|
[621] | 455 | evt.setProgressMessage(bundle
|
---|
| 456 | .getString("mandatoryToolsInstall.title"));
|
---|
| 457 | Installer
|
---|
| 458 | .installTools(ModManager.getInstance().getMandatoryTools());
|
---|
[604] | 459 | }
|
---|
[602] | 460 | }
|
---|
| 461 |
|
---|
[600] | 462 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
[621] | 463 | private void install(final BackgroundEvent evt) {
|
---|
[600] | 464 | TreeSet<Mod> mods = new TreeSet<Mod>();
|
---|
[602] | 465 | mods.addAll(ModManager.getInstance().getMandatoryMods());
|
---|
[631] | 466 | mods.addAll(tblMods.getSelectedMods());
|
---|
[600] | 467 |
|
---|
[605] | 468 | boolean instReady = false;
|
---|
[621] | 469 | installDone = EInstallResult.DONE;
|
---|
[605] | 470 |
|
---|
| 471 | while (!instReady) {
|
---|
| 472 | TreeSet<Mod> toDownload = new TreeSet<Mod>();
|
---|
| 473 | for (Mod m : mods) {
|
---|
| 474 | if (!m.isLocalAvailable())
|
---|
| 475 | toDownload.add(m);
|
---|
| 476 | }
|
---|
[621] | 477 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 478 | installDone = EInstallResult.OFFLINE;
|
---|
| 479 | break;
|
---|
| 480 | }
|
---|
[605] | 481 | if (toDownload.size() > 0) {
|
---|
| 482 | Downloader dl = new Downloader(toDownload);
|
---|
[617] | 483 | try {
|
---|
| 484 | dl.setVisible(true);
|
---|
| 485 | if (!dl.isFinished())
|
---|
| 486 | break;
|
---|
| 487 | } finally {
|
---|
| 488 | dl.dispose();
|
---|
| 489 | }
|
---|
[605] | 490 | }
|
---|
| 491 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
|
---|
| 492 | .checkDependencies(mods);
|
---|
| 493 | if (dependencies.size() > 0) {
|
---|
| 494 | System.out.println("Unmet dependencies: "
|
---|
| 495 | + dependencies.toString());
|
---|
| 496 | for (Mod m : dependencies.keySet()) {
|
---|
| 497 | for (Mod mDep : dependencies.get(m))
|
---|
| 498 | mods.add(mDep);
|
---|
| 499 | }
|
---|
| 500 | } else {
|
---|
| 501 | HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
|
---|
[608] | 502 | .checkIncompabitilites(mods);
|
---|
[605] | 503 | if (conflicts.size() > 0) {
|
---|
[621] | 504 | installDone = EInstallResult.INCOMPATIBLE;
|
---|
[608] | 505 | System.err.println("Incompatible mods: "
|
---|
[605] | 506 | + conflicts.toString());
|
---|
| 507 | break;
|
---|
| 508 | } else {
|
---|
| 509 | instReady = true;
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
[600] | 512 | }
|
---|
[618] | 513 |
|
---|
[605] | 514 | if (instReady) {
|
---|
[623] | 515 | TreeSet<Mod> actuallyMods = new TreeSet<Mod>();
|
---|
| 516 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 517 |
|
---|
| 518 | for (Mod m : mods) {
|
---|
| 519 | if (m.isTool())
|
---|
| 520 | actuallyTools.add(m);
|
---|
| 521 | else
|
---|
| 522 | actuallyMods.add(m);
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | if (actuallyTools.size() > 0) {
|
---|
| 526 | Installer.installTools(actuallyTools);
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | Installer.install(actuallyMods, new InstallProgressListener() {
|
---|
[605] | 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 | });
|
---|
[621] | 538 | installDone = EInstallResult.DONE;
|
---|
[605] | 539 | }
|
---|
[600] | 540 | }
|
---|
[618] | 541 |
|
---|
[617] | 542 | @SuppressWarnings("unused")
|
---|
| 543 | private void installDone() {
|
---|
[621] | 544 | switch (installDone) {
|
---|
| 545 | case DONE:
|
---|
| 546 | JOptionPane.showMessageDialog(this,
|
---|
| 547 | bundle.getString("installDone.text"),
|
---|
| 548 | bundle.getString("installDone.title"),
|
---|
| 549 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 550 | break;
|
---|
| 551 | case OFFLINE:
|
---|
| 552 | JOptionPane.showMessageDialog(this,
|
---|
| 553 | bundle.getString("offlineMode.text"),
|
---|
| 554 | bundle.getString("offlineMode.title"),
|
---|
| 555 | JOptionPane.WARNING_MESSAGE);
|
---|
| 556 | break;
|
---|
| 557 | case INCOMPATIBLE:
|
---|
| 558 | break;
|
---|
| 559 | }
|
---|
[617] | 560 | }
|
---|
[600] | 561 |
|
---|
[631] | 562 | @Override
|
---|
| 563 | public void modSelectionChanged(ModTable source, Mod m) {
|
---|
[592] | 564 | lblSubmitterVal.setText("");
|
---|
| 565 | lblCreatorVal.setText("");
|
---|
| 566 | lblDescriptionVal.setText("");
|
---|
[606] | 567 | lblTypesVal.setText("");
|
---|
| 568 | lblPlatformVal.setText("");
|
---|
[621] | 569 | lblPackageNumberVal.setText("");
|
---|
[600] | 570 | if (m != null) {
|
---|
| 571 | lblSubmitterVal.setText(m.getName());
|
---|
| 572 | lblCreatorVal.setText(m.getCreator());
|
---|
| 573 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 574 |
|
---|
| 575 | String types = "";
|
---|
| 576 | for (Type t : m.getTypes()) {
|
---|
| 577 | if (types.length() > 0)
|
---|
| 578 | types += ", ";
|
---|
| 579 | types += t.getName();
|
---|
| 580 | }
|
---|
| 581 | lblTypesVal.setText(types);
|
---|
| 582 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 583 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[591] | 584 | }
|
---|
| 585 | }
|
---|
| 586 |
|
---|
[630] | 587 | private void updateTableFilter() {
|
---|
| 588 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 589 | Type t = null;
|
---|
| 590 | if (o instanceof Type)
|
---|
| 591 | t = (Type) o;
|
---|
| 592 | int downloadState = 0;
|
---|
| 593 | if (radOnline.isSelected())
|
---|
| 594 | downloadState = 1;
|
---|
| 595 | if (radLocal.isSelected())
|
---|
| 596 | downloadState = 2;
|
---|
[631] | 597 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 598 | }
|
---|
| 599 |
|
---|
[591] | 600 | @SuppressWarnings("unused")
|
---|
[592] | 601 | private void modTypeSelection() {
|
---|
[630] | 602 | updateTableFilter();
|
---|
[591] | 603 | }
|
---|
[593] | 604 |
|
---|
[630] | 605 | @SuppressWarnings("unused")
|
---|
| 606 | private void showTypeSelection() {
|
---|
| 607 | updateTableFilter();
|
---|
| 608 | }
|
---|
| 609 |
|
---|
[593] | 610 | @Override
|
---|
[600] | 611 | public void downloadSizeChanged(int newSize) {
|
---|
| 612 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 613 | }
|
---|
| 614 |
|
---|
[616] | 615 | @SuppressWarnings("unused")
|
---|
| 616 | private void checkInitialize() {
|
---|
[600] | 617 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 618 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 619 | JOptionPane.showMessageDialog(this,
|
---|
| 620 | bundle.getString("noOniSplit.text"),
|
---|
| 621 | bundle.getString("noOniSplit.title"),
|
---|
| 622 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 623 | exit();
|
---|
[621] | 624 | } else {
|
---|
| 625 | int res = JOptionPane
|
---|
| 626 | .showConfirmDialog(this,
|
---|
| 627 | bundle.getString("askInitialize.text"),
|
---|
| 628 | bundle.getString("askInitialize.title"),
|
---|
| 629 | JOptionPane.YES_NO_OPTION,
|
---|
| 630 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 631 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 632 | saveLocalData();
|
---|
| 633 | exit();
|
---|
| 634 | }
|
---|
[600] | 635 | }
|
---|
| 636 | }
|
---|
| 637 | }
|
---|
[606] | 638 |
|
---|
[616] | 639 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 640 | private void initialize(final BackgroundEvent evt) {
|
---|
| 641 | if (!Installer.isEditionInitialized()) {
|
---|
| 642 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 643 | @Override
|
---|
| 644 | public void installProgressUpdate(int done, int total,
|
---|
| 645 | String step) {
|
---|
| 646 | evt.setProgressEnd(total);
|
---|
| 647 | evt.setProgressValue(done);
|
---|
| 648 | evt.setProgressMessage(step);
|
---|
| 649 | }
|
---|
| 650 | });
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
| 653 |
|
---|
[605] | 654 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 655 | Vector<String> params = new Vector<String>();
|
---|
[618] | 656 | File exe = null;
|
---|
[605] | 657 | switch (Settings.getPlatform()) {
|
---|
| 658 | case WIN:
|
---|
[618] | 659 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 660 | if (exe.exists())
|
---|
| 661 | params.add(exe.getPath());
|
---|
[605] | 662 | break;
|
---|
| 663 | case MACOS:
|
---|
[618] | 664 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 665 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 666 | if (exe.exists())
|
---|
| 667 | params.add(exe.getPath());
|
---|
[605] | 668 | break;
|
---|
| 669 | case LINUX:
|
---|
| 670 | String wine = Settings.getWinePath();
|
---|
[618] | 671 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 672 | if (exe.exists()) {
|
---|
| 673 | if (wine != null) {
|
---|
| 674 | params.add(wine);
|
---|
| 675 | params.add(exe.getPath());
|
---|
| 676 | }
|
---|
[605] | 677 | }
|
---|
| 678 | break;
|
---|
| 679 | default:
|
---|
| 680 | }
|
---|
| 681 | if (params.size() > 0) {
|
---|
| 682 | params.add("-debugfiles");
|
---|
| 683 | }
|
---|
| 684 | return params;
|
---|
| 685 | }
|
---|
[600] | 686 |
|
---|
[605] | 687 | @SuppressWarnings("unused")
|
---|
| 688 | private void oniFull() {
|
---|
| 689 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 690 | if (params.size() > 0) {
|
---|
[623] | 691 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 692 | }
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | @SuppressWarnings("unused")
|
---|
| 696 | private void oniWin() {
|
---|
| 697 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 698 | if (params.size() > 0) {
|
---|
| 699 | params.add("-noswitch");
|
---|
[623] | 700 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 701 | }
|
---|
| 702 | }
|
---|
| 703 |
|
---|
[608] | 704 | @SuppressWarnings("unused")
|
---|
| 705 | private void openEditionFolder() {
|
---|
| 706 | try {
|
---|
| 707 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
| 708 | } catch (IOException e) {
|
---|
| 709 | e.printStackTrace();
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
| 712 |
|
---|
[600] | 713 | @Override
|
---|
[593] | 714 | public void handleAbout(ApplicationEvent event) {
|
---|
| 715 | event.setHandled(true);
|
---|
| 716 | showAbout();
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | @Override
|
---|
| 720 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | @Override
|
---|
| 724 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 725 | }
|
---|
| 726 |
|
---|
| 727 | @Override
|
---|
| 728 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 729 | showSettings();
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | @Override
|
---|
| 733 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 734 | }
|
---|
| 735 |
|
---|
| 736 | @Override
|
---|
| 737 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 738 | event.setHandled(true);
|
---|
| 739 | saveLocalData();
|
---|
| 740 | exit();
|
---|
[593] | 741 | }
|
---|
| 742 |
|
---|
| 743 | @Override
|
---|
| 744 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 745 | }
|
---|
[600] | 746 |
|
---|
[592] | 747 | }
|
---|