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

Last change on this file since 1002 was 892, checked in by alloc, 11 years ago

AEI2.16:

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