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

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

AEI2 0.99h:

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