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