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

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

AEI2.02:

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