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

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

AEI2.00:

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