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

Last change on this file since 864 was 863, checked in by alloc, 12 years ago

AEI2.12:

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