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

Last change on this file since 1156 was 1090, checked in by alloc, 7 years ago

AEI 2.30: Better conflicts display

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