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

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

AEI2.08, AEIUpdater:

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