[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;
|
---|
[623] | 10 | import java.net.URL;
|
---|
[634] | 11 | import java.util.Date;
|
---|
[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.DepotManager;
|
---|
[600] | 45 | import net.oni2.aeinstaller.backend.mods.Mod;
|
---|
| 46 | import net.oni2.aeinstaller.backend.mods.ModManager;
|
---|
| 47 | import net.oni2.aeinstaller.backend.mods.Type;
|
---|
[604] | 48 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
|
---|
| 49 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
|
---|
| 50 | import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
|
---|
[600] | 51 | import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
|
---|
| 52 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
[621] | 53 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[593] | 54 | import net.oni2.aeinstaller.gui.about.AboutDialog;
|
---|
[605] | 55 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[600] | 56 | import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
|
---|
[631] | 57 | import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
|
---|
| 58 | import net.oni2.aeinstaller.gui.modtable.ModTable;
|
---|
[591] | 59 | import net.oni2.aeinstaller.gui.settings.SettingsDialog;
|
---|
[625] | 60 | import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
|
---|
[591] | 61 |
|
---|
| 62 | import org.javabuilders.BuildResult;
|
---|
| 63 | import org.javabuilders.annotations.DoInBackground;
|
---|
| 64 | import org.javabuilders.event.BackgroundEvent;
|
---|
| 65 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 66 | import org.simplericity.macify.eawt.ApplicationEvent;
|
---|
| 67 | import org.simplericity.macify.eawt.ApplicationListener;
|
---|
[591] | 68 |
|
---|
| 69 | /**
|
---|
| 70 | * @author Christian Illy
|
---|
| 71 | */
|
---|
[600] | 72 | public class MainWin extends JFrame implements ApplicationListener,
|
---|
[631] | 73 | DownloadSizeListener, ModSelectionListener {
|
---|
[591] | 74 | private static final long serialVersionUID = -4027395051382659650L;
|
---|
| 75 |
|
---|
[629] | 76 | private ResourceBundle bundle = ResourceBundle
|
---|
| 77 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 78 | + getClass().getSimpleName());
|
---|
[591] | 79 | @SuppressWarnings("unused")
|
---|
| 80 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 81 |
|
---|
[593] | 82 | private JMenu mainMenu;
|
---|
[623] | 83 | private JMenu toolsMenu;
|
---|
[641] | 84 | private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
|
---|
[593] | 85 |
|
---|
[592] | 86 | private JSplitPane contents;
|
---|
| 87 |
|
---|
[591] | 88 | private JComboBox cmbModTypes;
|
---|
[630] | 89 | private JRadioButton radAll;
|
---|
| 90 | private JRadioButton radOnline;
|
---|
| 91 | private JRadioButton radLocal;
|
---|
[631] | 92 | private ModTable tblMods;
|
---|
[600] | 93 | private JLabel lblDownloadSizeVal;
|
---|
[591] | 94 |
|
---|
[639] | 95 | private JLabel lblTitleVal;
|
---|
[592] | 96 | private JLabel lblCreatorVal;
|
---|
[606] | 97 | private JLabel lblTypesVal;
|
---|
| 98 | private JLabel lblPlatformVal;
|
---|
[621] | 99 | private JLabel lblPackageNumberVal;
|
---|
[638] | 100 | private JLabel lblVersionNumberVal;
|
---|
[592] | 101 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 102 |
|
---|
[600] | 103 | private JButton btnInstall;
|
---|
| 104 |
|
---|
[621] | 105 | private TreeSet<Mod> execUpdates = null;
|
---|
| 106 |
|
---|
[641] | 107 | private enum EInstallState {
|
---|
[621] | 108 | DONE,
|
---|
[641] | 109 | READY,
|
---|
| 110 | ABORTED,
|
---|
[621] | 111 | OFFLINE,
|
---|
[641] | 112 | INCOMPATIBLE,
|
---|
| 113 | CHECKING
|
---|
[621] | 114 | };
|
---|
| 115 |
|
---|
[641] | 116 | private EInstallState installState = EInstallState.DONE;
|
---|
| 117 | private TreeSet<Mod> installMods = null;
|
---|
[621] | 118 |
|
---|
[591] | 119 | /**
|
---|
| 120 | * Constructor of main window.
|
---|
| 121 | */
|
---|
| 122 | public MainWin() {
|
---|
[593] | 123 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 124 | + " - v"
|
---|
| 125 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 126 |
|
---|
[640] | 127 | setSize(getWidth() + 150, getHeight());
|
---|
[637] | 128 | contents.setDividerLocation(500);
|
---|
[631] | 129 | contents.setResizeWeight(0.4);
|
---|
[593] | 130 |
|
---|
| 131 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 132 | mainMenu.setVisible(false);
|
---|
| 133 | }
|
---|
[600] | 134 |
|
---|
[631] | 135 | ToolTipManager.sharedInstance().setInitialDelay(250);
|
---|
| 136 |
|
---|
[600] | 137 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 138 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[630] | 139 | radAll.setSelected(true);
|
---|
[631] | 140 |
|
---|
| 141 | tblMods.addModSelectionListener(this);
|
---|
| 142 | tblMods.addDownloadSizeListener(this);
|
---|
[591] | 143 | }
|
---|
| 144 |
|
---|
| 145 | private void initModTypeBox() {
|
---|
[592] | 146 | cmbModTypes.removeAllItems();
|
---|
| 147 |
|
---|
[600] | 148 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
| 149 | for (Type t : ModManager.getInstance().getTypesWithContent()) {
|
---|
| 150 | types.put(t.getName(), t);
|
---|
[591] | 151 | }
|
---|
[630] | 152 | cmbModTypes.addItem("-All-");
|
---|
[600] | 153 | for (Type t : types.values()) {
|
---|
[591] | 154 | cmbModTypes.addItem(t);
|
---|
| 155 | }
|
---|
| 156 | cmbModTypes.setSelectedIndex(0);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | private void exit() {
|
---|
| 160 | dispose();
|
---|
[608] | 161 | System.exit(0);
|
---|
[591] | 162 | }
|
---|
| 163 |
|
---|
| 164 | private void saveLocalData() {
|
---|
| 165 | Settings.getInstance().serializeToFile();
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 169 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
[621] | 170 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
[634] | 171 | long start = new Date().getTime();
|
---|
| 172 |
|
---|
[621] | 173 | try {
|
---|
[634] | 174 | DepotManager.getInstance().updateInformation(false);
|
---|
[621] | 175 | } catch (Exception e) {
|
---|
| 176 | e.printStackTrace();
|
---|
| 177 | }
|
---|
[634] | 178 |
|
---|
| 179 | System.out.println("Took: " + (new Date().getTime() - start)
|
---|
| 180 | + " msec");
|
---|
[621] | 181 | }
|
---|
[633] | 182 |
|
---|
[621] | 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()) {
|
---|
[640] | 389 | File exe = m.getExeFile();
|
---|
| 390 | if (exe != null && exe.exists()) {
|
---|
[623] | 391 | JMenuItem item = new JMenuItem();
|
---|
| 392 | final Vector<String> params = new Vector<String>();
|
---|
[640] | 393 | if (exe.getName().toLowerCase().endsWith(".jar")) {
|
---|
| 394 | File jre = null;
|
---|
| 395 | if (Settings.getPlatform() == Platform.WIN)
|
---|
| 396 | jre = new File(System.getProperties().getProperty(
|
---|
| 397 | "java.home"), "bin/javaw.exe");
|
---|
| 398 | else
|
---|
| 399 | jre = new File(System.getProperties().getProperty(
|
---|
| 400 | "java.home"), "bin/java");
|
---|
| 401 | params.add(jre.getPath());
|
---|
| 402 | params.add("-jar");
|
---|
| 403 | }
|
---|
| 404 | params.add(exe.getPath());
|
---|
[623] | 405 | final File wd = m.getWorkingDir();
|
---|
| 406 | Icon ico = null;
|
---|
| 407 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 408 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 409 | } else {
|
---|
[624] | 410 | URL icon = AEInstaller2.class
|
---|
| 411 | .getResource("images/transparent.png");
|
---|
[623] | 412 | ico = new ImageIcon(icon);
|
---|
| 413 | }
|
---|
| 414 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 415 | private static final long serialVersionUID = 1L;
|
---|
| 416 |
|
---|
| 417 | @Override
|
---|
| 418 | public void actionPerformed(ActionEvent e) {
|
---|
| 419 | AppExecution.execute(params, wd);
|
---|
| 420 | }
|
---|
| 421 | });
|
---|
| 422 | toolsMenuItems.add(item);
|
---|
| 423 | toolsMenu.add(item);
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 |
|
---|
[593] | 428 | private void revertSelection() {
|
---|
[631] | 429 | tblMods.revertSelection();
|
---|
[593] | 430 | }
|
---|
| 431 |
|
---|
[602] | 432 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
|
---|
| 433 | private void checkMandatoryFiles(final BackgroundEvent evt) {
|
---|
[621] | 434 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
| 435 | TreeSet<Mod> mand = new TreeSet<Mod>();
|
---|
| 436 | for (Mod m : ModManager.getInstance().getMandatoryTools()) {
|
---|
| 437 | if (m.isNewerAvailable()) {
|
---|
| 438 | mand.add(m);
|
---|
| 439 | }
|
---|
[604] | 440 | }
|
---|
[621] | 441 | for (Mod m : ModManager.getInstance().getMandatoryMods()) {
|
---|
| 442 | if (m.isNewerAvailable()) {
|
---|
| 443 | mand.add(m);
|
---|
| 444 | }
|
---|
[604] | 445 | }
|
---|
[621] | 446 | if (mand.size() > 0) {
|
---|
| 447 | ModDownloader m = new ModDownloader(mand,
|
---|
| 448 | new ModDownloaderListener() {
|
---|
| 449 | @Override
|
---|
| 450 | public void updateStatus(ModDownloader source,
|
---|
| 451 | State state, int filesDown, int filesTotal,
|
---|
| 452 | int bytesDown, int bytesTotal,
|
---|
| 453 | int duration, int remaining, int speed) {
|
---|
| 454 | evt.setProgressEnd(filesTotal);
|
---|
| 455 | evt.setProgressValue(filesDown);
|
---|
| 456 | }
|
---|
| 457 | });
|
---|
| 458 | while (!m.isFinished()) {
|
---|
| 459 | try {
|
---|
| 460 | Thread.sleep(10);
|
---|
| 461 | } catch (InterruptedException e) {
|
---|
| 462 | e.printStackTrace();
|
---|
| 463 | }
|
---|
[604] | 464 | }
|
---|
| 465 | }
|
---|
[621] | 466 | evt.setProgressMessage(bundle
|
---|
| 467 | .getString("mandatoryToolsInstall.title"));
|
---|
| 468 | Installer
|
---|
| 469 | .installTools(ModManager.getInstance().getMandatoryTools());
|
---|
[604] | 470 | }
|
---|
[602] | 471 | }
|
---|
| 472 |
|
---|
[641] | 473 | @SuppressWarnings("unused")
|
---|
| 474 | private void install() {
|
---|
[600] | 475 | TreeSet<Mod> mods = new TreeSet<Mod>();
|
---|
[602] | 476 | mods.addAll(ModManager.getInstance().getMandatoryMods());
|
---|
[631] | 477 | mods.addAll(tblMods.getSelectedMods());
|
---|
[600] | 478 |
|
---|
[641] | 479 | installState = EInstallState.CHECKING;
|
---|
[605] | 480 |
|
---|
[641] | 481 | while (installState == EInstallState.CHECKING) {
|
---|
[605] | 482 | TreeSet<Mod> toDownload = new TreeSet<Mod>();
|
---|
| 483 | for (Mod m : mods) {
|
---|
| 484 | if (!m.isLocalAvailable())
|
---|
| 485 | toDownload.add(m);
|
---|
| 486 | }
|
---|
[621] | 487 | if (Settings.getInstance().isOfflineMode()) {
|
---|
[641] | 488 | installState = EInstallState.OFFLINE;
|
---|
[621] | 489 | break;
|
---|
| 490 | }
|
---|
[605] | 491 | if (toDownload.size() > 0) {
|
---|
| 492 | Downloader dl = new Downloader(toDownload);
|
---|
[617] | 493 | try {
|
---|
| 494 | dl.setVisible(true);
|
---|
[641] | 495 | if (!dl.isFinished()) {
|
---|
| 496 | installState = EInstallState.ABORTED;
|
---|
[617] | 497 | break;
|
---|
[641] | 498 | }
|
---|
[617] | 499 | } finally {
|
---|
| 500 | dl.dispose();
|
---|
| 501 | }
|
---|
[605] | 502 | }
|
---|
| 503 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
|
---|
| 504 | .checkDependencies(mods);
|
---|
| 505 | if (dependencies.size() > 0) {
|
---|
[641] | 506 | int size = 0;
|
---|
| 507 | String depsLocalString = "";
|
---|
| 508 | String depsDownloadString = "";
|
---|
[605] | 509 | for (Mod m : dependencies.keySet()) {
|
---|
[641] | 510 | for (Mod mDep : dependencies.get(m)) {
|
---|
| 511 | if (!mods.contains(mDep)) {
|
---|
| 512 | mods.add(mDep);
|
---|
| 513 | if (!mDep.isLocalAvailable()) {
|
---|
| 514 | size += mDep.getZipSize();
|
---|
| 515 | if (depsDownloadString.length() > 0)
|
---|
| 516 | depsDownloadString += "\n";
|
---|
| 517 | depsDownloadString += " - " + mDep.getName();
|
---|
| 518 | } else {
|
---|
| 519 | if (depsLocalString.length() > 0)
|
---|
| 520 | depsLocalString += "\n";
|
---|
| 521 | depsLocalString += " - " + mDep.getName();
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 | }
|
---|
[605] | 525 | }
|
---|
[641] | 526 | if (depsLocalString.length() == 0)
|
---|
[643] | 527 | depsLocalString = bundle
|
---|
| 528 | .getString("installDependencies.none");
|
---|
[641] | 529 | if (depsDownloadString.length() == 0)
|
---|
[643] | 530 | depsDownloadString = bundle
|
---|
| 531 | .getString("installDependencies.none");
|
---|
[641] | 532 |
|
---|
| 533 | int res = JOptionPane.showConfirmDialog(this, String.format(
|
---|
| 534 | bundle.getString("installDependencies.text"),
|
---|
| 535 | depsLocalString, depsDownloadString,
|
---|
| 536 | SizeFormatter.format(size, 3)), bundle
|
---|
| 537 | .getString("installDependencies.title"),
|
---|
| 538 | JOptionPane.YES_NO_OPTION,
|
---|
| 539 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 540 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 541 | installState = EInstallState.ABORTED;
|
---|
| 542 | break;
|
---|
| 543 | }
|
---|
[605] | 544 | } else {
|
---|
[643] | 545 | HashMap<Mod, HashSet<Mod>> incompatibilities = ModManager.getInstance()
|
---|
[608] | 546 | .checkIncompabitilites(mods);
|
---|
[643] | 547 | if (incompatibilities.size() > 0) {
|
---|
[641] | 548 | installState = EInstallState.INCOMPATIBLE;
|
---|
[643] | 549 |
|
---|
| 550 | String incompatString = "";
|
---|
| 551 | for (Mod m : incompatibilities.keySet()) {
|
---|
| 552 | if (incompatString.length() > 0)
|
---|
| 553 | incompatString += "\n";
|
---|
| 554 | incompatString += m.getName() + ": ";
|
---|
| 555 | String confMods = "";
|
---|
| 556 | for (Mod mConf : incompatibilities.get(m)) {
|
---|
| 557 | if (confMods.length() > 0)
|
---|
| 558 | confMods += ", ";
|
---|
| 559 | confMods += mConf.getName();
|
---|
| 560 | }
|
---|
| 561 | incompatString += confMods;
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 565 | bundle.getString("installIncompatibilities.text"),
|
---|
| 566 | incompatString), bundle
|
---|
| 567 | .getString("installIncompatibilities.title"),
|
---|
| 568 | JOptionPane.ERROR_MESSAGE);
|
---|
[605] | 569 | break;
|
---|
| 570 | } else {
|
---|
[641] | 571 | installState = EInstallState.READY;
|
---|
[605] | 572 | }
|
---|
| 573 | }
|
---|
[600] | 574 | }
|
---|
[618] | 575 |
|
---|
[641] | 576 | if (installState == EInstallState.READY) {
|
---|
| 577 | installMods = new TreeSet<Mod>();
|
---|
[623] | 578 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 579 |
|
---|
| 580 | for (Mod m : mods) {
|
---|
| 581 | if (m.isTool())
|
---|
| 582 | actuallyTools.add(m);
|
---|
| 583 | else
|
---|
[641] | 584 | installMods.add(m);
|
---|
[623] | 585 | }
|
---|
| 586 |
|
---|
| 587 | if (actuallyTools.size() > 0) {
|
---|
| 588 | Installer.installTools(actuallyTools);
|
---|
| 589 | }
|
---|
[641] | 590 | }
|
---|
[623] | 591 |
|
---|
[641] | 592 | }
|
---|
| 593 |
|
---|
| 594 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
| 595 | private void installExec(final BackgroundEvent evt) {
|
---|
| 596 | if (installState == EInstallState.READY) {
|
---|
| 597 | Installer.install(installMods, new InstallProgressListener() {
|
---|
[605] | 598 | @Override
|
---|
| 599 | public void installProgressUpdate(int done, int total,
|
---|
| 600 | String step) {
|
---|
| 601 | evt.setProgressEnd(total);
|
---|
| 602 | evt.setProgressValue(done);
|
---|
| 603 | evt.setProgressMessage(step);
|
---|
| 604 | }
|
---|
| 605 | });
|
---|
[641] | 606 | installState = EInstallState.DONE;
|
---|
[605] | 607 | }
|
---|
[641] | 608 | installMods = null;
|
---|
[600] | 609 | }
|
---|
[618] | 610 |
|
---|
[617] | 611 | @SuppressWarnings("unused")
|
---|
| 612 | private void installDone() {
|
---|
[637] | 613 | ModManager.getInstance().updateInstalledMods();
|
---|
[641] | 614 | switch (installState) {
|
---|
[621] | 615 | case DONE:
|
---|
[641] | 616 | revertSelection();
|
---|
[621] | 617 | JOptionPane.showMessageDialog(this,
|
---|
| 618 | bundle.getString("installDone.text"),
|
---|
| 619 | bundle.getString("installDone.title"),
|
---|
| 620 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 621 | break;
|
---|
| 622 | case OFFLINE:
|
---|
| 623 | JOptionPane.showMessageDialog(this,
|
---|
| 624 | bundle.getString("offlineMode.text"),
|
---|
| 625 | bundle.getString("offlineMode.title"),
|
---|
| 626 | JOptionPane.WARNING_MESSAGE);
|
---|
| 627 | break;
|
---|
[641] | 628 | default:
|
---|
[621] | 629 | break;
|
---|
| 630 | }
|
---|
[617] | 631 | }
|
---|
[600] | 632 |
|
---|
[631] | 633 | @Override
|
---|
| 634 | public void modSelectionChanged(ModTable source, Mod m) {
|
---|
[639] | 635 | lblTitleVal.setText("");
|
---|
[592] | 636 | lblCreatorVal.setText("");
|
---|
| 637 | lblDescriptionVal.setText("");
|
---|
[606] | 638 | lblTypesVal.setText("");
|
---|
| 639 | lblPlatformVal.setText("");
|
---|
[621] | 640 | lblPackageNumberVal.setText("");
|
---|
[638] | 641 | lblVersionNumberVal.setText("");
|
---|
[600] | 642 | if (m != null) {
|
---|
[639] | 643 | lblTitleVal.setText(m.getName());
|
---|
[600] | 644 | lblCreatorVal.setText(m.getCreator());
|
---|
| 645 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 646 |
|
---|
| 647 | String types = "";
|
---|
| 648 | for (Type t : m.getTypes()) {
|
---|
| 649 | if (types.length() > 0)
|
---|
| 650 | types += ", ";
|
---|
| 651 | types += t.getName();
|
---|
| 652 | }
|
---|
| 653 | lblTypesVal.setText(types);
|
---|
| 654 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 655 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[638] | 656 | lblVersionNumberVal.setText(m.getVersion());
|
---|
[591] | 657 | }
|
---|
| 658 | }
|
---|
| 659 |
|
---|
[630] | 660 | private void updateTableFilter() {
|
---|
| 661 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 662 | Type t = null;
|
---|
| 663 | if (o instanceof Type)
|
---|
| 664 | t = (Type) o;
|
---|
| 665 | int downloadState = 0;
|
---|
| 666 | if (radOnline.isSelected())
|
---|
| 667 | downloadState = 1;
|
---|
| 668 | if (radLocal.isSelected())
|
---|
| 669 | downloadState = 2;
|
---|
[631] | 670 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 671 | }
|
---|
| 672 |
|
---|
[591] | 673 | @SuppressWarnings("unused")
|
---|
[592] | 674 | private void modTypeSelection() {
|
---|
[630] | 675 | updateTableFilter();
|
---|
[591] | 676 | }
|
---|
[593] | 677 |
|
---|
[630] | 678 | @SuppressWarnings("unused")
|
---|
| 679 | private void showTypeSelection() {
|
---|
| 680 | updateTableFilter();
|
---|
| 681 | }
|
---|
| 682 |
|
---|
[593] | 683 | @Override
|
---|
[600] | 684 | public void downloadSizeChanged(int newSize) {
|
---|
| 685 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 686 | }
|
---|
| 687 |
|
---|
[616] | 688 | @SuppressWarnings("unused")
|
---|
| 689 | private void checkInitialize() {
|
---|
[600] | 690 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 691 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 692 | JOptionPane.showMessageDialog(this,
|
---|
| 693 | bundle.getString("noOniSplit.text"),
|
---|
| 694 | bundle.getString("noOniSplit.title"),
|
---|
| 695 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 696 | exit();
|
---|
[621] | 697 | } else {
|
---|
| 698 | int res = JOptionPane
|
---|
| 699 | .showConfirmDialog(this,
|
---|
| 700 | bundle.getString("askInitialize.text"),
|
---|
| 701 | bundle.getString("askInitialize.title"),
|
---|
| 702 | JOptionPane.YES_NO_OPTION,
|
---|
| 703 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 704 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 705 | saveLocalData();
|
---|
| 706 | exit();
|
---|
| 707 | }
|
---|
[600] | 708 | }
|
---|
| 709 | }
|
---|
| 710 | }
|
---|
[606] | 711 |
|
---|
[616] | 712 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 713 | private void initialize(final BackgroundEvent evt) {
|
---|
| 714 | if (!Installer.isEditionInitialized()) {
|
---|
| 715 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 716 | @Override
|
---|
| 717 | public void installProgressUpdate(int done, int total,
|
---|
| 718 | String step) {
|
---|
| 719 | evt.setProgressEnd(total);
|
---|
| 720 | evt.setProgressValue(done);
|
---|
| 721 | evt.setProgressMessage(step);
|
---|
| 722 | }
|
---|
| 723 | });
|
---|
| 724 | }
|
---|
| 725 | }
|
---|
| 726 |
|
---|
[605] | 727 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 728 | Vector<String> params = new Vector<String>();
|
---|
[618] | 729 | File exe = null;
|
---|
[605] | 730 | switch (Settings.getPlatform()) {
|
---|
| 731 | case WIN:
|
---|
[618] | 732 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 733 | if (exe.exists())
|
---|
| 734 | params.add(exe.getPath());
|
---|
[605] | 735 | break;
|
---|
| 736 | case MACOS:
|
---|
[618] | 737 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 738 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 739 | if (exe.exists())
|
---|
| 740 | params.add(exe.getPath());
|
---|
[605] | 741 | break;
|
---|
| 742 | case LINUX:
|
---|
| 743 | String wine = Settings.getWinePath();
|
---|
[618] | 744 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 745 | if (exe.exists()) {
|
---|
| 746 | if (wine != null) {
|
---|
| 747 | params.add(wine);
|
---|
| 748 | params.add(exe.getPath());
|
---|
| 749 | }
|
---|
[605] | 750 | }
|
---|
| 751 | break;
|
---|
| 752 | default:
|
---|
| 753 | }
|
---|
| 754 | if (params.size() > 0) {
|
---|
| 755 | params.add("-debugfiles");
|
---|
| 756 | }
|
---|
| 757 | return params;
|
---|
| 758 | }
|
---|
[600] | 759 |
|
---|
[605] | 760 | @SuppressWarnings("unused")
|
---|
| 761 | private void oniFull() {
|
---|
| 762 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 763 | if (params.size() > 0) {
|
---|
[623] | 764 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 765 | }
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | @SuppressWarnings("unused")
|
---|
| 769 | private void oniWin() {
|
---|
| 770 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 771 | if (params.size() > 0) {
|
---|
| 772 | params.add("-noswitch");
|
---|
[623] | 773 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 774 | }
|
---|
| 775 | }
|
---|
| 776 |
|
---|
[608] | 777 | @SuppressWarnings("unused")
|
---|
| 778 | private void openEditionFolder() {
|
---|
| 779 | try {
|
---|
| 780 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
[639] | 781 | } catch (Exception e) {
|
---|
[608] | 782 | e.printStackTrace();
|
---|
| 783 | }
|
---|
| 784 | }
|
---|
| 785 |
|
---|
[600] | 786 | @Override
|
---|
[593] | 787 | public void handleAbout(ApplicationEvent event) {
|
---|
| 788 | event.setHandled(true);
|
---|
| 789 | showAbout();
|
---|
| 790 | }
|
---|
| 791 |
|
---|
| 792 | @Override
|
---|
| 793 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | @Override
|
---|
| 797 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | @Override
|
---|
| 801 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 802 | showSettings();
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | @Override
|
---|
| 806 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 807 | }
|
---|
| 808 |
|
---|
| 809 | @Override
|
---|
| 810 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 811 | event.setHandled(true);
|
---|
| 812 | saveLocalData();
|
---|
| 813 | exit();
|
---|
[593] | 814 | }
|
---|
| 815 |
|
---|
| 816 | @Override
|
---|
| 817 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 818 | }
|
---|
[600] | 819 |
|
---|
[592] | 820 | }
|
---|