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

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

AEI2 0.99r:

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