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

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

AEI2.02:

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