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

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

AEI2: Refactorings for breaking out independent features into libraries

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