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
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;
[852]52import net.oni2.aeinstaller.backend.RuntimeOptions;
[600]53import net.oni2.aeinstaller.backend.SizeFormatter;
[720]54import net.oni2.aeinstaller.backend.oni.OniLauncher;
[658]55import net.oni2.aeinstaller.backend.oni.OniSplit;
[749]56import net.oni2.aeinstaller.backend.oni.management.Initializer;
57import net.oni2.aeinstaller.backend.oni.management.InstallProgressListener;
58import net.oni2.aeinstaller.backend.oni.management.Installer;
[804]59import net.oni2.aeinstaller.backend.oni.management.tools.ToolInstallationList;
60import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
[648]61import net.oni2.aeinstaller.backend.packages.Package;
62import net.oni2.aeinstaller.backend.packages.PackageManager;
63import net.oni2.aeinstaller.backend.packages.Type;
[593]64import net.oni2.aeinstaller.gui.about.AboutDialog;
[648]65import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
[605]66import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
[720]67import net.oni2.aeinstaller.gui.modtable.EApplyFilterTo;
[673]68import net.oni2.aeinstaller.gui.modtable.ModInstallSelectionListener;
[631]69import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
70import net.oni2.aeinstaller.gui.modtable.ModTable;
[658]71import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
72import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
[591]73import net.oni2.aeinstaller.gui.settings.SettingsDialog;
[625]74import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
[749]75import net.oni2.moddepot.DepotManager;
[720]76import net.oni2.platformtools.PlatformInformation;
77import net.oni2.platformtools.PlatformInformation.Platform;
78import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
79import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException;
[840]80import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
[591]81
82import org.javabuilders.BuildResult;
83import org.javabuilders.annotations.DoInBackground;
84import org.javabuilders.event.BackgroundEvent;
85import org.javabuilders.swing.SwingJavaBuilder;
[593]86import org.simplericity.macify.eawt.ApplicationEvent;
87import org.simplericity.macify.eawt.ApplicationListener;
[591]88
89/**
90 * @author Christian Illy
91 */
[600]92public class MainWin extends JFrame implements ApplicationListener,
[673]93 ModInstallSelectionListener, ModSelectionListener {
[591]94 private static final long serialVersionUID = -4027395051382659650L;
95
[840]96 private ResourceBundle bundle = UTF8ResourceBundleLoader
[629]97 .getBundle("net.oni2.aeinstaller.localization."
98 + getClass().getSimpleName());
[591]99 @SuppressWarnings("unused")
100 private BuildResult result = SwingJavaBuilder.build(this, bundle);
101
[593]102 private JMenu mainMenu;
[623]103 private JMenu toolsMenu;
[641]104 private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
[593]105
[592]106 private JSplitPane contents;
107
[591]108 private JComboBox cmbModTypes;
[630]109 private JRadioButton radAll;
110 private JRadioButton radOnline;
111 private JRadioButton radLocal;
[805]112 private JRadioButton radInstalled;
[817]113 private JButton btnShowHelp;
[660]114 private JTextField txtShowFilter;
115 private JComboBox cmbShowFilterTo;
[658]116 private JScrollPane scrollMods;
[631]117 private ModTable tblMods;
[673]118 private JLabel lblSelectedModsVal;
[600]119 private JLabel lblDownloadSizeVal;
[591]120
[658]121 private PackageInfoBox pkgInfo;
[660]122
[600]123 private JButton btnInstall;
124
[648]125 private TreeSet<Package> execCoreUpdates = new TreeSet<Package>();
126 private TreeSet<Package> execUpdates = null;
[621]127
[641]128 private enum EInstallState {
[621]129 DONE,
[641]130 READY,
131 ABORTED,
[621]132 OFFLINE,
[641]133 INCOMPATIBLE,
134 CHECKING
[621]135 };
136
[641]137 private EInstallState installState = EInstallState.DONE;
[648]138 private TreeSet<Package> installMods = null;
139 private TreeSet<Package> installDeps = null;
[621]140
[591]141 /**
142 * Constructor of main window.
143 */
144 public MainWin() {
[593]145 this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
146 + SwingJavaBuilder.getConfig().getResource("appversion"));
[591]147
[658]148 tblMods = new ModTable(ETableContentType.MODS);
149 tblMods.setVisible(false);
150 scrollMods.setViewportView(tblMods);
151
[720]152 contents.setDividerLocation(SettingsManager.getInstance().get(
[772]153 "win_main_divloc", 700));
[631]154 contents.setResizeWeight(0.4);
[593]155
[720]156 if (PlatformInformation.getPlatform() == Platform.MACOS) {
[593]157 mainMenu.setVisible(false);
[817]158 } else {
159 btnShowHelp.setVisible(false);
[593]160 }
[600]161
[631]162 ToolTipManager.sharedInstance().setInitialDelay(250);
163
[600]164 getRootPane().setDefaultButton(btnInstall);
[673]165 lblSelectedModsVal.setText("0");
[605]166 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
[630]167 radAll.setSelected(true);
[631]168
[660]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
[631]180 tblMods.addModSelectionListener(this);
181 tblMods.addDownloadSizeListener(this);
[720]182
[772]183 setSize(SettingsManager.getInstance().get("win_main_width", 1050),
[720]184 SettingsManager.getInstance().get("win_main_height", 600));
[701]185 setLocationRelativeTo(null);
[591]186 }
187
188 private void initModTypeBox() {
[592]189 cmbModTypes.removeAllItems();
190
[600]191 TreeMap<String, Type> types = new TreeMap<String, Type>();
[648]192 for (Type t : PackageManager.getInstance().getTypesWithContent()) {
[600]193 types.put(t.getName(), t);
[591]194 }
[630]195 cmbModTypes.addItem("-All-");
[600]196 for (Type t : types.values()) {
[591]197 cmbModTypes.addItem(t);
198 }
199 cmbModTypes.setSelectedIndex(0);
200 }
201
202 private void exit() {
203 dispose();
[608]204 System.exit(0);
[591]205 }
206
207 private void saveLocalData() {
[720]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());
[591]214 }
215
216 @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
217 private void execDepotUpdate(final BackgroundEvent evt) {
[857]218 boolean hasUpdated = false;
[852]219 if (!RuntimeOptions.isOfflineMode()
220 && !RuntimeOptions.isNoCacheUpdateMode()) {
[634]221 long start = new Date().getTime();
[858]222 hasUpdated = DepotManager.getInstance().updateInformation();
[634]223 System.out.println("Took: " + (new Date().getTime() - start)
224 + " msec");
[621]225 }
[633]226
[860]227 PackageManager.loadFromCacheFile(Paths.getPacManCacheFilename());
228
[857]229 if (hasUpdated || !Paths.getPacManCacheFilename().exists()) {
230 PackageManager.getInstance().init();
231 PackageManager.getInstance().saveToCacheFile(
232 Paths.getPacManCacheFilename());
[860]233 }
[631]234 tblMods.reloadData();
[621]235 initModTypeBox();
[600]236
[621]237 tblMods.setVisible(true);
238 }
239
240 @SuppressWarnings("unused")
241 private void checkUpdates(Object evtSource) {
242 if ((evtSource != this)
[720]243 || SettingsManager.getInstance().get("notifyupdates", true)) {
[852]244 if (RuntimeOptions.isOfflineMode()) {
[621]245 if (evtSource != this) {
[657]246 JOptionPane.showMessageDialog(
247 this,
248 SwingJavaBuilder.getConfig().getResource(
249 "offlineMode.text"),
250 SwingJavaBuilder.getConfig().getResource(
251 "offlineMode.title"),
[621]252 JOptionPane.WARNING_MESSAGE);
253 }
254 } else {
[657]255 TreeSet<Package> mods = PackageManager.getInstance()
256 .getUpdatableMods();
[648]257 TreeSet<Package> tools = PackageManager.getInstance()
[621]258 .getUpdatableTools();
[632]259 JPanel panPackages = new JPanel(new GridLayout(0, 1));
[648]260 execUpdates = new TreeSet<Package>();
[632]261 execUpdates.addAll(mods);
262 execUpdates.addAll(tools);
[672]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;
[648]268 for (final Package m : mods) {
[621]269 size += m.getZipSize();
[672]270 JCheckBox check = new JCheckBox("Mod: " + m.getName()
[720]271 + " (" + SizeFormatter.format(m.getZipSize(), 1)
272 + ")");
[632]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);
[672]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>");
[632]289 }
290 });
291 panPackages.add(check);
[621]292 }
[648]293 for (final Package m : tools) {
[621]294 size += m.getZipSize();
[672]295 JCheckBox check = new JCheckBox("Tool: " + m.getName()
[720]296 + " (" + SizeFormatter.format(m.getZipSize(), 1)
297 + ")");
[632]298 check.setSelected(true);
[672]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 });
[632]316 panPackages.add(check);
[621]317 }
[672]318 lblSize.setText("<html>"
319 + String.format(
320 bundle.getString("updatesAvailableSize.text"),
321 SizeFormatter.format(size, 3)) + "</html>");
[622]322 if (size > 0) {
[627]323 // Build info dialog content
[632]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);
[627]331
[632]332 JPanel pan = new JPanel(new BorderLayout(0, 25));
333 pan.add(packages, BorderLayout.CENTER);
[627]334 JCheckBox checkFutureUpdates = new JCheckBox(
335 bundle.getString("checkOnStartup.text"));
[720]336 checkFutureUpdates.setSelected(SettingsManager
337 .getInstance().get("notifyupdates", true));
[627]338 checkFutureUpdates.addItemListener(new ItemListener() {
339 @Override
340 public void itemStateChanged(ItemEvent evt) {
[720]341 SettingsManager.getInstance().put("notifyupdates",
[627]342 evt.getStateChange() == ItemEvent.SELECTED);
343 }
344 });
345 pan.add(checkFutureUpdates, BorderLayout.SOUTH);
346
347 // Show dialog
348 int res = JOptionPane.showConfirmDialog(this, pan,
[622]349 bundle.getString("updatesAvailable.title"),
350 JOptionPane.YES_NO_OPTION,
351 JOptionPane.QUESTION_MESSAGE);
[632]352 if (res == JOptionPane.NO_OPTION) {
353 execUpdates = null;
[622]354 }
[656]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 }
[621]362 }
363 }
[591]364 }
365 }
366
[624]367 @SuppressWarnings("unused")
368 private void doUpdate() {
[632]369 if (execUpdates != null && execUpdates.size() > 0) {
[773]370 Downloader dl = new Downloader(execUpdates, null, false);
[624]371 try {
372 dl.setVisible(true);
373 if (dl.isFinished()) {
[804]374 ToolInstallationList til = ToolInstallationList
375 .getInstance();
[648]376 TreeSet<Package> tools = new TreeSet<Package>();
377 for (Package m : execUpdates)
[804]378 if (m.isTool() && til.isInstalled(m.getPackageNumber()))
[624]379 tools.add(m);
380 if (tools.size() > 0) {
[804]381 ToolsManager.installTools(tools, true);
[749]382 ToolsManager.installTools(tools, false);
[624]383 }
384 }
385 } finally {
386 dl.dispose();
387 }
[591]388 }
[621]389 execUpdates = null;
[591]390 }
391
392 @SuppressWarnings("unused")
[860]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")
[591]456 private void focus() {
457 SwingUtilities.invokeLater(new Runnable() {
458
459 @Override
460 public void run() {
461 toFront();
462 repaint();
463 }
464 });
465
466 }
[646]467
[645]468 @SuppressWarnings("unused")
[648]469 private void showCorePackagesDialog() {
470 new CorePackagesDialog().setVisible(true);
[645]471 }
[591]472
473 private void showSettings() {
[593]474 new SettingsDialog().setVisible(true);
[591]475 }
476
[593]477 private void showAbout() {
478 new AboutDialog().setVisible(true);
479 }
[807]480
[806]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 }
[593]491
[604]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
[593]516 @SuppressWarnings("unused")
517 private void loadConfig() {
[604]518 JFileChooser fc = getConfigOpenSaveDialog(false);
519 int res = fc.showOpenDialog(this);
520 if (res == JFileChooser.APPROVE_OPTION) {
521 if (fc.getSelectedFile().exists())
[631]522 tblMods.reloadSelection(fc.getSelectedFile());
[604]523 }
[593]524 }
525
526 @SuppressWarnings("unused")
527 private void saveConfig() {
[604]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");
[648]534 PackageManager.getInstance().saveModSelection(f,
[631]535 tblMods.getSelectedMods());
[604]536 }
[593]537 }
538
[661]539 @SuppressWarnings("unused")
[807]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]");
[810]547
[807]548 StringSelection selection = new StringSelection(b.toString());
[810]549 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
550 clipboard.setContents(selection, selection);
[807]551 }
552
553 @SuppressWarnings("unused")
[661]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
[600]562 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
563 private void reglobalize(final BackgroundEvent evt) {
[749]564 Initializer.initializeEdition(new InstallProgressListener() {
[600]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 }
[860]573
[859]574 @SuppressWarnings("unused")
575 private void refreshLocalMods() {
576 PackageManager.getInstance().updateLocalData();
[863]577 tblMods.reloadData();
578 initModTypeBox();
[859]579 }
[600]580
[593]581 @SuppressWarnings("unused")
[600]582 private void tools() {
[625]583 new ToolManager().setVisible(true);
[593]584 }
[596]585
[593]586 @SuppressWarnings("unused")
[623]587 private void refreshToolsMenu() {
588 for (JMenuItem i : toolsMenuItems) {
589 toolsMenu.remove(i);
590 }
591 toolsMenuItems.clear();
[672]592 for (final Package m : PackageManager.getInstance().getInstalledTools()) {
[640]593 File exe = m.getExeFile();
594 if (exe != null && exe.exists()) {
[623]595 JMenuItem item = new JMenuItem();
[671]596 ImageIcon ico = null;
[623]597 if (m.getIconFile() != null && m.getIconFile().exists()) {
598 ico = new ImageIcon(m.getIconFile().getPath());
599 } else {
[624]600 URL icon = AEInstaller2.class
601 .getResource("images/transparent.png");
[623]602 ico = new ImageIcon(icon);
603 }
[671]604 ico = ImageResizer.resizeImage(ico, 32, 32);
[623]605 item.setAction(new AbstractAction(m.getName(), ico) {
606 private static final long serialVersionUID = 1L;
607
608 @Override
[672]609 public void actionPerformed(ActionEvent evt) {
610 try {
[720]611 ApplicationInvoker.execute(m.getExeType(),
[773]612 m.getWorkingDir(), m.getExeFile(), null,
613 false);
[720]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"))
[672]622 JOptionPane.showMessageDialog(null,
623 bundle.getString("jreNotFound.text"),
624 bundle.getString("jreNotFound.title"),
625 JOptionPane.ERROR_MESSAGE);
[720]626 if (e.getMessage().contains(".NET"))
[673]627 JOptionPane.showMessageDialog(
628 null,
[672]629 bundle.getString("dotNetNotFound.text"),
630 bundle.getString("dotNetNotFound.title"),
631 JOptionPane.ERROR_MESSAGE);
[720]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();
[672]638 }
[623]639 }
640 });
641 toolsMenuItems.add(item);
642 toolsMenu.add(item);
643 }
644 }
645 }
646
[593]647 private void revertSelection() {
[631]648 tblMods.revertSelection();
[593]649 }
[658]650
[657]651 @SuppressWarnings("unused")
652 private void unSelectAll() {
653 tblMods.unSelectAll();
654 }
[593]655
[773]656 @SuppressWarnings("unused")
657 private void checkCorePackages() {
[852]658 if (!RuntimeOptions.isOfflineMode()) {
[804]659 TreeSet<Package> tools = new TreeSet<Package>();
[648]660 for (Package m : PackageManager.getInstance().getCoreTools()) {
[621]661 if (m.isNewerAvailable()) {
[648]662 execCoreUpdates.add(m);
[804]663 tools.add(m);
[840]664 } else if (!m.isInstalled())
665 tools.add(m);
[604]666 }
[648]667 for (Package m : PackageManager.getInstance().getCoreMods()) {
[621]668 if (m.isNewerAvailable()) {
[648]669 execCoreUpdates.add(m);
[621]670 }
[604]671 }
[648]672 if (execCoreUpdates.size() > 0) {
[773]673 Downloader dl = new Downloader(execCoreUpdates, null, true);
674 try {
675 dl.setVisible(true);
676 } finally {
677 dl.dispose();
[604]678 }
679 }
[804]680
681 ToolsManager.installTools(tools, true);
682 ToolsManager.installTools(tools, false);
[604]683 }
[804]684 ToolsManager.verifyToolsIntegrity();
685 if (ToolInstallationList.getInstance().getModifiedTools().size() > 0)
686 System.out.println("Locally modified tools: "
687 + ToolInstallationList.getInstance().getModifiedTools()
688 .toString());
[602]689 }
690
[641]691 @SuppressWarnings("unused")
[648]692 private void infoCorePackages() {
693 if (execCoreUpdates.size() > 0) {
[645]694 String packages = "";
[648]695 for (Package m : execCoreUpdates) {
[645]696 packages += String.format("\n - %s (%s)", m.getName(),
697 m.getVersion());
698 }
699 JOptionPane.showMessageDialog(this, String.format(
[648]700 bundle.getString("corePackagesUpdated.text"), packages),
701 bundle.getString("corePackagesUpdated.title"),
[645]702 JOptionPane.INFORMATION_MESSAGE);
703 }
704 }
705
706 @SuppressWarnings("unused")
[641]707 private void install() {
[648]708 TreeSet<Package> mods = new TreeSet<Package>();
709 mods.addAll(PackageManager.getInstance().getCoreMods());
[631]710 mods.addAll(tblMods.getSelectedMods());
[600]711
[648]712 installDeps = new TreeSet<Package>();
[646]713
[641]714 installState = EInstallState.CHECKING;
[605]715
[641]716 while (installState == EInstallState.CHECKING) {
[648]717 TreeSet<Package> toDownload = new TreeSet<Package>();
718 for (Package m : mods) {
[605]719 if (!m.isLocalAvailable())
720 toDownload.add(m);
721 }
[669]722
[852]723 if (toDownload.size() > 0 && RuntimeOptions.isOfflineMode()) {
[641]724 installState = EInstallState.OFFLINE;
[621]725 break;
726 }
[669]727
[605]728 if (toDownload.size() > 0) {
[773]729 Downloader dl = new Downloader(toDownload, installDeps, false);
[617]730 try {
731 dl.setVisible(true);
[641]732 if (!dl.isFinished()) {
733 installState = EInstallState.ABORTED;
[617]734 break;
[641]735 }
[617]736 } finally {
737 dl.dispose();
738 }
[605]739 }
[669]740
[657]741 HashMap<Package, HashSet<Package>> dependencies = PackageManager
742 .getInstance().checkDependencies(mods);
[605]743 if (dependencies.size() > 0) {
[648]744 for (HashSet<Package> hm : dependencies.values()) {
[646]745 installDeps.addAll(hm);
746 }
[647]747
[669]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();
[641]764 }
765 }
766 }
[669]767 }
[641]768
[669]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
[720]776 if (!SettingsManager.getInstance().get(
777 "notifyDepsAfterInstall", false)) {
[646]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);
[669]786
[646]787 if (res == JOptionPane.NO_OPTION) {
788 installState = EInstallState.ABORTED;
789 break;
790 }
[641]791 }
[605]792 } else {
[648]793 HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
[645]794 .getInstance().checkIncompabitilites(mods);
[643]795 if (incompatibilities.size() > 0) {
[641]796 installState = EInstallState.INCOMPATIBLE;
[643]797
798 String incompatString = "";
[648]799 for (Package m : incompatibilities.keySet()) {
[643]800 if (incompatString.length() > 0)
801 incompatString += "\n";
802 incompatString += m.getName() + ": ";
803 String confMods = "";
[648]804 for (Package mConf : incompatibilities.get(m)) {
[643]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);
[605]817 break;
818 } else {
[641]819 installState = EInstallState.READY;
[605]820 }
821 }
[600]822 }
[618]823
[641]824 if (installState == EInstallState.READY) {
[648]825 installMods = new TreeSet<Package>();
826 TreeSet<Package> actuallyTools = new TreeSet<Package>();
[623]827
[648]828 for (Package m : mods) {
[623]829 if (m.isTool())
830 actuallyTools.add(m);
831 else
[641]832 installMods.add(m);
[623]833 }
834
835 if (actuallyTools.size() > 0) {
[749]836 ToolsManager.installTools(actuallyTools, false);
[623]837 }
[641]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() {
[605]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 });
[641]853 installState = EInstallState.DONE;
[605]854 }
[641]855 installMods = null;
[600]856 }
[618]857
[617]858 @SuppressWarnings("unused")
859 private void installDone() {
[641]860 switch (installState) {
[621]861 case DONE:
[641]862 revertSelection();
[646]863 if (installDeps.size() > 0
[720]864 && SettingsManager.getInstance().get(
865 "notifyDepsAfterInstall", false)) {
[646]866 String installedDeps = "";
[648]867 for (Package m : installDeps) {
[646]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 }
[621]883 break;
884 case OFFLINE:
[657]885 JOptionPane.showMessageDialog(
886 this,
887 SwingJavaBuilder.getConfig().getResource(
888 "offlineMode.text"),
889 SwingJavaBuilder.getConfig().getResource(
890 "offlineMode.title"),
[621]891 JOptionPane.WARNING_MESSAGE);
892 break;
[641]893 default:
[621]894 break;
895 }
[646]896 installDeps = null;
[617]897 }
[600]898
[631]899 @Override
[648]900 public void modSelectionChanged(ModTable source, Package m) {
[658]901 pkgInfo.updateInfo(m);
[591]902 }
[807]903
[805]904 @SuppressWarnings("unused")
905 private void clearFilter() {
906 txtShowFilter.setText("");
907 updateTableFilter();
908 }
[591]909
[630]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;
[805]920 if (radInstalled.isSelected())
921 downloadState = 3;
[660]922 tblMods.setFilter(t, downloadState, txtShowFilter.getText(),
923 (EApplyFilterTo) cmbShowFilterTo.getSelectedItem());
[630]924 }
925
[593]926 @Override
[673]927 public void modInstallSelectionChanged(int newSize, int newCount) {
928 lblSelectedModsVal.setText(String.valueOf(newCount));
[600]929 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
930 }
931
[616]932 @SuppressWarnings("unused")
933 private void checkInitialize() {
[600]934 if (!Installer.isEditionInitialized()) {
[621]935 if (!OniSplit.isOniSplitInstalled()) {
936 JOptionPane.showMessageDialog(this,
937 bundle.getString("noOniSplit.text"),
938 bundle.getString("noOniSplit.title"),
939 JOptionPane.ERROR_MESSAGE);
[600]940 exit();
[621]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 }
[600]952 }
953 }
954 }
[606]955
[616]956 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
957 private void initialize(final BackgroundEvent evt) {
958 if (!Installer.isEditionInitialized()) {
[749]959 Initializer.initializeEdition(new InstallProgressListener() {
[616]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
[720]971 private void oni(boolean windowed) {
[810]972 if (!Paths.getEditionGDF().isDirectory()) {
[720]973 JOptionPane.showMessageDialog(this,
[810]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 }
[605]993 }
994 }
[600]995
[605]996 @SuppressWarnings("unused")
997 private void oniFull() {
[720]998 oni(false);
[605]999 }
1000
1001 @SuppressWarnings("unused")
1002 private void oniWin() {
[720]1003 oni(true);
[605]1004 }
1005
[608]1006 @SuppressWarnings("unused")
1007 private void openEditionFolder() {
1008 try {
1009 Desktop.getDesktop().open(Paths.getEditionBasePath());
[639]1010 } catch (Exception e) {
[608]1011 e.printStackTrace();
1012 }
1013 }
1014
[600]1015 @Override
[593]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) {
[605]1040 event.setHandled(true);
1041 saveLocalData();
1042 exit();
[593]1043 }
1044
1045 @Override
1046 public void handleReOpenApplication(ApplicationEvent event) {
1047 }
[600]1048
[592]1049}
Note: See TracBrowser for help on using the repository browser.