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

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

AEI2.02:

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