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

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

AEI2 0.99x:

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