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

Last change on this file since 887 was 886, checked in by alloc, 11 years ago

AEI2.16:

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