[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)
|
---|
| 527 | depsLocalString = bundle.getString("installDependencies.none");
|
---|
| 528 | if (depsDownloadString.length() == 0)
|
---|
| 529 | depsDownloadString = bundle.getString("installDependencies.none");
|
---|
| 530 |
|
---|
| 531 | int res = JOptionPane.showConfirmDialog(this, String.format(
|
---|
| 532 | bundle.getString("installDependencies.text"),
|
---|
| 533 | depsLocalString, depsDownloadString,
|
---|
| 534 | SizeFormatter.format(size, 3)), bundle
|
---|
| 535 | .getString("installDependencies.title"),
|
---|
| 536 | JOptionPane.YES_NO_OPTION,
|
---|
| 537 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 538 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 539 | installState = EInstallState.ABORTED;
|
---|
| 540 | break;
|
---|
| 541 | }
|
---|
[605] | 542 | } else {
|
---|
| 543 | HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
|
---|
[608] | 544 | .checkIncompabitilites(mods);
|
---|
[605] | 545 | if (conflicts.size() > 0) {
|
---|
[641] | 546 | installState = EInstallState.INCOMPATIBLE;
|
---|
[608] | 547 | System.err.println("Incompatible mods: "
|
---|
[605] | 548 | + conflicts.toString());
|
---|
[641] | 549 | // TODO: Message window with incompatibilities
|
---|
[605] | 550 | break;
|
---|
| 551 | } else {
|
---|
[641] | 552 | installState = EInstallState.READY;
|
---|
[605] | 553 | }
|
---|
| 554 | }
|
---|
[600] | 555 | }
|
---|
[618] | 556 |
|
---|
[641] | 557 | if (installState == EInstallState.READY) {
|
---|
| 558 | installMods = new TreeSet<Mod>();
|
---|
[623] | 559 | TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
|
---|
| 560 |
|
---|
| 561 | for (Mod m : mods) {
|
---|
| 562 | if (m.isTool())
|
---|
| 563 | actuallyTools.add(m);
|
---|
| 564 | else
|
---|
[641] | 565 | installMods.add(m);
|
---|
[623] | 566 | }
|
---|
| 567 |
|
---|
| 568 | if (actuallyTools.size() > 0) {
|
---|
| 569 | Installer.installTools(actuallyTools);
|
---|
| 570 | }
|
---|
[641] | 571 | }
|
---|
[623] | 572 |
|
---|
[641] | 573 | }
|
---|
| 574 |
|
---|
| 575 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
| 576 | private void installExec(final BackgroundEvent evt) {
|
---|
| 577 | if (installState == EInstallState.READY) {
|
---|
| 578 | Installer.install(installMods, new InstallProgressListener() {
|
---|
[605] | 579 | @Override
|
---|
| 580 | public void installProgressUpdate(int done, int total,
|
---|
| 581 | String step) {
|
---|
| 582 | evt.setProgressEnd(total);
|
---|
| 583 | evt.setProgressValue(done);
|
---|
| 584 | evt.setProgressMessage(step);
|
---|
| 585 | }
|
---|
| 586 | });
|
---|
[641] | 587 | installState = EInstallState.DONE;
|
---|
[605] | 588 | }
|
---|
[641] | 589 | installMods = null;
|
---|
[600] | 590 | }
|
---|
[618] | 591 |
|
---|
[617] | 592 | @SuppressWarnings("unused")
|
---|
| 593 | private void installDone() {
|
---|
[637] | 594 | ModManager.getInstance().updateInstalledMods();
|
---|
[641] | 595 | switch (installState) {
|
---|
[621] | 596 | case DONE:
|
---|
[641] | 597 | revertSelection();
|
---|
[621] | 598 | JOptionPane.showMessageDialog(this,
|
---|
| 599 | bundle.getString("installDone.text"),
|
---|
| 600 | bundle.getString("installDone.title"),
|
---|
| 601 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 602 | break;
|
---|
| 603 | case OFFLINE:
|
---|
| 604 | JOptionPane.showMessageDialog(this,
|
---|
| 605 | bundle.getString("offlineMode.text"),
|
---|
| 606 | bundle.getString("offlineMode.title"),
|
---|
| 607 | JOptionPane.WARNING_MESSAGE);
|
---|
| 608 | break;
|
---|
[641] | 609 | default:
|
---|
[621] | 610 | break;
|
---|
| 611 | }
|
---|
[617] | 612 | }
|
---|
[600] | 613 |
|
---|
[631] | 614 | @Override
|
---|
| 615 | public void modSelectionChanged(ModTable source, Mod m) {
|
---|
[639] | 616 | lblTitleVal.setText("");
|
---|
[592] | 617 | lblCreatorVal.setText("");
|
---|
| 618 | lblDescriptionVal.setText("");
|
---|
[606] | 619 | lblTypesVal.setText("");
|
---|
| 620 | lblPlatformVal.setText("");
|
---|
[621] | 621 | lblPackageNumberVal.setText("");
|
---|
[638] | 622 | lblVersionNumberVal.setText("");
|
---|
[600] | 623 | if (m != null) {
|
---|
[639] | 624 | lblTitleVal.setText(m.getName());
|
---|
[600] | 625 | lblCreatorVal.setText(m.getCreator());
|
---|
| 626 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 627 |
|
---|
| 628 | String types = "";
|
---|
| 629 | for (Type t : m.getTypes()) {
|
---|
| 630 | if (types.length() > 0)
|
---|
| 631 | types += ", ";
|
---|
| 632 | types += t.getName();
|
---|
| 633 | }
|
---|
| 634 | lblTypesVal.setText(types);
|
---|
| 635 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 636 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[638] | 637 | lblVersionNumberVal.setText(m.getVersion());
|
---|
[591] | 638 | }
|
---|
| 639 | }
|
---|
| 640 |
|
---|
[630] | 641 | private void updateTableFilter() {
|
---|
| 642 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 643 | Type t = null;
|
---|
| 644 | if (o instanceof Type)
|
---|
| 645 | t = (Type) o;
|
---|
| 646 | int downloadState = 0;
|
---|
| 647 | if (radOnline.isSelected())
|
---|
| 648 | downloadState = 1;
|
---|
| 649 | if (radLocal.isSelected())
|
---|
| 650 | downloadState = 2;
|
---|
[631] | 651 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 652 | }
|
---|
| 653 |
|
---|
[591] | 654 | @SuppressWarnings("unused")
|
---|
[592] | 655 | private void modTypeSelection() {
|
---|
[630] | 656 | updateTableFilter();
|
---|
[591] | 657 | }
|
---|
[593] | 658 |
|
---|
[630] | 659 | @SuppressWarnings("unused")
|
---|
| 660 | private void showTypeSelection() {
|
---|
| 661 | updateTableFilter();
|
---|
| 662 | }
|
---|
| 663 |
|
---|
[593] | 664 | @Override
|
---|
[600] | 665 | public void downloadSizeChanged(int newSize) {
|
---|
| 666 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 667 | }
|
---|
| 668 |
|
---|
[616] | 669 | @SuppressWarnings("unused")
|
---|
| 670 | private void checkInitialize() {
|
---|
[600] | 671 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 672 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 673 | JOptionPane.showMessageDialog(this,
|
---|
| 674 | bundle.getString("noOniSplit.text"),
|
---|
| 675 | bundle.getString("noOniSplit.title"),
|
---|
| 676 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 677 | exit();
|
---|
[621] | 678 | } else {
|
---|
| 679 | int res = JOptionPane
|
---|
| 680 | .showConfirmDialog(this,
|
---|
| 681 | bundle.getString("askInitialize.text"),
|
---|
| 682 | bundle.getString("askInitialize.title"),
|
---|
| 683 | JOptionPane.YES_NO_OPTION,
|
---|
| 684 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 685 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 686 | saveLocalData();
|
---|
| 687 | exit();
|
---|
| 688 | }
|
---|
[600] | 689 | }
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
[606] | 692 |
|
---|
[616] | 693 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 694 | private void initialize(final BackgroundEvent evt) {
|
---|
| 695 | if (!Installer.isEditionInitialized()) {
|
---|
| 696 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 697 | @Override
|
---|
| 698 | public void installProgressUpdate(int done, int total,
|
---|
| 699 | String step) {
|
---|
| 700 | evt.setProgressEnd(total);
|
---|
| 701 | evt.setProgressValue(done);
|
---|
| 702 | evt.setProgressMessage(step);
|
---|
| 703 | }
|
---|
| 704 | });
|
---|
| 705 | }
|
---|
| 706 | }
|
---|
| 707 |
|
---|
[605] | 708 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 709 | Vector<String> params = new Vector<String>();
|
---|
[618] | 710 | File exe = null;
|
---|
[605] | 711 | switch (Settings.getPlatform()) {
|
---|
| 712 | case WIN:
|
---|
[618] | 713 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 714 | if (exe.exists())
|
---|
| 715 | params.add(exe.getPath());
|
---|
[605] | 716 | break;
|
---|
| 717 | case MACOS:
|
---|
[618] | 718 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 719 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 720 | if (exe.exists())
|
---|
| 721 | params.add(exe.getPath());
|
---|
[605] | 722 | break;
|
---|
| 723 | case LINUX:
|
---|
| 724 | String wine = Settings.getWinePath();
|
---|
[618] | 725 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 726 | if (exe.exists()) {
|
---|
| 727 | if (wine != null) {
|
---|
| 728 | params.add(wine);
|
---|
| 729 | params.add(exe.getPath());
|
---|
| 730 | }
|
---|
[605] | 731 | }
|
---|
| 732 | break;
|
---|
| 733 | default:
|
---|
| 734 | }
|
---|
| 735 | if (params.size() > 0) {
|
---|
| 736 | params.add("-debugfiles");
|
---|
| 737 | }
|
---|
| 738 | return params;
|
---|
| 739 | }
|
---|
[600] | 740 |
|
---|
[605] | 741 | @SuppressWarnings("unused")
|
---|
| 742 | private void oniFull() {
|
---|
| 743 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 744 | if (params.size() > 0) {
|
---|
[623] | 745 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 746 | }
|
---|
| 747 | }
|
---|
| 748 |
|
---|
| 749 | @SuppressWarnings("unused")
|
---|
| 750 | private void oniWin() {
|
---|
| 751 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 752 | if (params.size() > 0) {
|
---|
| 753 | params.add("-noswitch");
|
---|
[623] | 754 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 755 | }
|
---|
| 756 | }
|
---|
| 757 |
|
---|
[608] | 758 | @SuppressWarnings("unused")
|
---|
| 759 | private void openEditionFolder() {
|
---|
| 760 | try {
|
---|
| 761 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
[639] | 762 | } catch (Exception e) {
|
---|
[608] | 763 | e.printStackTrace();
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
| 766 |
|
---|
[600] | 767 | @Override
|
---|
[593] | 768 | public void handleAbout(ApplicationEvent event) {
|
---|
| 769 | event.setHandled(true);
|
---|
| 770 | showAbout();
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 | @Override
|
---|
| 774 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | @Override
|
---|
| 778 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 | @Override
|
---|
| 782 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 783 | showSettings();
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | @Override
|
---|
| 787 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | @Override
|
---|
| 791 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 792 | event.setHandled(true);
|
---|
| 793 | saveLocalData();
|
---|
| 794 | exit();
|
---|
[593] | 795 | }
|
---|
| 796 |
|
---|
| 797 | @Override
|
---|
| 798 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 799 | }
|
---|
[600] | 800 |
|
---|
[592] | 801 | }
|
---|