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