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

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

AEI2 0.99q:

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