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

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

AEI2.02:

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