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

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

AEI2.02:

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