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

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

AEI2.07:

  • Allow for non-ISO-8859-1 characters in properties files (more exactly require them to be UTF8)
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.SizeFormatter;
53import net.oni2.aeinstaller.backend.oni.OniLauncher;
54import net.oni2.aeinstaller.backend.oni.OniSplit;
55import net.oni2.aeinstaller.backend.oni.management.Initializer;
56import net.oni2.aeinstaller.backend.oni.management.InstallProgressListener;
57import net.oni2.aeinstaller.backend.oni.management.Installer;
58import net.oni2.aeinstaller.backend.oni.management.tools.ToolInstallationList;
59import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
60import net.oni2.aeinstaller.backend.packages.Package;
61import net.oni2.aeinstaller.backend.packages.PackageManager;
62import net.oni2.aeinstaller.backend.packages.Type;
63import net.oni2.aeinstaller.gui.about.AboutDialog;
64import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
65import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
66import net.oni2.aeinstaller.gui.modtable.EApplyFilterTo;
67import net.oni2.aeinstaller.gui.modtable.ModInstallSelectionListener;
68import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
69import net.oni2.aeinstaller.gui.modtable.ModTable;
70import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
71import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
72import net.oni2.aeinstaller.gui.settings.SettingsDialog;
73import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
74import net.oni2.moddepot.DepotManager;
75import net.oni2.platformtools.PlatformInformation;
76import net.oni2.platformtools.PlatformInformation.Platform;
77import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
78import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException;
79import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
80
81import org.javabuilders.BuildResult;
82import org.javabuilders.annotations.DoInBackground;
83import org.javabuilders.event.BackgroundEvent;
84import org.javabuilders.swing.SwingJavaBuilder;
85import org.simplericity.macify.eawt.ApplicationEvent;
86import org.simplericity.macify.eawt.ApplicationListener;
87
88/**
89 * @author Christian Illy
90 */
91public class MainWin extends JFrame implements ApplicationListener,
92 ModInstallSelectionListener, ModSelectionListener {
93 private static final long serialVersionUID = -4027395051382659650L;
94
95 private ResourceBundle bundle = UTF8ResourceBundleLoader
96 .getBundle("net.oni2.aeinstaller.localization."
97 + getClass().getSimpleName());
98 @SuppressWarnings("unused")
99 private BuildResult result = SwingJavaBuilder.build(this, bundle);
100
101 private JMenu mainMenu;
102 private JMenu toolsMenu;
103 private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
104
105 private JSplitPane contents;
106
107 private JComboBox cmbModTypes;
108 private JRadioButton radAll;
109 private JRadioButton radOnline;
110 private JRadioButton radLocal;
111 private JRadioButton radInstalled;
112 private JButton btnShowHelp;
113 private JTextField txtShowFilter;
114 private JComboBox cmbShowFilterTo;
115 private JScrollPane scrollMods;
116 private ModTable tblMods;
117 private JLabel lblSelectedModsVal;
118 private JLabel lblDownloadSizeVal;
119
120 private PackageInfoBox pkgInfo;
121
122 private JButton btnInstall;
123
124 private TreeSet<Package> execCoreUpdates = new TreeSet<Package>();
125 private TreeSet<Package> execUpdates = null;
126
127 private enum EInstallState {
128 DONE,
129 READY,
130 ABORTED,
131 OFFLINE,
132 INCOMPATIBLE,
133 CHECKING
134 };
135
136 private EInstallState installState = EInstallState.DONE;
137 private TreeSet<Package> installMods = null;
138 private TreeSet<Package> installDeps = null;
139
140 /**
141 * Constructor of main window.
142 */
143 public MainWin() {
144 this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
145 + SwingJavaBuilder.getConfig().getResource("appversion"));
146
147 tblMods = new ModTable(ETableContentType.MODS);
148 tblMods.setVisible(false);
149 scrollMods.setViewportView(tblMods);
150
151 contents.setDividerLocation(SettingsManager.getInstance().get(
152 "win_main_divloc", 700));
153 contents.setResizeWeight(0.4);
154
155 if (PlatformInformation.getPlatform() == Platform.MACOS) {
156 mainMenu.setVisible(false);
157 } else {
158 btnShowHelp.setVisible(false);
159 }
160
161 ToolTipManager.sharedInstance().setInitialDelay(250);
162
163 getRootPane().setDefaultButton(btnInstall);
164 lblSelectedModsVal.setText("0");
165 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
166 radAll.setSelected(true);
167
168 for (EApplyFilterTo f : EApplyFilterTo.values()) {
169 cmbShowFilterTo.addItem(f);
170 }
171 txtShowFilter.addKeyListener(new KeyAdapter() {
172 @Override
173 public void keyReleased(KeyEvent e) {
174 super.keyReleased(e);
175 updateTableFilter();
176 }
177 });
178
179 tblMods.addModSelectionListener(this);
180 tblMods.addDownloadSizeListener(this);
181
182 setSize(SettingsManager.getInstance().get("win_main_width", 1050),
183 SettingsManager.getInstance().get("win_main_height", 600));
184 setLocationRelativeTo(null);
185 }
186
187 private void initModTypeBox() {
188 cmbModTypes.removeAllItems();
189
190 TreeMap<String, Type> types = new TreeMap<String, Type>();
191 for (Type t : PackageManager.getInstance().getTypesWithContent()) {
192 types.put(t.getName(), t);
193 }
194 cmbModTypes.addItem("-All-");
195 for (Type t : types.values()) {
196 cmbModTypes.addItem(t);
197 }
198 cmbModTypes.setSelectedIndex(0);
199 }
200
201 private void exit() {
202 dispose();
203 System.exit(0);
204 }
205
206 private void saveLocalData() {
207 SettingsManager.getInstance().put("win_main_divloc",
208 contents.getDividerLocation());
209 SettingsManager.getInstance().put("win_main_width", getWidth());
210 SettingsManager.getInstance().put("win_main_height", getHeight());
211 SettingsManager.getInstance().serializeToFile(
212 Paths.getSettingsFilename());
213 }
214
215 @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
216 private void execDepotUpdate(final BackgroundEvent evt) {
217 DepotManager.loadFromCacheFile(Paths.getDepotCacheFilename());
218
219 if (!SettingsManager.getInstance().isOfflineMode()
220 && !SettingsManager.getInstance().isNoCacheUpdateMode()) {
221 long start = new Date().getTime();
222
223 if (DepotManager.getInstance().updateInformation())
224 DepotManager.getInstance().saveToCacheFile(
225 Paths.getDepotCacheFilename());
226
227 System.out.println("Took: " + (new Date().getTime() - start)
228 + " msec");
229 }
230
231 PackageManager.getInstance().init();
232 tblMods.reloadData();
233 initModTypeBox();
234
235 tblMods.setVisible(true);
236 }
237
238 @SuppressWarnings("unused")
239 private void checkUpdates(Object evtSource) {
240 if ((evtSource != this)
241 || SettingsManager.getInstance().get("notifyupdates", true)) {
242 if (SettingsManager.getInstance().isOfflineMode()) {
243 if (evtSource != this) {
244 JOptionPane.showMessageDialog(
245 this,
246 SwingJavaBuilder.getConfig().getResource(
247 "offlineMode.text"),
248 SwingJavaBuilder.getConfig().getResource(
249 "offlineMode.title"),
250 JOptionPane.WARNING_MESSAGE);
251 }
252 } else {
253 TreeSet<Package> mods = PackageManager.getInstance()
254 .getUpdatableMods();
255 TreeSet<Package> tools = PackageManager.getInstance()
256 .getUpdatableTools();
257 JPanel panPackages = new JPanel(new GridLayout(0, 1));
258 execUpdates = new TreeSet<Package>();
259 execUpdates.addAll(mods);
260 execUpdates.addAll(tools);
261 final JLabel lblSize = new JLabel("<html>"
262 + String.format(
263 bundle.getString("updatesAvailableSize.text"),
264 SizeFormatter.format(0, 3)) + "</html>");
265 int size = 0;
266 for (final Package m : mods) {
267 size += m.getZipSize();
268 JCheckBox check = new JCheckBox("Mod: " + m.getName()
269 + " (" + SizeFormatter.format(m.getZipSize(), 1)
270 + ")");
271 check.setSelected(true);
272 check.addItemListener(new ItemListener() {
273 @Override
274 public void itemStateChanged(ItemEvent e) {
275 if (e.getStateChange() == ItemEvent.SELECTED)
276 execUpdates.add(m);
277 else
278 execUpdates.remove(m);
279 int s = 0;
280 for (Package p : execUpdates)
281 s += p.getZipSize();
282 lblSize.setText("<html>"
283 + String.format(
284 bundle.getString("updatesAvailableSize.text"),
285 SizeFormatter.format(s, 3))
286 + "</html>");
287 }
288 });
289 panPackages.add(check);
290 }
291 for (final Package m : tools) {
292 size += m.getZipSize();
293 JCheckBox check = new JCheckBox("Tool: " + m.getName()
294 + " (" + SizeFormatter.format(m.getZipSize(), 1)
295 + ")");
296 check.setSelected(true);
297 check.addItemListener(new ItemListener() {
298 @Override
299 public void itemStateChanged(ItemEvent e) {
300 if (e.getStateChange() == ItemEvent.SELECTED)
301 execUpdates.add(m);
302 else
303 execUpdates.remove(m);
304 int s = 0;
305 for (Package p : execUpdates)
306 s += p.getZipSize();
307 lblSize.setText("<html>"
308 + String.format(
309 bundle.getString("updatesAvailableSize.text"),
310 SizeFormatter.format(s, 3))
311 + "</html>");
312 }
313 });
314 panPackages.add(check);
315 }
316 lblSize.setText("<html>"
317 + String.format(
318 bundle.getString("updatesAvailableSize.text"),
319 SizeFormatter.format(size, 3)) + "</html>");
320 if (size > 0) {
321 // Build info dialog content
322 JPanel packages = new JPanel(new BorderLayout(0, 7));
323 JLabel lblIntro = new JLabel("<html>"
324 + bundle.getString("updatesAvailable.text")
325 + "</html>");
326 packages.add(lblIntro, BorderLayout.NORTH);
327 packages.add(panPackages, BorderLayout.CENTER);
328 packages.add(lblSize, BorderLayout.SOUTH);
329
330 JPanel pan = new JPanel(new BorderLayout(0, 25));
331 pan.add(packages, BorderLayout.CENTER);
332 JCheckBox checkFutureUpdates = new JCheckBox(
333 bundle.getString("checkOnStartup.text"));
334 checkFutureUpdates.setSelected(SettingsManager
335 .getInstance().get("notifyupdates", true));
336 checkFutureUpdates.addItemListener(new ItemListener() {
337 @Override
338 public void itemStateChanged(ItemEvent evt) {
339 SettingsManager.getInstance().put("notifyupdates",
340 evt.getStateChange() == ItemEvent.SELECTED);
341 }
342 });
343 pan.add(checkFutureUpdates, BorderLayout.SOUTH);
344
345 // Show dialog
346 int res = JOptionPane.showConfirmDialog(this, pan,
347 bundle.getString("updatesAvailable.title"),
348 JOptionPane.YES_NO_OPTION,
349 JOptionPane.QUESTION_MESSAGE);
350 if (res == JOptionPane.NO_OPTION) {
351 execUpdates = null;
352 }
353 } else {
354 if (evtSource != this) {
355 JOptionPane.showMessageDialog(this,
356 bundle.getString("updatesNotAvailable.text"),
357 bundle.getString("updatesNotAvailable.title"),
358 JOptionPane.INFORMATION_MESSAGE);
359 }
360 }
361 }
362 }
363 }
364
365 @SuppressWarnings("unused")
366 private void doUpdate() {
367 if (execUpdates != null && execUpdates.size() > 0) {
368 Downloader dl = new Downloader(execUpdates, null, false);
369 try {
370 dl.setVisible(true);
371 if (dl.isFinished()) {
372 ToolInstallationList til = ToolInstallationList
373 .getInstance();
374 TreeSet<Package> tools = new TreeSet<Package>();
375 for (Package m : execUpdates)
376 if (m.isTool() && til.isInstalled(m.getPackageNumber()))
377 tools.add(m);
378 if (tools.size() > 0) {
379 ToolsManager.installTools(tools, true);
380 ToolsManager.installTools(tools, false);
381 }
382 }
383 } finally {
384 dl.dispose();
385 }
386 }
387 execUpdates = null;
388 }
389
390 @SuppressWarnings("unused")
391 private void focus() {
392 SwingUtilities.invokeLater(new Runnable() {
393
394 @Override
395 public void run() {
396 toFront();
397 repaint();
398 }
399 });
400
401 }
402
403 @SuppressWarnings("unused")
404 private void showCorePackagesDialog() {
405 new CorePackagesDialog().setVisible(true);
406 }
407
408 private void showSettings() {
409 new SettingsDialog().setVisible(true);
410 }
411
412 private void showAbout() {
413 new AboutDialog().setVisible(true);
414 }
415
416 @SuppressWarnings("unused")
417 private void showHelp() {
418 try {
419 Desktop.getDesktop().browse(new URI("http://wiki.oni2.net/AEI"));
420 } catch (IOException e) {
421 e.printStackTrace();
422 } catch (URISyntaxException e) {
423 e.printStackTrace();
424 }
425 }
426
427 private JFileChooser getConfigOpenSaveDialog(boolean save) {
428 JFileChooser fc = new JFileChooser();
429 fc.setCurrentDirectory(Paths.getEditionBasePath());
430 if (save)
431 fc.setDialogType(JFileChooser.SAVE_DIALOG);
432 else
433 fc.setDialogType(JFileChooser.OPEN_DIALOG);
434 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
435 fc.setFileFilter(new FileFilter() {
436 @Override
437 public String getDescription() {
438 return "XML files";
439 }
440
441 @Override
442 public boolean accept(File arg0) {
443 return (arg0.isDirectory())
444 || (arg0.getName().toLowerCase().endsWith(".xml"));
445 }
446 });
447 fc.setMultiSelectionEnabled(false);
448 return fc;
449 }
450
451 @SuppressWarnings("unused")
452 private void loadConfig() {
453 JFileChooser fc = getConfigOpenSaveDialog(false);
454 int res = fc.showOpenDialog(this);
455 if (res == JFileChooser.APPROVE_OPTION) {
456 if (fc.getSelectedFile().exists())
457 tblMods.reloadSelection(fc.getSelectedFile());
458 }
459 }
460
461 @SuppressWarnings("unused")
462 private void saveConfig() {
463 JFileChooser fc = getConfigOpenSaveDialog(true);
464 int res = fc.showSaveDialog(this);
465 if (res == JFileChooser.APPROVE_OPTION) {
466 File f = fc.getSelectedFile();
467 if (!f.getName().endsWith(".xml"))
468 f = new File(f.getParentFile(), f.getName() + ".xml");
469 PackageManager.getInstance().saveModSelection(f,
470 tblMods.getSelectedMods());
471 }
472 }
473
474 @SuppressWarnings("unused")
475 private void copyConfig() {
476 StringBuffer b = new StringBuffer();
477 b.append("[code]");
478 for (Package p : PackageManager.getInstance().getInstalledMods())
479 b.append(String.format("%s %s%n", p.getPackageNumberString(),
480 p.getName()));
481 b.append("[/code]");
482
483 StringSelection selection = new StringSelection(b.toString());
484 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
485 clipboard.setContents(selection, selection);
486 }
487
488 @SuppressWarnings("unused")
489 private boolean reglobalizeVerify() {
490 int res = JOptionPane.showConfirmDialog(this,
491 bundle.getString("rebuildCore.text"),
492 bundle.getString("rebuildCore.title"),
493 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
494 return res == JOptionPane.YES_OPTION;
495 }
496
497 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
498 private void reglobalize(final BackgroundEvent evt) {
499 Initializer.initializeEdition(new InstallProgressListener() {
500 @Override
501 public void installProgressUpdate(int done, int total, String step) {
502 evt.setProgressEnd(total);
503 evt.setProgressValue(done);
504 evt.setProgressMessage(step);
505 }
506 });
507 }
508
509 @SuppressWarnings("unused")
510 private void tools() {
511 new ToolManager().setVisible(true);
512 }
513
514 @SuppressWarnings("unused")
515 private void refreshToolsMenu() {
516 for (JMenuItem i : toolsMenuItems) {
517 toolsMenu.remove(i);
518 }
519 toolsMenuItems.clear();
520 for (final Package m : PackageManager.getInstance().getInstalledTools()) {
521 File exe = m.getExeFile();
522 if (exe != null && exe.exists()) {
523 JMenuItem item = new JMenuItem();
524 ImageIcon ico = null;
525 if (m.getIconFile() != null && m.getIconFile().exists()) {
526 ico = new ImageIcon(m.getIconFile().getPath());
527 } else {
528 URL icon = AEInstaller2.class
529 .getResource("images/transparent.png");
530 ico = new ImageIcon(icon);
531 }
532 ico = ImageResizer.resizeImage(ico, 32, 32);
533 item.setAction(new AbstractAction(m.getName(), ico) {
534 private static final long serialVersionUID = 1L;
535
536 @Override
537 public void actionPerformed(ActionEvent evt) {
538 try {
539 ApplicationInvoker.execute(m.getExeType(),
540 m.getWorkingDir(), m.getExeFile(), null,
541 false);
542 } catch (ERuntimeNotInstalledException e) {
543 JOptionPane.showMessageDialog(null,
544 bundle.getString("exeNotFound.text"),
545 bundle.getString("exeNotFound.title"),
546 JOptionPane.ERROR_MESSAGE);
547 e.printStackTrace();
548 } catch (FileNotFoundException e) {
549 if (e.getMessage().contains("JRE"))
550 JOptionPane.showMessageDialog(null,
551 bundle.getString("jreNotFound.text"),
552 bundle.getString("jreNotFound.title"),
553 JOptionPane.ERROR_MESSAGE);
554 if (e.getMessage().contains(".NET"))
555 JOptionPane.showMessageDialog(
556 null,
557 bundle.getString("dotNetNotFound.text"),
558 bundle.getString("dotNetNotFound.title"),
559 JOptionPane.ERROR_MESSAGE);
560 if (e.getMessage().contains("Wine"))
561 JOptionPane.showMessageDialog(null,
562 bundle.getString("wineNotFound.text"),
563 bundle.getString("wineNotFound.title"),
564 JOptionPane.ERROR_MESSAGE);
565 e.printStackTrace();
566 }
567 }
568 });
569 toolsMenuItems.add(item);
570 toolsMenu.add(item);
571 }
572 }
573 }
574
575 private void revertSelection() {
576 tblMods.revertSelection();
577 }
578
579 @SuppressWarnings("unused")
580 private void unSelectAll() {
581 tblMods.unSelectAll();
582 }
583
584 @SuppressWarnings("unused")
585 private void checkCorePackages() {
586 if (!SettingsManager.getInstance().isOfflineMode()) {
587 TreeSet<Package> tools = new TreeSet<Package>();
588 for (Package m : PackageManager.getInstance().getCoreTools()) {
589 if (m.isNewerAvailable()) {
590 execCoreUpdates.add(m);
591 tools.add(m);
592 } else if (!m.isInstalled())
593 tools.add(m);
594 }
595 for (Package m : PackageManager.getInstance().getCoreMods()) {
596 if (m.isNewerAvailable()) {
597 execCoreUpdates.add(m);
598 }
599 }
600 if (execCoreUpdates.size() > 0) {
601 Downloader dl = new Downloader(execCoreUpdates, null, true);
602 try {
603 dl.setVisible(true);
604 } finally {
605 dl.dispose();
606 }
607 }
608
609 ToolsManager.installTools(tools, true);
610 ToolsManager.installTools(tools, false);
611 }
612 ToolsManager.verifyToolsIntegrity();
613 if (ToolInstallationList.getInstance().getModifiedTools().size() > 0)
614 System.out.println("Locally modified tools: "
615 + ToolInstallationList.getInstance().getModifiedTools()
616 .toString());
617 }
618
619 @SuppressWarnings("unused")
620 private void infoCorePackages() {
621 if (execCoreUpdates.size() > 0) {
622 String packages = "";
623 for (Package m : execCoreUpdates) {
624 packages += String.format("\n - %s (%s)", m.getName(),
625 m.getVersion());
626 }
627 JOptionPane.showMessageDialog(this, String.format(
628 bundle.getString("corePackagesUpdated.text"), packages),
629 bundle.getString("corePackagesUpdated.title"),
630 JOptionPane.INFORMATION_MESSAGE);
631 }
632 }
633
634 @SuppressWarnings("unused")
635 private void install() {
636 TreeSet<Package> mods = new TreeSet<Package>();
637 mods.addAll(PackageManager.getInstance().getCoreMods());
638 mods.addAll(tblMods.getSelectedMods());
639
640 installDeps = new TreeSet<Package>();
641
642 installState = EInstallState.CHECKING;
643
644 while (installState == EInstallState.CHECKING) {
645 TreeSet<Package> toDownload = new TreeSet<Package>();
646 for (Package m : mods) {
647 if (!m.isLocalAvailable())
648 toDownload.add(m);
649 }
650
651 if (toDownload.size() > 0
652 && SettingsManager.getInstance().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.