source: AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java@ 667

Last change on this file since 667 was 662, checked in by alloc, 12 years ago

AEI2 0.99m:

  • Made the Depot query even more invulnerable against caches
File size: 25.9 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui;
2
[627]3import java.awt.BorderLayout;
[608]4import java.awt.Desktop;
[632]5import java.awt.GridLayout;
[608]6import java.awt.event.ActionEvent;
[627]7import java.awt.event.ItemEvent;
8import java.awt.event.ItemListener;
[660]9import java.awt.event.KeyAdapter;
10import java.awt.event.KeyEvent;
[604]11import java.io.File;
[623]12import java.net.URL;
[634]13import java.util.Date;
[605]14import java.util.HashMap;
15import java.util.HashSet;
[591]16import java.util.ResourceBundle;
17import java.util.TreeMap;
[600]18import java.util.TreeSet;
[605]19import java.util.Vector;
[591]20
[623]21import javax.swing.AbstractAction;
22import javax.swing.Icon;
23import javax.swing.ImageIcon;
[600]24import javax.swing.JButton;
[627]25import javax.swing.JCheckBox;
[591]26import javax.swing.JComboBox;
[604]27import javax.swing.JFileChooser;
[591]28import javax.swing.JFrame;
[592]29import javax.swing.JLabel;
[593]30import javax.swing.JMenu;
[608]31import javax.swing.JMenuItem;
[593]32import javax.swing.JOptionPane;
[627]33import javax.swing.JPanel;
[630]34import javax.swing.JRadioButton;
[658]35import javax.swing.JScrollPane;
[592]36import javax.swing.JSplitPane;
[660]37import javax.swing.JTextField;
[591]38import javax.swing.SwingUtilities;
[631]39import javax.swing.ToolTipManager;
[604]40import javax.swing.filechooser.FileFilter;
[591]41
[623]42import net.oni2.aeinstaller.AEInstaller2;
43import net.oni2.aeinstaller.backend.AppExecution;
[604]44import net.oni2.aeinstaller.backend.Paths;
[591]45import net.oni2.aeinstaller.backend.Settings;
[593]46import net.oni2.aeinstaller.backend.Settings.Platform;
[600]47import net.oni2.aeinstaller.backend.SizeFormatter;
[591]48import net.oni2.aeinstaller.backend.depot.DepotManager;
[658]49import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
50import net.oni2.aeinstaller.backend.oni.Installer;
51import net.oni2.aeinstaller.backend.oni.OniSplit;
[648]52import net.oni2.aeinstaller.backend.packages.Package;
53import net.oni2.aeinstaller.backend.packages.PackageManager;
54import net.oni2.aeinstaller.backend.packages.Type;
55import net.oni2.aeinstaller.backend.packages.download.ModDownloader;
[658]56import net.oni2.aeinstaller.backend.packages.download.ModDownloader.State;
[648]57import net.oni2.aeinstaller.backend.packages.download.ModDownloaderListener;
[593]58import net.oni2.aeinstaller.gui.about.AboutDialog;
[648]59import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
[605]60import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
[600]61import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
[660]62import net.oni2.aeinstaller.gui.modtable.EApplyFilterTo;
[631]63import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
64import net.oni2.aeinstaller.gui.modtable.ModTable;
[658]65import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
66import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
[591]67import net.oni2.aeinstaller.gui.settings.SettingsDialog;
[625]68import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
[591]69
70import org.javabuilders.BuildResult;
71import org.javabuilders.annotations.DoInBackground;
72import org.javabuilders.event.BackgroundEvent;
73import org.javabuilders.swing.SwingJavaBuilder;
[593]74import org.simplericity.macify.eawt.ApplicationEvent;
75import org.simplericity.macify.eawt.ApplicationListener;
[591]76
77/**
78 * @author Christian Illy
79 */
[600]80public 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 {
[662]196 DepotManager.getInstance().updateInformation();
[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
[661]403 @SuppressWarnings("unused")
404 private boolean reglobalizeVerify() {
405 int res = JOptionPane.showConfirmDialog(this,
406 bundle.getString("rebuildCore.text"),
407 bundle.getString("rebuildCore.title"),
408 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
409 return res == JOptionPane.YES_OPTION;
410 }
411
[600]412 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
413 private void reglobalize(final BackgroundEvent evt) {
414 Installer.initializeEdition(new InstallProgressListener() {
415 @Override
416 public void installProgressUpdate(int done, int total, String step) {
417 evt.setProgressEnd(total);
418 evt.setProgressValue(done);
419 evt.setProgressMessage(step);
420 }
421 });
422 }
423
[593]424 @SuppressWarnings("unused")
[600]425 private void tools() {
[625]426 new ToolManager().setVisible(true);
[593]427 }
[596]428
[593]429 @SuppressWarnings("unused")
[623]430 private void refreshToolsMenu() {
431 for (JMenuItem i : toolsMenuItems) {
432 toolsMenu.remove(i);
433 }
434 toolsMenuItems.clear();
[648]435 for (Package m : PackageManager.getInstance().getInstalledTools()) {
[640]436 File exe = m.getExeFile();
437 if (exe != null && exe.exists()) {
[623]438 JMenuItem item = new JMenuItem();
439 final Vector<String> params = new Vector<String>();
[640]440 if (exe.getName().toLowerCase().endsWith(".jar")) {
441 File jre = null;
442 if (Settings.getPlatform() == Platform.WIN)
443 jre = new File(System.getProperties().getProperty(
444 "java.home"), "bin/javaw.exe");
445 else
446 jre = new File(System.getProperties().getProperty(
447 "java.home"), "bin/java");
448 params.add(jre.getPath());
449 params.add("-jar");
450 }
451 params.add(exe.getPath());
[623]452 final File wd = m.getWorkingDir();
453 Icon ico = null;
454 if (m.getIconFile() != null && m.getIconFile().exists()) {
455 ico = new ImageIcon(m.getIconFile().getPath());
456 } else {
[624]457 URL icon = AEInstaller2.class
458 .getResource("images/transparent.png");
[623]459 ico = new ImageIcon(icon);
460 }
461 item.setAction(new AbstractAction(m.getName(), ico) {
462 private static final long serialVersionUID = 1L;
463
464 @Override
465 public void actionPerformed(ActionEvent e) {
466 AppExecution.execute(params, wd);
467 }
468 });
469 toolsMenuItems.add(item);
470 toolsMenu.add(item);
471 }
472 }
473 }
474
[593]475 private void revertSelection() {
[631]476 tblMods.revertSelection();
[593]477 }
[658]478
[657]479 @SuppressWarnings("unused")
480 private void unSelectAll() {
481 tblMods.unSelectAll();
482 }
[593]483
[648]484 @DoInBackground(progressMessage = "checkCorePackages.title", cancelable = false, indeterminateProgress = false)
485 private void checkCorePackages(final BackgroundEvent evt) {
[621]486 if (!Settings.getInstance().isOfflineMode()) {
[648]487 for (Package m : PackageManager.getInstance().getCoreTools()) {
[621]488 if (m.isNewerAvailable()) {
[648]489 execCoreUpdates.add(m);
[621]490 }
[604]491 }
[648]492 for (Package m : PackageManager.getInstance().getCoreMods()) {
[621]493 if (m.isNewerAvailable()) {
[648]494 execCoreUpdates.add(m);
[621]495 }
[604]496 }
[648]497 if (execCoreUpdates.size() > 0) {
498 ModDownloader m = new ModDownloader(execCoreUpdates,
[621]499 new ModDownloaderListener() {
500 @Override
501 public void updateStatus(ModDownloader source,
[648]502 Package currentDownload, State state,
[646]503 int filesDown, int filesTotal,
[621]504 int bytesDown, int bytesTotal,
505 int duration, int remaining, int speed) {
506 evt.setProgressEnd(filesTotal);
507 evt.setProgressValue(filesDown);
508 }
509 });
510 while (!m.isFinished()) {
511 try {
512 Thread.sleep(10);
513 } catch (InterruptedException e) {
514 e.printStackTrace();
515 }
[604]516 }
517 }
[657]518 evt.setProgressMessage(bundle.getString("coreToolsInstall.title"));
519 Installer.installTools(PackageManager.getInstance().getCoreTools());
[604]520 }
[602]521 }
522
[641]523 @SuppressWarnings("unused")
[648]524 private void infoCorePackages() {
525 if (execCoreUpdates.size() > 0) {
[645]526 String packages = "";
[648]527 for (Package m : execCoreUpdates) {
[645]528 packages += String.format("\n - %s (%s)", m.getName(),
529 m.getVersion());
530 }
531 JOptionPane.showMessageDialog(this, String.format(
[648]532 bundle.getString("corePackagesUpdated.text"), packages),
533 bundle.getString("corePackagesUpdated.title"),
[645]534 JOptionPane.INFORMATION_MESSAGE);
535 }
536 }
537
538 @SuppressWarnings("unused")
[641]539 private void install() {
[648]540 TreeSet<Package> mods = new TreeSet<Package>();
541 mods.addAll(PackageManager.getInstance().getCoreMods());
[631]542 mods.addAll(tblMods.getSelectedMods());
[600]543
[648]544 installDeps = new TreeSet<Package>();
[646]545
[641]546 installState = EInstallState.CHECKING;
[605]547
[641]548 while (installState == EInstallState.CHECKING) {
[648]549 TreeSet<Package> toDownload = new TreeSet<Package>();
550 for (Package m : mods) {
[605]551 if (!m.isLocalAvailable())
552 toDownload.add(m);
553 }
[657]554 if (toDownload.size() > 0 && Settings.getInstance().isOfflineMode()) {
[641]555 installState = EInstallState.OFFLINE;
[621]556 break;
557 }
[605]558 if (toDownload.size() > 0) {
[646]559 Downloader dl = new Downloader(toDownload, installDeps);
[617]560 try {
561 dl.setVisible(true);
[641]562 if (!dl.isFinished()) {
563 installState = EInstallState.ABORTED;
[617]564 break;
[641]565 }
[617]566 } finally {
567 dl.dispose();
568 }
[605]569 }
[657]570 HashMap<Package, HashSet<Package>> dependencies = PackageManager
571 .getInstance().checkDependencies(mods);
[605]572 if (dependencies.size() > 0) {
[648]573 for (HashSet<Package> hm : dependencies.values()) {
[646]574 installDeps.addAll(hm);
575 }
[647]576
[646]577 if (!Settings.getInstance()
578 .get("notifyDepsAfterInstall", false)) {
579 int size = 0;
580 String depsLocalString = "";
581 String depsDownloadString = "";
[648]582 for (Package m : dependencies.keySet()) {
583 for (Package mDep : dependencies.get(m)) {
[646]584 if (!mods.contains(mDep)) {
585 mods.add(mDep);
586 if (!mDep.isLocalAvailable()) {
587 size += mDep.getZipSize();
588 if (depsDownloadString.length() > 0)
589 depsDownloadString += "\n";
590 depsDownloadString += " - "
591 + mDep.getName();
592 } else {
593 if (depsLocalString.length() > 0)
594 depsLocalString += "\n";
595 depsLocalString += " - " + mDep.getName();
596 }
[641]597 }
598 }
599 }
[646]600 if (depsLocalString.length() == 0)
601 depsLocalString = bundle
602 .getString("installDependencies.none");
603 if (depsDownloadString.length() == 0)
604 depsDownloadString = bundle
605 .getString("installDependencies.none");
[641]606
[646]607 int res = JOptionPane.showConfirmDialog(this, String
608 .format(bundle
609 .getString("installDependencies.text"),
610 depsLocalString, depsDownloadString,
611 SizeFormatter.format(size, 3)), bundle
612 .getString("installDependencies.title"),
613 JOptionPane.YES_NO_OPTION,
614 JOptionPane.INFORMATION_MESSAGE);
615 if (res == JOptionPane.NO_OPTION) {
616 installState = EInstallState.ABORTED;
617 break;
618 }
[641]619 }
[605]620 } else {
[648]621 HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
[645]622 .getInstance().checkIncompabitilites(mods);
[643]623 if (incompatibilities.size() > 0) {
[641]624 installState = EInstallState.INCOMPATIBLE;
[643]625
626 String incompatString = "";
[648]627 for (Package m : incompatibilities.keySet()) {
[643]628 if (incompatString.length() > 0)
629 incompatString += "\n";
630 incompatString += m.getName() + ": ";
631 String confMods = "";
[648]632 for (Package mConf : incompatibilities.get(m)) {
[643]633 if (confMods.length() > 0)
634 confMods += ", ";
635 confMods += mConf.getName();
636 }
637 incompatString += confMods;
638 }
639
640 JOptionPane.showMessageDialog(this, String.format(
641 bundle.getString("installIncompatibilities.text"),
642 incompatString), bundle
643 .getString("installIncompatibilities.title"),
644 JOptionPane.ERROR_MESSAGE);
[605]645 break;
646 } else {
[641]647 installState = EInstallState.READY;
[605]648 }
649 }
[600]650 }
[618]651
[641]652 if (installState == EInstallState.READY) {
[648]653 installMods = new TreeSet<Package>();
654 TreeSet<Package> actuallyTools = new TreeSet<Package>();
[623]655
[648]656 for (Package m : mods) {
[623]657 if (m.isTool())
658 actuallyTools.add(m);
659 else
[641]660 installMods.add(m);
[623]661 }
662
663 if (actuallyTools.size() > 0) {
664 Installer.installTools(actuallyTools);
665 }
[641]666 }
[623]667
[641]668 }
669
670 @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
671 private void installExec(final BackgroundEvent evt) {
672 if (installState == EInstallState.READY) {
673 Installer.install(installMods, new InstallProgressListener() {
[605]674 @Override
675 public void installProgressUpdate(int done, int total,
676 String step) {
677 evt.setProgressEnd(total);
678 evt.setProgressValue(done);
679 evt.setProgressMessage(step);
680 }
681 });
[641]682 installState = EInstallState.DONE;
[605]683 }
[641]684 installMods = null;
[600]685 }
[618]686
[617]687 @SuppressWarnings("unused")
688 private void installDone() {
[648]689 PackageManager.getInstance().updateInstalledMods();
[641]690 switch (installState) {
[621]691 case DONE:
[641]692 revertSelection();
[646]693 if (installDeps.size() > 0
694 && Settings.getInstance().get("notifyDepsAfterInstall",
695 false)) {
696 String installedDeps = "";
[648]697 for (Package m : installDeps) {
[646]698 if (installedDeps.length() > 0)
699 installedDeps += "\n";
700 installedDeps += " - " + m.getName();
701 }
702 JOptionPane.showMessageDialog(this, String.format(
703 bundle.getString("installDoneDeps.text"),
704 installedDeps), bundle
705 .getString("installDone.title"),
706 JOptionPane.INFORMATION_MESSAGE);
707 } else {
708 JOptionPane.showMessageDialog(this,
709 bundle.getString("installDone.text"),
710 bundle.getString("installDone.title"),
711 JOptionPane.INFORMATION_MESSAGE);
712 }
[621]713 break;
714 case OFFLINE:
[657]715 JOptionPane.showMessageDialog(
716 this,
717 SwingJavaBuilder.getConfig().getResource(
718 "offlineMode.text"),
719 SwingJavaBuilder.getConfig().getResource(
720 "offlineMode.title"),
[621]721 JOptionPane.WARNING_MESSAGE);
722 break;
[641]723 default:
[621]724 break;
725 }
[646]726 installDeps = null;
[617]727 }
[600]728
[631]729 @Override
[648]730 public void modSelectionChanged(ModTable source, Package m) {
[658]731 pkgInfo.updateInfo(m);
[591]732 }
733
[630]734 private void updateTableFilter() {
735 Object o = cmbModTypes.getSelectedItem();
736 Type t = null;
737 if (o instanceof Type)
738 t = (Type) o;
739 int downloadState = 0;
740 if (radOnline.isSelected())
741 downloadState = 1;
742 if (radLocal.isSelected())
743 downloadState = 2;
[660]744 tblMods.setFilter(t, downloadState, txtShowFilter.getText(),
745 (EApplyFilterTo) cmbShowFilterTo.getSelectedItem());
[630]746 }
747
[593]748 @Override
[600]749 public void downloadSizeChanged(int newSize) {
750 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
751 }
752
[616]753 @SuppressWarnings("unused")
754 private void checkInitialize() {
[600]755 if (!Installer.isEditionInitialized()) {
[621]756 if (!OniSplit.isOniSplitInstalled()) {
757 JOptionPane.showMessageDialog(this,
758 bundle.getString("noOniSplit.text"),
759 bundle.getString("noOniSplit.title"),
760 JOptionPane.ERROR_MESSAGE);
[600]761 exit();
[621]762 } else {
763 int res = JOptionPane
764 .showConfirmDialog(this,
765 bundle.getString("askInitialize.text"),
766 bundle.getString("askInitialize.title"),
767 JOptionPane.YES_NO_OPTION,
768 JOptionPane.QUESTION_MESSAGE);
769 if (res == JOptionPane.NO_OPTION) {
770 saveLocalData();
771 exit();
772 }
[600]773 }
774 }
775 }
[606]776
[616]777 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
778 private void initialize(final BackgroundEvent evt) {
779 if (!Installer.isEditionInitialized()) {
780 Installer.initializeEdition(new InstallProgressListener() {
781 @Override
782 public void installProgressUpdate(int done, int total,
783 String step) {
784 evt.setProgressEnd(total);
785 evt.setProgressValue(done);
786 evt.setProgressMessage(step);
787 }
788 });
789 }
790 }
791
[605]792 private Vector<String> getBasicOniLaunchParams() {
793 Vector<String> params = new Vector<String>();
[618]794 File exe = null;
[605]795 switch (Settings.getPlatform()) {
796 case WIN:
[618]797 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
798 if (exe.exists())
799 params.add(exe.getPath());
[605]800 break;
801 case MACOS:
[618]802 exe = new File(Paths.getEditionBasePath(),
803 "Oni.app/Contents/MacOS/Oni");
804 if (exe.exists())
805 params.add(exe.getPath());
[605]806 break;
807 case LINUX:
808 String wine = Settings.getWinePath();
[618]809 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
810 if (exe.exists()) {
811 if (wine != null) {
812 params.add(wine);
813 params.add(exe.getPath());
814 }
[605]815 }
816 break;
817 default:
818 }
819 if (params.size() > 0) {
820 params.add("-debugfiles");
821 }
822 return params;
823 }
[600]824
[605]825 @SuppressWarnings("unused")
826 private void oniFull() {
827 Vector<String> params = getBasicOniLaunchParams();
828 if (params.size() > 0) {
[623]829 AppExecution.execute(params, Paths.getEditionBasePath());
[605]830 }
831 }
832
833 @SuppressWarnings("unused")
834 private void oniWin() {
835 Vector<String> params = getBasicOniLaunchParams();
836 if (params.size() > 0) {
837 params.add("-noswitch");
[623]838 AppExecution.execute(params, Paths.getEditionBasePath());
[605]839 }
840 }
841
[608]842 @SuppressWarnings("unused")
843 private void openEditionFolder() {
844 try {
845 Desktop.getDesktop().open(Paths.getEditionBasePath());
[639]846 } catch (Exception e) {
[608]847 e.printStackTrace();
848 }
849 }
850
[600]851 @Override
[593]852 public void handleAbout(ApplicationEvent event) {
853 event.setHandled(true);
854 showAbout();
855 }
856
857 @Override
858 public void handleOpenApplication(ApplicationEvent event) {
859 }
860
861 @Override
862 public void handleOpenFile(ApplicationEvent event) {
863 }
864
865 @Override
866 public void handlePreferences(ApplicationEvent event) {
867 showSettings();
868 }
869
870 @Override
871 public void handlePrintFile(ApplicationEvent event) {
872 }
873
874 @Override
875 public void handleQuit(ApplicationEvent event) {
[605]876 event.setHandled(true);
877 saveLocalData();
878 exit();
[593]879 }
880
881 @Override
882 public void handleReOpenApplication(ApplicationEvent event) {
883 }
[600]884
[592]885}
Note: See TracBrowser for help on using the repository browser.