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

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

AEI2.07:

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