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

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

AEI2 0.99r:

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