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