[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;
|
---|
[647] | 6 | import java.awt.Insets;
|
---|
[608] | 7 | import java.awt.event.ActionEvent;
|
---|
[627] | 8 | import java.awt.event.ItemEvent;
|
---|
| 9 | import java.awt.event.ItemListener;
|
---|
[604] | 10 | import java.io.File;
|
---|
[623] | 11 | import java.net.URL;
|
---|
[634] | 12 | import java.util.Date;
|
---|
[605] | 13 | import java.util.HashMap;
|
---|
| 14 | import java.util.HashSet;
|
---|
[591] | 15 | import java.util.ResourceBundle;
|
---|
| 16 | import java.util.TreeMap;
|
---|
[600] | 17 | import java.util.TreeSet;
|
---|
[605] | 18 | import java.util.Vector;
|
---|
[591] | 19 |
|
---|
[623] | 20 | import javax.swing.AbstractAction;
|
---|
| 21 | import javax.swing.Icon;
|
---|
| 22 | import javax.swing.ImageIcon;
|
---|
[600] | 23 | import javax.swing.JButton;
|
---|
[627] | 24 | import javax.swing.JCheckBox;
|
---|
[591] | 25 | import javax.swing.JComboBox;
|
---|
[604] | 26 | import javax.swing.JFileChooser;
|
---|
[591] | 27 | import javax.swing.JFrame;
|
---|
[592] | 28 | import javax.swing.JLabel;
|
---|
[593] | 29 | import javax.swing.JMenu;
|
---|
[608] | 30 | import javax.swing.JMenuItem;
|
---|
[593] | 31 | import javax.swing.JOptionPane;
|
---|
[627] | 32 | import javax.swing.JPanel;
|
---|
[630] | 33 | import javax.swing.JRadioButton;
|
---|
[592] | 34 | import javax.swing.JSplitPane;
|
---|
[591] | 35 | import javax.swing.SwingUtilities;
|
---|
[631] | 36 | import javax.swing.ToolTipManager;
|
---|
[604] | 37 | import javax.swing.filechooser.FileFilter;
|
---|
[591] | 38 |
|
---|
[623] | 39 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
| 40 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[604] | 41 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[591] | 42 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[593] | 43 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[600] | 44 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[591] | 45 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
[648] | 46 | import net.oni2.aeinstaller.backend.packages.Package;
|
---|
| 47 | import net.oni2.aeinstaller.backend.packages.PackageManager;
|
---|
| 48 | import net.oni2.aeinstaller.backend.packages.Type;
|
---|
[600] | 49 | import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
|
---|
| 50 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
[621] | 51 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
[648] | 52 | import net.oni2.aeinstaller.backend.packages.download.ModDownloader;
|
---|
| 53 | import net.oni2.aeinstaller.backend.packages.download.ModDownloaderListener;
|
---|
| 54 | import net.oni2.aeinstaller.backend.packages.download.ModDownloader.State;
|
---|
[593] | 55 | import net.oni2.aeinstaller.gui.about.AboutDialog;
|
---|
[648] | 56 | import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
|
---|
[605] | 57 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[600] | 58 | import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
|
---|
[631] | 59 | import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
|
---|
| 60 | import net.oni2.aeinstaller.gui.modtable.ModTable;
|
---|
[591] | 61 | import net.oni2.aeinstaller.gui.settings.SettingsDialog;
|
---|
[625] | 62 | import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
|
---|
[591] | 63 |
|
---|
| 64 | import org.javabuilders.BuildResult;
|
---|
| 65 | import org.javabuilders.annotations.DoInBackground;
|
---|
| 66 | import org.javabuilders.event.BackgroundEvent;
|
---|
| 67 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[593] | 68 | import org.simplericity.macify.eawt.ApplicationEvent;
|
---|
| 69 | import org.simplericity.macify.eawt.ApplicationListener;
|
---|
[591] | 70 |
|
---|
| 71 | /**
|
---|
| 72 | * @author Christian Illy
|
---|
| 73 | */
|
---|
[600] | 74 | public class MainWin extends JFrame implements ApplicationListener,
|
---|
[631] | 75 | DownloadSizeListener, ModSelectionListener {
|
---|
[591] | 76 | private static final long serialVersionUID = -4027395051382659650L;
|
---|
| 77 |
|
---|
[629] | 78 | private ResourceBundle bundle = ResourceBundle
|
---|
| 79 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 80 | + getClass().getSimpleName());
|
---|
[591] | 81 | @SuppressWarnings("unused")
|
---|
| 82 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 83 |
|
---|
[593] | 84 | private JMenu mainMenu;
|
---|
[623] | 85 | private JMenu toolsMenu;
|
---|
[641] | 86 | private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
|
---|
[593] | 87 |
|
---|
[592] | 88 | private JSplitPane contents;
|
---|
| 89 |
|
---|
[591] | 90 | private JComboBox cmbModTypes;
|
---|
[630] | 91 | private JRadioButton radAll;
|
---|
| 92 | private JRadioButton radOnline;
|
---|
| 93 | private JRadioButton radLocal;
|
---|
[631] | 94 | private ModTable tblMods;
|
---|
[600] | 95 | private JLabel lblDownloadSizeVal;
|
---|
[591] | 96 |
|
---|
[639] | 97 | private JLabel lblTitleVal;
|
---|
[592] | 98 | private JLabel lblCreatorVal;
|
---|
[606] | 99 | private JLabel lblTypesVal;
|
---|
| 100 | private JLabel lblPlatformVal;
|
---|
[621] | 101 | private JLabel lblPackageNumberVal;
|
---|
[638] | 102 | private JLabel lblVersionNumberVal;
|
---|
[592] | 103 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 104 |
|
---|
[600] | 105 | private JButton btnInstall;
|
---|
| 106 |
|
---|
[648] | 107 | private TreeSet<Package> execCoreUpdates = new TreeSet<Package>();
|
---|
| 108 | private TreeSet<Package> execUpdates = null;
|
---|
[621] | 109 |
|
---|
[641] | 110 | private enum EInstallState {
|
---|
[621] | 111 | DONE,
|
---|
[641] | 112 | READY,
|
---|
| 113 | ABORTED,
|
---|
[621] | 114 | OFFLINE,
|
---|
[641] | 115 | INCOMPATIBLE,
|
---|
| 116 | CHECKING
|
---|
[621] | 117 | };
|
---|
| 118 |
|
---|
[641] | 119 | private EInstallState installState = EInstallState.DONE;
|
---|
[648] | 120 | private TreeSet<Package> installMods = null;
|
---|
| 121 | private TreeSet<Package> installDeps = null;
|
---|
[621] | 122 |
|
---|
[591] | 123 | /**
|
---|
| 124 | * Constructor of main window.
|
---|
| 125 | */
|
---|
| 126 | public MainWin() {
|
---|
[593] | 127 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
|
---|
| 128 | + " - v"
|
---|
| 129 | + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[591] | 130 |
|
---|
[640] | 131 | setSize(getWidth() + 150, getHeight());
|
---|
[651] | 132 | contents.setDividerLocation(550);
|
---|
[631] | 133 | contents.setResizeWeight(0.4);
|
---|
[593] | 134 |
|
---|
| 135 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
| 136 | mainMenu.setVisible(false);
|
---|
| 137 | }
|
---|
[600] | 138 |
|
---|
[631] | 139 | ToolTipManager.sharedInstance().setInitialDelay(250);
|
---|
| 140 |
|
---|
[600] | 141 | getRootPane().setDefaultButton(btnInstall);
|
---|
[605] | 142 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
|
---|
[630] | 143 | radAll.setSelected(true);
|
---|
[631] | 144 |
|
---|
| 145 | tblMods.addModSelectionListener(this);
|
---|
| 146 | tblMods.addDownloadSizeListener(this);
|
---|
[647] | 147 |
|
---|
| 148 | lblDescriptionVal.setMargin(new Insets(-15, 0, 0, 0));
|
---|
[591] | 149 | }
|
---|
| 150 |
|
---|
| 151 | private void initModTypeBox() {
|
---|
[592] | 152 | cmbModTypes.removeAllItems();
|
---|
| 153 |
|
---|
[600] | 154 | TreeMap<String, Type> types = new TreeMap<String, Type>();
|
---|
[648] | 155 | for (Type t : PackageManager.getInstance().getTypesWithContent()) {
|
---|
[600] | 156 | types.put(t.getName(), t);
|
---|
[591] | 157 | }
|
---|
[630] | 158 | cmbModTypes.addItem("-All-");
|
---|
[600] | 159 | for (Type t : types.values()) {
|
---|
[591] | 160 | cmbModTypes.addItem(t);
|
---|
| 161 | }
|
---|
| 162 | cmbModTypes.setSelectedIndex(0);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | private void exit() {
|
---|
| 166 | dispose();
|
---|
[608] | 167 | System.exit(0);
|
---|
[591] | 168 | }
|
---|
| 169 |
|
---|
| 170 | private void saveLocalData() {
|
---|
| 171 | Settings.getInstance().serializeToFile();
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
|
---|
| 175 | private void execDepotUpdate(final BackgroundEvent evt) {
|
---|
[649] | 176 | if (!Settings.getInstance().isOfflineMode() && !Settings.getInstance().isNoCacheUpdateMode()) {
|
---|
[634] | 177 | long start = new Date().getTime();
|
---|
| 178 |
|
---|
[621] | 179 | try {
|
---|
[634] | 180 | DepotManager.getInstance().updateInformation(false);
|
---|
[621] | 181 | } catch (Exception e) {
|
---|
| 182 | e.printStackTrace();
|
---|
| 183 | }
|
---|
[634] | 184 |
|
---|
| 185 | System.out.println("Took: " + (new Date().getTime() - start)
|
---|
| 186 | + " msec");
|
---|
[621] | 187 | }
|
---|
[633] | 188 |
|
---|
[648] | 189 | PackageManager.getInstance().init();
|
---|
[631] | 190 | tblMods.reloadData();
|
---|
[621] | 191 | initModTypeBox();
|
---|
[600] | 192 |
|
---|
[621] | 193 | tblMods.setVisible(true);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | @SuppressWarnings("unused")
|
---|
| 197 | private void checkUpdates(Object evtSource) {
|
---|
| 198 | if ((evtSource != this)
|
---|
| 199 | || Settings.getInstance().get("notifyupdates", true)) {
|
---|
| 200 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 201 | if (evtSource != this) {
|
---|
| 202 | JOptionPane.showMessageDialog(this,
|
---|
| 203 | bundle.getString("offlineMode.text"),
|
---|
| 204 | bundle.getString("offlineMode.title"),
|
---|
| 205 | JOptionPane.WARNING_MESSAGE);
|
---|
| 206 | }
|
---|
| 207 | } else {
|
---|
[648] | 208 | TreeSet<Package> mods = PackageManager.getInstance().getUpdatableMods();
|
---|
| 209 | TreeSet<Package> tools = PackageManager.getInstance()
|
---|
[621] | 210 | .getUpdatableTools();
|
---|
| 211 | int size = 0;
|
---|
[632] | 212 | JPanel panPackages = new JPanel(new GridLayout(0, 1));
|
---|
[648] | 213 | execUpdates = new TreeSet<Package>();
|
---|
[632] | 214 | execUpdates.addAll(mods);
|
---|
| 215 | execUpdates.addAll(tools);
|
---|
[648] | 216 | for (final Package m : mods) {
|
---|
[621] | 217 | size += m.getZipSize();
|
---|
[632] | 218 | JCheckBox check = new JCheckBox("Mod: " + m.getName());
|
---|
| 219 | check.setSelected(true);
|
---|
| 220 | check.addItemListener(new ItemListener() {
|
---|
| 221 | @Override
|
---|
| 222 | public void itemStateChanged(ItemEvent e) {
|
---|
| 223 | if (e.getStateChange() == ItemEvent.SELECTED)
|
---|
| 224 | execUpdates.add(m);
|
---|
| 225 | else
|
---|
| 226 | execUpdates.remove(m);
|
---|
| 227 | }
|
---|
| 228 | });
|
---|
| 229 | panPackages.add(check);
|
---|
[621] | 230 | }
|
---|
[648] | 231 | for (final Package m : tools) {
|
---|
[621] | 232 | size += m.getZipSize();
|
---|
[632] | 233 | JCheckBox check = new JCheckBox("Tool: " + m.getName());
|
---|
| 234 | check.setSelected(true);
|
---|
| 235 | panPackages.add(check);
|
---|
[621] | 236 | }
|
---|
[622] | 237 | if (size > 0) {
|
---|
[627] | 238 | // Build info dialog content
|
---|
[632] | 239 | JPanel packages = new JPanel(new BorderLayout(0, 7));
|
---|
| 240 | JLabel lblIntro = new JLabel("<html>"
|
---|
| 241 | + bundle.getString("updatesAvailable.text")
|
---|
| 242 | + "</html>");
|
---|
| 243 | JLabel lblSize = new JLabel("<html>"
|
---|
| 244 | + String.format(bundle
|
---|
| 245 | .getString("updatesAvailableSize.text"),
|
---|
| 246 | SizeFormatter.format(size, 3)) + "</html>");
|
---|
| 247 | packages.add(lblIntro, BorderLayout.NORTH);
|
---|
| 248 | packages.add(panPackages, BorderLayout.CENTER);
|
---|
| 249 | packages.add(lblSize, BorderLayout.SOUTH);
|
---|
[627] | 250 |
|
---|
[632] | 251 | JPanel pan = new JPanel(new BorderLayout(0, 25));
|
---|
| 252 | pan.add(packages, BorderLayout.CENTER);
|
---|
[627] | 253 | JCheckBox checkFutureUpdates = new JCheckBox(
|
---|
| 254 | bundle.getString("checkOnStartup.text"));
|
---|
| 255 | checkFutureUpdates.setSelected(Settings.getInstance().get(
|
---|
| 256 | "notifyupdates", true));
|
---|
| 257 | checkFutureUpdates.addItemListener(new ItemListener() {
|
---|
| 258 | @Override
|
---|
| 259 | public void itemStateChanged(ItemEvent evt) {
|
---|
| 260 | Settings.getInstance().put("notifyupdates",
|
---|
| 261 | evt.getStateChange() == ItemEvent.SELECTED);
|
---|
| 262 | }
|
---|
| 263 | });
|
---|
| 264 | pan.add(checkFutureUpdates, BorderLayout.SOUTH);
|
---|
| 265 |
|
---|
| 266 | // Show dialog
|
---|
| 267 | int res = JOptionPane.showConfirmDialog(this, pan,
|
---|
[622] | 268 | bundle.getString("updatesAvailable.title"),
|
---|
| 269 | JOptionPane.YES_NO_OPTION,
|
---|
| 270 | JOptionPane.QUESTION_MESSAGE);
|
---|
[632] | 271 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 272 | execUpdates = null;
|
---|
[622] | 273 | }
|
---|
[621] | 274 | }
|
---|
| 275 | }
|
---|
[591] | 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[624] | 279 | @SuppressWarnings("unused")
|
---|
| 280 | private void doUpdate() {
|
---|
[632] | 281 | if (execUpdates != null && execUpdates.size() > 0) {
|
---|
[646] | 282 | Downloader dl = new Downloader(execUpdates, null);
|
---|
[624] | 283 | try {
|
---|
| 284 | dl.setVisible(true);
|
---|
| 285 | if (dl.isFinished()) {
|
---|
| 286 | TreeSet<Integer> installed = Installer.getInstalledTools();
|
---|
[648] | 287 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
| 288 | for (Package m : execUpdates)
|
---|
[624] | 289 | if (m.isTool()
|
---|
| 290 | && installed.contains(m.getPackageNumber()))
|
---|
| 291 | tools.add(m);
|
---|
| 292 | if (tools.size() > 0) {
|
---|
| 293 | Installer.installTools(tools);
|
---|
| 294 | }
|
---|
| 295 | }
|
---|
| 296 | } finally {
|
---|
| 297 | dl.dispose();
|
---|
| 298 | }
|
---|
[591] | 299 | }
|
---|
[621] | 300 | execUpdates = null;
|
---|
[591] | 301 | }
|
---|
| 302 |
|
---|
| 303 | @SuppressWarnings("unused")
|
---|
| 304 | private void focus() {
|
---|
| 305 | SwingUtilities.invokeLater(new Runnable() {
|
---|
| 306 |
|
---|
| 307 | @Override
|
---|
| 308 | public void run() {
|
---|
| 309 | toFront();
|
---|
| 310 | repaint();
|
---|
| 311 | }
|
---|
| 312 | });
|
---|
| 313 |
|
---|
| 314 | }
|
---|
[646] | 315 |
|
---|
[645] | 316 | @SuppressWarnings("unused")
|
---|
[648] | 317 | private void showCorePackagesDialog() {
|
---|
| 318 | new CorePackagesDialog().setVisible(true);
|
---|
[645] | 319 | }
|
---|
[591] | 320 |
|
---|
| 321 | private void showSettings() {
|
---|
[593] | 322 | new SettingsDialog().setVisible(true);
|
---|
[591] | 323 | }
|
---|
| 324 |
|
---|
[593] | 325 | private void showAbout() {
|
---|
| 326 | new AboutDialog().setVisible(true);
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[604] | 329 | private JFileChooser getConfigOpenSaveDialog(boolean save) {
|
---|
| 330 | JFileChooser fc = new JFileChooser();
|
---|
| 331 | fc.setCurrentDirectory(Paths.getEditionBasePath());
|
---|
| 332 | if (save)
|
---|
| 333 | fc.setDialogType(JFileChooser.SAVE_DIALOG);
|
---|
| 334 | else
|
---|
| 335 | fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
---|
| 336 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
---|
| 337 | fc.setFileFilter(new FileFilter() {
|
---|
| 338 | @Override
|
---|
| 339 | public String getDescription() {
|
---|
| 340 | return "XML files";
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | @Override
|
---|
| 344 | public boolean accept(File arg0) {
|
---|
| 345 | return (arg0.isDirectory())
|
---|
| 346 | || (arg0.getName().toLowerCase().endsWith(".xml"));
|
---|
| 347 | }
|
---|
| 348 | });
|
---|
| 349 | fc.setMultiSelectionEnabled(false);
|
---|
| 350 | return fc;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
[593] | 353 | @SuppressWarnings("unused")
|
---|
| 354 | private void loadConfig() {
|
---|
[604] | 355 | JFileChooser fc = getConfigOpenSaveDialog(false);
|
---|
| 356 | int res = fc.showOpenDialog(this);
|
---|
| 357 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 358 | if (fc.getSelectedFile().exists())
|
---|
[631] | 359 | tblMods.reloadSelection(fc.getSelectedFile());
|
---|
[604] | 360 | }
|
---|
[593] | 361 | }
|
---|
| 362 |
|
---|
| 363 | @SuppressWarnings("unused")
|
---|
| 364 | private void saveConfig() {
|
---|
[604] | 365 | JFileChooser fc = getConfigOpenSaveDialog(true);
|
---|
| 366 | int res = fc.showSaveDialog(this);
|
---|
| 367 | if (res == JFileChooser.APPROVE_OPTION) {
|
---|
| 368 | File f = fc.getSelectedFile();
|
---|
| 369 | if (!f.getName().endsWith(".xml"))
|
---|
| 370 | f = new File(f.getParentFile(), f.getName() + ".xml");
|
---|
[648] | 371 | PackageManager.getInstance().saveModSelection(f,
|
---|
[631] | 372 | tblMods.getSelectedMods());
|
---|
[604] | 373 | }
|
---|
[593] | 374 | }
|
---|
| 375 |
|
---|
[600] | 376 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 377 | private void reglobalize(final BackgroundEvent evt) {
|
---|
| 378 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 379 | @Override
|
---|
| 380 | public void installProgressUpdate(int done, int total, String step) {
|
---|
| 381 | evt.setProgressEnd(total);
|
---|
| 382 | evt.setProgressValue(done);
|
---|
| 383 | evt.setProgressMessage(step);
|
---|
| 384 | }
|
---|
| 385 | });
|
---|
| 386 | }
|
---|
| 387 |
|
---|
[593] | 388 | @SuppressWarnings("unused")
|
---|
[600] | 389 | private void tools() {
|
---|
[625] | 390 | new ToolManager().setVisible(true);
|
---|
[593] | 391 | }
|
---|
[596] | 392 |
|
---|
[593] | 393 | @SuppressWarnings("unused")
|
---|
[623] | 394 | private void refreshToolsMenu() {
|
---|
| 395 | for (JMenuItem i : toolsMenuItems) {
|
---|
| 396 | toolsMenu.remove(i);
|
---|
| 397 | }
|
---|
| 398 | toolsMenuItems.clear();
|
---|
[648] | 399 | for (Package m : PackageManager.getInstance().getInstalledTools()) {
|
---|
[640] | 400 | File exe = m.getExeFile();
|
---|
| 401 | if (exe != null && exe.exists()) {
|
---|
[623] | 402 | JMenuItem item = new JMenuItem();
|
---|
| 403 | final Vector<String> params = new Vector<String>();
|
---|
[640] | 404 | if (exe.getName().toLowerCase().endsWith(".jar")) {
|
---|
| 405 | File jre = null;
|
---|
| 406 | if (Settings.getPlatform() == Platform.WIN)
|
---|
| 407 | jre = new File(System.getProperties().getProperty(
|
---|
| 408 | "java.home"), "bin/javaw.exe");
|
---|
| 409 | else
|
---|
| 410 | jre = new File(System.getProperties().getProperty(
|
---|
| 411 | "java.home"), "bin/java");
|
---|
| 412 | params.add(jre.getPath());
|
---|
| 413 | params.add("-jar");
|
---|
| 414 | }
|
---|
| 415 | params.add(exe.getPath());
|
---|
[623] | 416 | final File wd = m.getWorkingDir();
|
---|
| 417 | Icon ico = null;
|
---|
| 418 | if (m.getIconFile() != null && m.getIconFile().exists()) {
|
---|
| 419 | ico = new ImageIcon(m.getIconFile().getPath());
|
---|
| 420 | } else {
|
---|
[624] | 421 | URL icon = AEInstaller2.class
|
---|
| 422 | .getResource("images/transparent.png");
|
---|
[623] | 423 | ico = new ImageIcon(icon);
|
---|
| 424 | }
|
---|
| 425 | item.setAction(new AbstractAction(m.getName(), ico) {
|
---|
| 426 | private static final long serialVersionUID = 1L;
|
---|
| 427 |
|
---|
| 428 | @Override
|
---|
| 429 | public void actionPerformed(ActionEvent e) {
|
---|
| 430 | AppExecution.execute(params, wd);
|
---|
| 431 | }
|
---|
| 432 | });
|
---|
| 433 | toolsMenuItems.add(item);
|
---|
| 434 | toolsMenu.add(item);
|
---|
| 435 | }
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 |
|
---|
[593] | 439 | private void revertSelection() {
|
---|
[631] | 440 | tblMods.revertSelection();
|
---|
[593] | 441 | }
|
---|
| 442 |
|
---|
[648] | 443 | @DoInBackground(progressMessage = "checkCorePackages.title", cancelable = false, indeterminateProgress = false)
|
---|
| 444 | private void checkCorePackages(final BackgroundEvent evt) {
|
---|
[621] | 445 | if (!Settings.getInstance().isOfflineMode()) {
|
---|
[648] | 446 | for (Package m : PackageManager.getInstance().getCoreTools()) {
|
---|
[621] | 447 | if (m.isNewerAvailable()) {
|
---|
[648] | 448 | execCoreUpdates.add(m);
|
---|
[621] | 449 | }
|
---|
[604] | 450 | }
|
---|
[648] | 451 | for (Package m : PackageManager.getInstance().getCoreMods()) {
|
---|
[621] | 452 | if (m.isNewerAvailable()) {
|
---|
[648] | 453 | execCoreUpdates.add(m);
|
---|
[621] | 454 | }
|
---|
[604] | 455 | }
|
---|
[648] | 456 | if (execCoreUpdates.size() > 0) {
|
---|
| 457 | ModDownloader m = new ModDownloader(execCoreUpdates,
|
---|
[621] | 458 | new ModDownloaderListener() {
|
---|
| 459 | @Override
|
---|
| 460 | public void updateStatus(ModDownloader source,
|
---|
[648] | 461 | Package currentDownload, State state,
|
---|
[646] | 462 | int filesDown, int filesTotal,
|
---|
[621] | 463 | int bytesDown, int bytesTotal,
|
---|
| 464 | int duration, int remaining, int speed) {
|
---|
| 465 | evt.setProgressEnd(filesTotal);
|
---|
| 466 | evt.setProgressValue(filesDown);
|
---|
| 467 | }
|
---|
| 468 | });
|
---|
| 469 | while (!m.isFinished()) {
|
---|
| 470 | try {
|
---|
| 471 | Thread.sleep(10);
|
---|
| 472 | } catch (InterruptedException e) {
|
---|
| 473 | e.printStackTrace();
|
---|
| 474 | }
|
---|
[604] | 475 | }
|
---|
| 476 | }
|
---|
[621] | 477 | evt.setProgressMessage(bundle
|
---|
[648] | 478 | .getString("coreToolsInstall.title"));
|
---|
[621] | 479 | Installer
|
---|
[648] | 480 | .installTools(PackageManager.getInstance().getCoreTools());
|
---|
[604] | 481 | }
|
---|
[602] | 482 | }
|
---|
| 483 |
|
---|
[641] | 484 | @SuppressWarnings("unused")
|
---|
[648] | 485 | private void infoCorePackages() {
|
---|
| 486 | if (execCoreUpdates.size() > 0) {
|
---|
[645] | 487 | String packages = "";
|
---|
[648] | 488 | for (Package m : execCoreUpdates) {
|
---|
[645] | 489 | packages += String.format("\n - %s (%s)", m.getName(),
|
---|
| 490 | m.getVersion());
|
---|
| 491 | }
|
---|
| 492 | JOptionPane.showMessageDialog(this, String.format(
|
---|
[648] | 493 | bundle.getString("corePackagesUpdated.text"), packages),
|
---|
| 494 | bundle.getString("corePackagesUpdated.title"),
|
---|
[645] | 495 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 496 | }
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | @SuppressWarnings("unused")
|
---|
[641] | 500 | private void install() {
|
---|
[648] | 501 | TreeSet<Package> mods = new TreeSet<Package>();
|
---|
| 502 | mods.addAll(PackageManager.getInstance().getCoreMods());
|
---|
[631] | 503 | mods.addAll(tblMods.getSelectedMods());
|
---|
[600] | 504 |
|
---|
[648] | 505 | installDeps = new TreeSet<Package>();
|
---|
[646] | 506 |
|
---|
[641] | 507 | installState = EInstallState.CHECKING;
|
---|
[605] | 508 |
|
---|
[641] | 509 | while (installState == EInstallState.CHECKING) {
|
---|
[648] | 510 | TreeSet<Package> toDownload = new TreeSet<Package>();
|
---|
| 511 | for (Package m : mods) {
|
---|
[605] | 512 | if (!m.isLocalAvailable())
|
---|
| 513 | toDownload.add(m);
|
---|
| 514 | }
|
---|
[621] | 515 | if (Settings.getInstance().isOfflineMode()) {
|
---|
[641] | 516 | installState = EInstallState.OFFLINE;
|
---|
[621] | 517 | break;
|
---|
| 518 | }
|
---|
[605] | 519 | if (toDownload.size() > 0) {
|
---|
[646] | 520 | Downloader dl = new Downloader(toDownload, installDeps);
|
---|
[617] | 521 | try {
|
---|
| 522 | dl.setVisible(true);
|
---|
[641] | 523 | if (!dl.isFinished()) {
|
---|
| 524 | installState = EInstallState.ABORTED;
|
---|
[617] | 525 | break;
|
---|
[641] | 526 | }
|
---|
[617] | 527 | } finally {
|
---|
| 528 | dl.dispose();
|
---|
| 529 | }
|
---|
[605] | 530 | }
|
---|
[648] | 531 | HashMap<Package, HashSet<Package>> dependencies = PackageManager.getInstance()
|
---|
[605] | 532 | .checkDependencies(mods);
|
---|
| 533 | if (dependencies.size() > 0) {
|
---|
[648] | 534 | for (HashSet<Package> hm : dependencies.values()) {
|
---|
[646] | 535 | installDeps.addAll(hm);
|
---|
| 536 | }
|
---|
[647] | 537 |
|
---|
[646] | 538 | if (!Settings.getInstance()
|
---|
| 539 | .get("notifyDepsAfterInstall", false)) {
|
---|
| 540 | int size = 0;
|
---|
| 541 | String depsLocalString = "";
|
---|
| 542 | String depsDownloadString = "";
|
---|
[648] | 543 | for (Package m : dependencies.keySet()) {
|
---|
| 544 | for (Package mDep : dependencies.get(m)) {
|
---|
[646] | 545 | if (!mods.contains(mDep)) {
|
---|
| 546 | mods.add(mDep);
|
---|
| 547 | if (!mDep.isLocalAvailable()) {
|
---|
| 548 | size += mDep.getZipSize();
|
---|
| 549 | if (depsDownloadString.length() > 0)
|
---|
| 550 | depsDownloadString += "\n";
|
---|
| 551 | depsDownloadString += " - "
|
---|
| 552 | + mDep.getName();
|
---|
| 553 | } else {
|
---|
| 554 | if (depsLocalString.length() > 0)
|
---|
| 555 | depsLocalString += "\n";
|
---|
| 556 | depsLocalString += " - " + mDep.getName();
|
---|
| 557 | }
|
---|
[641] | 558 | }
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
[646] | 561 | if (depsLocalString.length() == 0)
|
---|
| 562 | depsLocalString = bundle
|
---|
| 563 | .getString("installDependencies.none");
|
---|
| 564 | if (depsDownloadString.length() == 0)
|
---|
| 565 | depsDownloadString = bundle
|
---|
| 566 | .getString("installDependencies.none");
|
---|
[641] | 567 |
|
---|
[646] | 568 | int res = JOptionPane.showConfirmDialog(this, String
|
---|
| 569 | .format(bundle
|
---|
| 570 | .getString("installDependencies.text"),
|
---|
| 571 | depsLocalString, depsDownloadString,
|
---|
| 572 | SizeFormatter.format(size, 3)), bundle
|
---|
| 573 | .getString("installDependencies.title"),
|
---|
| 574 | JOptionPane.YES_NO_OPTION,
|
---|
| 575 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 576 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 577 | installState = EInstallState.ABORTED;
|
---|
| 578 | break;
|
---|
| 579 | }
|
---|
[641] | 580 | }
|
---|
[605] | 581 | } else {
|
---|
[648] | 582 | HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
|
---|
[645] | 583 | .getInstance().checkIncompabitilites(mods);
|
---|
[643] | 584 | if (incompatibilities.size() > 0) {
|
---|
[641] | 585 | installState = EInstallState.INCOMPATIBLE;
|
---|
[643] | 586 |
|
---|
| 587 | String incompatString = "";
|
---|
[648] | 588 | for (Package m : incompatibilities.keySet()) {
|
---|
[643] | 589 | if (incompatString.length() > 0)
|
---|
| 590 | incompatString += "\n";
|
---|
| 591 | incompatString += m.getName() + ": ";
|
---|
| 592 | String confMods = "";
|
---|
[648] | 593 | for (Package mConf : incompatibilities.get(m)) {
|
---|
[643] | 594 | if (confMods.length() > 0)
|
---|
| 595 | confMods += ", ";
|
---|
| 596 | confMods += mConf.getName();
|
---|
| 597 | }
|
---|
| 598 | incompatString += confMods;
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 602 | bundle.getString("installIncompatibilities.text"),
|
---|
| 603 | incompatString), bundle
|
---|
| 604 | .getString("installIncompatibilities.title"),
|
---|
| 605 | JOptionPane.ERROR_MESSAGE);
|
---|
[605] | 606 | break;
|
---|
| 607 | } else {
|
---|
[641] | 608 | installState = EInstallState.READY;
|
---|
[605] | 609 | }
|
---|
| 610 | }
|
---|
[600] | 611 | }
|
---|
[618] | 612 |
|
---|
[641] | 613 | if (installState == EInstallState.READY) {
|
---|
[648] | 614 | installMods = new TreeSet<Package>();
|
---|
| 615 | TreeSet<Package> actuallyTools = new TreeSet<Package>();
|
---|
[623] | 616 |
|
---|
[648] | 617 | for (Package m : mods) {
|
---|
[623] | 618 | if (m.isTool())
|
---|
| 619 | actuallyTools.add(m);
|
---|
| 620 | else
|
---|
[641] | 621 | installMods.add(m);
|
---|
[623] | 622 | }
|
---|
| 623 |
|
---|
| 624 | if (actuallyTools.size() > 0) {
|
---|
| 625 | Installer.installTools(actuallyTools);
|
---|
| 626 | }
|
---|
[641] | 627 | }
|
---|
[623] | 628 |
|
---|
[641] | 629 | }
|
---|
| 630 |
|
---|
| 631 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
|
---|
| 632 | private void installExec(final BackgroundEvent evt) {
|
---|
| 633 | if (installState == EInstallState.READY) {
|
---|
| 634 | Installer.install(installMods, new InstallProgressListener() {
|
---|
[605] | 635 | @Override
|
---|
| 636 | public void installProgressUpdate(int done, int total,
|
---|
| 637 | String step) {
|
---|
| 638 | evt.setProgressEnd(total);
|
---|
| 639 | evt.setProgressValue(done);
|
---|
| 640 | evt.setProgressMessage(step);
|
---|
| 641 | }
|
---|
| 642 | });
|
---|
[641] | 643 | installState = EInstallState.DONE;
|
---|
[605] | 644 | }
|
---|
[641] | 645 | installMods = null;
|
---|
[600] | 646 | }
|
---|
[618] | 647 |
|
---|
[617] | 648 | @SuppressWarnings("unused")
|
---|
| 649 | private void installDone() {
|
---|
[648] | 650 | PackageManager.getInstance().updateInstalledMods();
|
---|
[641] | 651 | switch (installState) {
|
---|
[621] | 652 | case DONE:
|
---|
[641] | 653 | revertSelection();
|
---|
[646] | 654 | if (installDeps.size() > 0
|
---|
| 655 | && Settings.getInstance().get("notifyDepsAfterInstall",
|
---|
| 656 | false)) {
|
---|
| 657 | String installedDeps = "";
|
---|
[648] | 658 | for (Package m : installDeps) {
|
---|
[646] | 659 | if (installedDeps.length() > 0)
|
---|
| 660 | installedDeps += "\n";
|
---|
| 661 | installedDeps += " - " + m.getName();
|
---|
| 662 | }
|
---|
| 663 | JOptionPane.showMessageDialog(this, String.format(
|
---|
| 664 | bundle.getString("installDoneDeps.text"),
|
---|
| 665 | installedDeps), bundle
|
---|
| 666 | .getString("installDone.title"),
|
---|
| 667 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 668 | } else {
|
---|
| 669 | JOptionPane.showMessageDialog(this,
|
---|
| 670 | bundle.getString("installDone.text"),
|
---|
| 671 | bundle.getString("installDone.title"),
|
---|
| 672 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 673 | }
|
---|
[621] | 674 | break;
|
---|
| 675 | case OFFLINE:
|
---|
| 676 | JOptionPane.showMessageDialog(this,
|
---|
| 677 | bundle.getString("offlineMode.text"),
|
---|
| 678 | bundle.getString("offlineMode.title"),
|
---|
| 679 | JOptionPane.WARNING_MESSAGE);
|
---|
| 680 | break;
|
---|
[641] | 681 | default:
|
---|
[621] | 682 | break;
|
---|
| 683 | }
|
---|
[646] | 684 | installDeps = null;
|
---|
[617] | 685 | }
|
---|
[600] | 686 |
|
---|
[631] | 687 | @Override
|
---|
[648] | 688 | public void modSelectionChanged(ModTable source, Package m) {
|
---|
[639] | 689 | lblTitleVal.setText("");
|
---|
[592] | 690 | lblCreatorVal.setText("");
|
---|
| 691 | lblDescriptionVal.setText("");
|
---|
[606] | 692 | lblTypesVal.setText("");
|
---|
| 693 | lblPlatformVal.setText("");
|
---|
[621] | 694 | lblPackageNumberVal.setText("");
|
---|
[638] | 695 | lblVersionNumberVal.setText("");
|
---|
[600] | 696 | if (m != null) {
|
---|
[639] | 697 | lblTitleVal.setText(m.getName());
|
---|
[600] | 698 | lblCreatorVal.setText(m.getCreator());
|
---|
| 699 | lblDescriptionVal.setText(m.getDescription());
|
---|
[606] | 700 |
|
---|
| 701 | String types = "";
|
---|
| 702 | for (Type t : m.getTypes()) {
|
---|
| 703 | if (types.length() > 0)
|
---|
| 704 | types += ", ";
|
---|
| 705 | types += t.getName();
|
---|
| 706 | }
|
---|
| 707 | lblTypesVal.setText(types);
|
---|
| 708 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
[621] | 709 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[638] | 710 | lblVersionNumberVal.setText(m.getVersion());
|
---|
[591] | 711 | }
|
---|
| 712 | }
|
---|
| 713 |
|
---|
[630] | 714 | private void updateTableFilter() {
|
---|
| 715 | Object o = cmbModTypes.getSelectedItem();
|
---|
| 716 | Type t = null;
|
---|
| 717 | if (o instanceof Type)
|
---|
| 718 | t = (Type) o;
|
---|
| 719 | int downloadState = 0;
|
---|
| 720 | if (radOnline.isSelected())
|
---|
| 721 | downloadState = 1;
|
---|
| 722 | if (radLocal.isSelected())
|
---|
| 723 | downloadState = 2;
|
---|
[631] | 724 | tblMods.setFilter(t, downloadState);
|
---|
[630] | 725 | }
|
---|
| 726 |
|
---|
[591] | 727 | @SuppressWarnings("unused")
|
---|
[592] | 728 | private void modTypeSelection() {
|
---|
[630] | 729 | updateTableFilter();
|
---|
[591] | 730 | }
|
---|
[593] | 731 |
|
---|
[630] | 732 | @SuppressWarnings("unused")
|
---|
| 733 | private void showTypeSelection() {
|
---|
| 734 | updateTableFilter();
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[593] | 737 | @Override
|
---|
[600] | 738 | public void downloadSizeChanged(int newSize) {
|
---|
| 739 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
|
---|
| 740 | }
|
---|
| 741 |
|
---|
[616] | 742 | @SuppressWarnings("unused")
|
---|
| 743 | private void checkInitialize() {
|
---|
[600] | 744 | if (!Installer.isEditionInitialized()) {
|
---|
[621] | 745 | if (!OniSplit.isOniSplitInstalled()) {
|
---|
| 746 | JOptionPane.showMessageDialog(this,
|
---|
| 747 | bundle.getString("noOniSplit.text"),
|
---|
| 748 | bundle.getString("noOniSplit.title"),
|
---|
| 749 | JOptionPane.ERROR_MESSAGE);
|
---|
[600] | 750 | exit();
|
---|
[621] | 751 | } else {
|
---|
| 752 | int res = JOptionPane
|
---|
| 753 | .showConfirmDialog(this,
|
---|
| 754 | bundle.getString("askInitialize.text"),
|
---|
| 755 | bundle.getString("askInitialize.title"),
|
---|
| 756 | JOptionPane.YES_NO_OPTION,
|
---|
| 757 | JOptionPane.QUESTION_MESSAGE);
|
---|
| 758 | if (res == JOptionPane.NO_OPTION) {
|
---|
| 759 | saveLocalData();
|
---|
| 760 | exit();
|
---|
| 761 | }
|
---|
[600] | 762 | }
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
[606] | 765 |
|
---|
[616] | 766 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
|
---|
| 767 | private void initialize(final BackgroundEvent evt) {
|
---|
| 768 | if (!Installer.isEditionInitialized()) {
|
---|
| 769 | Installer.initializeEdition(new InstallProgressListener() {
|
---|
| 770 | @Override
|
---|
| 771 | public void installProgressUpdate(int done, int total,
|
---|
| 772 | String step) {
|
---|
| 773 | evt.setProgressEnd(total);
|
---|
| 774 | evt.setProgressValue(done);
|
---|
| 775 | evt.setProgressMessage(step);
|
---|
| 776 | }
|
---|
| 777 | });
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 |
|
---|
[605] | 781 | private Vector<String> getBasicOniLaunchParams() {
|
---|
| 782 | Vector<String> params = new Vector<String>();
|
---|
[618] | 783 | File exe = null;
|
---|
[605] | 784 | switch (Settings.getPlatform()) {
|
---|
| 785 | case WIN:
|
---|
[618] | 786 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 787 | if (exe.exists())
|
---|
| 788 | params.add(exe.getPath());
|
---|
[605] | 789 | break;
|
---|
| 790 | case MACOS:
|
---|
[618] | 791 | exe = new File(Paths.getEditionBasePath(),
|
---|
| 792 | "Oni.app/Contents/MacOS/Oni");
|
---|
| 793 | if (exe.exists())
|
---|
| 794 | params.add(exe.getPath());
|
---|
[605] | 795 | break;
|
---|
| 796 | case LINUX:
|
---|
| 797 | String wine = Settings.getWinePath();
|
---|
[618] | 798 | exe = new File(Paths.getEditionBasePath(), "Oni.exe");
|
---|
| 799 | if (exe.exists()) {
|
---|
| 800 | if (wine != null) {
|
---|
| 801 | params.add(wine);
|
---|
| 802 | params.add(exe.getPath());
|
---|
| 803 | }
|
---|
[605] | 804 | }
|
---|
| 805 | break;
|
---|
| 806 | default:
|
---|
| 807 | }
|
---|
| 808 | if (params.size() > 0) {
|
---|
| 809 | params.add("-debugfiles");
|
---|
| 810 | }
|
---|
| 811 | return params;
|
---|
| 812 | }
|
---|
[600] | 813 |
|
---|
[605] | 814 | @SuppressWarnings("unused")
|
---|
| 815 | private void oniFull() {
|
---|
| 816 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 817 | if (params.size() > 0) {
|
---|
[623] | 818 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 819 | }
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | @SuppressWarnings("unused")
|
---|
| 823 | private void oniWin() {
|
---|
| 824 | Vector<String> params = getBasicOniLaunchParams();
|
---|
| 825 | if (params.size() > 0) {
|
---|
| 826 | params.add("-noswitch");
|
---|
[623] | 827 | AppExecution.execute(params, Paths.getEditionBasePath());
|
---|
[605] | 828 | }
|
---|
| 829 | }
|
---|
| 830 |
|
---|
[608] | 831 | @SuppressWarnings("unused")
|
---|
| 832 | private void openEditionFolder() {
|
---|
| 833 | try {
|
---|
| 834 | Desktop.getDesktop().open(Paths.getEditionBasePath());
|
---|
[639] | 835 | } catch (Exception e) {
|
---|
[608] | 836 | e.printStackTrace();
|
---|
| 837 | }
|
---|
| 838 | }
|
---|
| 839 |
|
---|
[600] | 840 | @Override
|
---|
[593] | 841 | public void handleAbout(ApplicationEvent event) {
|
---|
| 842 | event.setHandled(true);
|
---|
| 843 | showAbout();
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 | @Override
|
---|
| 847 | public void handleOpenApplication(ApplicationEvent event) {
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | @Override
|
---|
| 851 | public void handleOpenFile(ApplicationEvent event) {
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | @Override
|
---|
| 855 | public void handlePreferences(ApplicationEvent event) {
|
---|
| 856 | showSettings();
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | @Override
|
---|
| 860 | public void handlePrintFile(ApplicationEvent event) {
|
---|
| 861 | }
|
---|
| 862 |
|
---|
| 863 | @Override
|
---|
| 864 | public void handleQuit(ApplicationEvent event) {
|
---|
[605] | 865 | event.setHandled(true);
|
---|
| 866 | saveLocalData();
|
---|
| 867 | exit();
|
---|
[593] | 868 | }
|
---|
| 869 |
|
---|
| 870 | @Override
|
---|
| 871 | public void handleReOpenApplication(ApplicationEvent event) {
|
---|
| 872 | }
|
---|
[600] | 873 |
|
---|
[592] | 874 | }
|
---|