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

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

AEI2 0.99e:

  • Added "-nocacheupdate" argument to prevent from updating local Depot cache
File size: 25.4 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(500);
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 }
275 }
276 }
277 }
278
279 @SuppressWarnings("unused")
280 private void doUpdate() {
281 if (execUpdates != null && execUpdates.size() > 0) {
282 Downloader dl = new Downloader(execUpdates, null);
283 try {
284 dl.setVisible(true);
285 if (dl.isFinished()) {
286 TreeSet<Integer> installed = Installer.getInstalledTools();
287 TreeSet<Package> tools = new TreeSet<Package>();
288 for (Package m : execUpdates)
289 if (m.isTool()
290 && installed.contains(m.getPackageNumber()))
291 tools.add(m);
292 if (tools.size() > 0) {
293 Installer.installTools(tools);
294 }
295 }
296 } finally {
297 dl.dispose();
298 }
299 }
300 execUpdates = null;
301 }
302
303 @SuppressWarnings("unused")
304 private void focus() {
305 SwingUtilities.invokeLater(new Runnable() {
306
307 @Override
308 public void run() {
309 toFront();
310 repaint();
311 }
312 });
313
314 }
315
316 @SuppressWarnings("unused")
317 private void showCorePackagesDialog() {
318 new CorePackagesDialog().setVisible(true);
319 }
320
321 private void showSettings() {
322 new SettingsDialog().setVisible(true);
323 }
324
325 private void showAbout() {
326 new AboutDialog().setVisible(true);
327 }
328
329 private JFileChooser getConfigOpenSaveDialog(boolean save) {
330 JFileChooser fc = new JFileChooser();
331 fc.setCurrentDirectory(Paths.getEditionBasePath());
332 if (save)
333 fc.setDialogType(JFileChooser.SAVE_DIALOG);
334 else
335 fc.setDialogType(JFileChooser.OPEN_DIALOG);
336 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
337 fc.setFileFilter(new FileFilter() {
338 @Override
339 public String getDescription() {
340 return "XML files";
341 }
342
343 @Override
344 public boolean accept(File arg0) {
345 return (arg0.isDirectory())
346 || (arg0.getName().toLowerCase().endsWith(".xml"));
347 }
348 });
349 fc.setMultiSelectionEnabled(false);
350 return fc;
351 }
352
353 @SuppressWarnings("unused")
354 private void loadConfig() {
355 JFileChooser fc = getConfigOpenSaveDialog(false);
356 int res = fc.showOpenDialog(this);
357 if (res == JFileChooser.APPROVE_OPTION) {
358 if (fc.getSelectedFile().exists())
359 tblMods.reloadSelection(fc.getSelectedFile());
360 }
361 }
362
363 @SuppressWarnings("unused")
364 private void saveConfig() {
365 JFileChooser fc = getConfigOpenSaveDialog(true);
366 int res = fc.showSaveDialog(this);
367 if (res == JFileChooser.APPROVE_OPTION) {
368 File f = fc.getSelectedFile();
369 if (!f.getName().endsWith(".xml"))
370 f = new File(f.getParentFile(), f.getName() + ".xml");
371 PackageManager.getInstance().saveModSelection(f,
372 tblMods.getSelectedMods());
373 }
374 }
375
376 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
377 private void reglobalize(final BackgroundEvent evt) {
378 Installer.initializeEdition(new InstallProgressListener() {
379 @Override
380 public void installProgressUpdate(int done, int total, String step) {
381 evt.setProgressEnd(total);
382 evt.setProgressValue(done);
383 evt.setProgressMessage(step);
384 }
385 });
386 }
387
388 @SuppressWarnings("unused")
389 private void tools() {
390 new ToolManager().setVisible(true);
391 }
392
393 @SuppressWarnings("unused")
394 private void refreshToolsMenu() {
395 for (JMenuItem i : toolsMenuItems) {
396 toolsMenu.remove(i);
397 }
398 toolsMenuItems.clear();
399 for (Package m : PackageManager.getInstance().getInstalledTools()) {
400 File exe = m.getExeFile();
401 if (exe != null && exe.exists()) {
402 JMenuItem item = new JMenuItem();
403 final Vector<String> params = new Vector<String>();
404 if (exe.getName().toLowerCase().endsWith(".jar")) {
405 File jre = null;
406 if (Settings.getPlatform() == Platform.WIN)
407 jre = new File(System.getProperties().getProperty(
408 "java.home"), "bin/javaw.exe");
409 else
410 jre = new File(System.getProperties().getProperty(
411 "java.home"), "bin/java");
412 params.add(jre.getPath());
413 params.add("-jar");
414 }
415 params.add(exe.getPath());
416 final File wd = m.getWorkingDir();
417 Icon ico = null;
418 if (m.getIconFile() != null && m.getIconFile().exists()) {
419 ico = new ImageIcon(m.getIconFile().getPath());
420 } else {
421 URL icon = AEInstaller2.class
422 .getResource("images/transparent.png");
423 ico = new ImageIcon(icon);
424 }
425 item.setAction(new AbstractAction(m.getName(), ico) {
426 private static final long serialVersionUID = 1L;
427
428 @Override
429 public void actionPerformed(ActionEvent e) {
430 AppExecution.execute(params, wd);
431 }
432 });
433 toolsMenuItems.add(item);
434 toolsMenu.add(item);
435 }
436 }
437 }
438
439 private void revertSelection() {
440 tblMods.revertSelection();
441 }
442
443 @DoInBackground(progressMessage = "checkCorePackages.title", cancelable = false, indeterminateProgress = false)
444 private void checkCorePackages(final BackgroundEvent evt) {
445 if (!Settings.getInstance().isOfflineMode()) {
446 for (Package m : PackageManager.getInstance().getCoreTools()) {
447 if (m.isNewerAvailable()) {
448 execCoreUpdates.add(m);
449 }
450 }
451 for (Package m : PackageManager.getInstance().getCoreMods()) {
452 if (m.isNewerAvailable()) {
453 execCoreUpdates.add(m);
454 }
455 }
456 if (execCoreUpdates.size() > 0) {
457 ModDownloader m = new ModDownloader(execCoreUpdates,
458 new ModDownloaderListener() {
459 @Override
460 public void updateStatus(ModDownloader source,
461 Package currentDownload, State state,
462 int filesDown, int filesTotal,
463 int bytesDown, int bytesTotal,
464 int duration, int remaining, int speed) {
465 evt.setProgressEnd(filesTotal);
466 evt.setProgressValue(filesDown);
467 }
468 });
469 while (!m.isFinished()) {
470 try {
471 Thread.sleep(10);
472 } catch (InterruptedException e) {
473 e.printStackTrace();
474 }
475 }
476 }
477 evt.setProgressMessage(bundle
478 .getString("coreToolsInstall.title"));
479 Installer
480 .installTools(PackageManager.getInstance().getCoreTools());
481 }
482 }
483
484 @SuppressWarnings("unused")
485 private void infoCorePackages() {
486 if (execCoreUpdates.size() > 0) {
487 String packages = "";
488 for (Package m : execCoreUpdates) {
489 packages += String.format("\n - %s (%s)", m.getName(),
490 m.getVersion());
491 }
492 JOptionPane.showMessageDialog(this, String.format(
493 bundle.getString("corePackagesUpdated.text"), packages),
494 bundle.getString("corePackagesUpdated.title"),
495 JOptionPane.INFORMATION_MESSAGE);
496 }
497 }
498
499 @SuppressWarnings("unused")
500 private void install() {
501 TreeSet<Package> mods = new TreeSet<Package>();
502 mods.addAll(PackageManager.getInstance().getCoreMods());
503 mods.addAll(tblMods.getSelectedMods());
504
505 installDeps = new TreeSet<Package>();
506
507 installState = EInstallState.CHECKING;
508
509 while (installState == EInstallState.CHECKING) {
510 TreeSet<Package> toDownload = new TreeSet<Package>();
511 for (Package m : mods) {
512 if (!m.isLocalAvailable())
513 toDownload.add(m);
514 }
515 if (Settings.getInstance().isOfflineMode()) {
516 installState = EInstallState.OFFLINE;
517 break;
518 }
519 if (toDownload.size() > 0) {
520 Downloader dl = new Downloader(toDownload, installDeps);
521 try {
522 dl.setVisible(true);
523 if (!dl.isFinished()) {
524 installState = EInstallState.ABORTED;
525 break;
526 }
527 } finally {
528 dl.dispose();
529 }
530 }
531 HashMap<Package, HashSet<Package>> dependencies = PackageManager.getInstance()
532 .checkDependencies(mods);
533 if (dependencies.size() > 0) {
534 for (HashSet<Package> hm : dependencies.values()) {
535 installDeps.addAll(hm);
536 }
537
538 if (!Settings.getInstance()
539 .get("notifyDepsAfterInstall", false)) {
540 int size = 0;
541 String depsLocalString = "";
542 String depsDownloadString = "";
543 for (Package m : dependencies.keySet()) {
544 for (Package mDep : dependencies.get(m)) {
545 if (!mods.contains(mDep)) {
546 mods.add(mDep);
547 if (!mDep.isLocalAvailable()) {
548 size += mDep.getZipSize();
549 if (depsDownloadString.length() > 0)
550 depsDownloadString += "\n";
551 depsDownloadString += " - "
552 + mDep.getName();
553 } else {
554 if (depsLocalString.length() > 0)
555 depsLocalString += "\n";
556 depsLocalString += " - " + mDep.getName();
557 }
558 }
559 }
560 }
561 if (depsLocalString.length() == 0)
562 depsLocalString = bundle
563 .getString("installDependencies.none");
564 if (depsDownloadString.length() == 0)
565 depsDownloadString = bundle
566 .getString("installDependencies.none");
567
568 int res = JOptionPane.showConfirmDialog(this, String
569 .format(bundle
570 .getString("installDependencies.text"),
571 depsLocalString, depsDownloadString,
572 SizeFormatter.format(size, 3)), bundle
573 .getString("installDependencies.title"),
574 JOptionPane.YES_NO_OPTION,
575 JOptionPane.INFORMATION_MESSAGE);
576 if (res == JOptionPane.NO_OPTION) {
577 installState = EInstallState.ABORTED;
578 break;
579 }
580 }
581 } else {
582 HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
583 .getInstance().checkIncompabitilites(mods);
584 if (incompatibilities.size() > 0) {
585 installState = EInstallState.INCOMPATIBLE;
586
587 String incompatString = "";
588 for (Package m : incompatibilities.keySet()) {
589 if (incompatString.length() > 0)
590 incompatString += "\n";
591 incompatString += m.getName() + ": ";
592 String confMods = "";
593 for (Package mConf : incompatibilities.get(m)) {
594 if (confMods.length() > 0)
595 confMods += ", ";
596 confMods += mConf.getName();
597 }
598 incompatString += confMods;
599 }
600
601 JOptionPane.showMessageDialog(this, String.format(
602 bundle.getString("installIncompatibilities.text"),
603 incompatString), bundle
604 .getString("installIncompatibilities.title"),
605 JOptionPane.ERROR_MESSAGE);
606 break;
607 } else {
608 installState = EInstallState.READY;
609 }
610 }
611 }
612
613 if (installState == EInstallState.READY) {
614 installMods = new TreeSet<Package>();
615 TreeSet<Package> actuallyTools = new TreeSet<Package>();
616
617 for (Package m : mods) {
618 if (m.isTool())
619 actuallyTools.add(m);
620 else
621 installMods.add(m);
622 }
623
624 if (actuallyTools.size() > 0) {
625 Installer.installTools(actuallyTools);
626 }
627 }
628
629 }
630
631 @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
632 private void installExec(final BackgroundEvent evt) {
633 if (installState == EInstallState.READY) {
634 Installer.install(installMods, new InstallProgressListener() {
635 @Override
636 public void installProgressUpdate(int done, int total,
637 String step) {
638 evt.setProgressEnd(total);
639 evt.setProgressValue(done);
640 evt.setProgressMessage(step);
641 }
642 });
643 installState = EInstallState.DONE;
644 }
645 installMods = null;
646 }
647
648 @SuppressWarnings("unused")
649 private void installDone() {
650 PackageManager.getInstance().updateInstalledMods();
651 switch (installState) {
652 case DONE:
653 revertSelection();
654 if (installDeps.size() > 0
655 && Settings.getInstance().get("notifyDepsAfterInstall",
656 false)) {
657 String installedDeps = "";
658 for (Package m : installDeps) {
659 if (installedDeps.length() > 0)
660 installedDeps += "\n";
661 installedDeps += " - " + m.getName();
662 }
663 JOptionPane.showMessageDialog(this, String.format(
664 bundle.getString("installDoneDeps.text"),
665 installedDeps), bundle
666 .getString("installDone.title"),
667 JOptionPane.INFORMATION_MESSAGE);
668 } else {
669 JOptionPane.showMessageDialog(this,
670 bundle.getString("installDone.text"),
671 bundle.getString("installDone.title"),
672 JOptionPane.INFORMATION_MESSAGE);
673 }
674 break;
675 case OFFLINE:
676 JOptionPane.showMessageDialog(this,
677 bundle.getString("offlineMode.text"),
678 bundle.getString("offlineMode.title"),
679 JOptionPane.WARNING_MESSAGE);
680 break;
681 default:
682 break;
683 }
684 installDeps = null;
685 }
686
687 @Override
688 public void modSelectionChanged(ModTable source, Package m) {
689 lblTitleVal.setText("");
690 lblCreatorVal.setText("");
691 lblDescriptionVal.setText("");
692 lblTypesVal.setText("");
693 lblPlatformVal.setText("");
694 lblPackageNumberVal.setText("");
695 lblVersionNumberVal.setText("");
696 if (m != null) {
697 lblTitleVal.setText(m.getName());
698 lblCreatorVal.setText(m.getCreator());
699 lblDescriptionVal.setText(m.getDescription());
700
701 String types = "";
702 for (Type t : m.getTypes()) {
703 if (types.length() > 0)
704 types += ", ";
705 types += t.getName();
706 }
707 lblTypesVal.setText(types);
708 lblPlatformVal.setText(m.getPlatform().toString());
709 lblPackageNumberVal.setText(m.getPackageNumberString());
710 lblVersionNumberVal.setText(m.getVersion());
711 }
712 }
713
714 private void updateTableFilter() {
715 Object o = cmbModTypes.getSelectedItem();
716 Type t = null;
717 if (o instanceof Type)
718 t = (Type) o;
719 int downloadState = 0;
720 if (radOnline.isSelected())
721 downloadState = 1;
722 if (radLocal.isSelected())
723 downloadState = 2;
724 tblMods.setFilter(t, downloadState);
725 }
726
727 @SuppressWarnings("unused")
728 private void modTypeSelection() {
729 updateTableFilter();
730 }
731
732 @SuppressWarnings("unused")
733 private void showTypeSelection() {
734 updateTableFilter();
735 }
736
737 @Override
738 public void downloadSizeChanged(int newSize) {
739 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
740 }
741
742 @SuppressWarnings("unused")
743 private void checkInitialize() {
744 if (!Installer.isEditionInitialized()) {
745 if (!OniSplit.isOniSplitInstalled()) {
746 JOptionPane.showMessageDialog(this,
747 bundle.getString("noOniSplit.text"),
748 bundle.getString("noOniSplit.title"),
749 JOptionPane.ERROR_MESSAGE);
750 exit();
751 } else {
752 int res = JOptionPane
753 .showConfirmDialog(this,
754 bundle.getString("askInitialize.text"),
755 bundle.getString("askInitialize.title"),
756 JOptionPane.YES_NO_OPTION,
757 JOptionPane.QUESTION_MESSAGE);
758 if (res == JOptionPane.NO_OPTION) {
759 saveLocalData();
760 exit();
761 }
762 }
763 }
764 }
765
766 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
767 private void initialize(final BackgroundEvent evt) {
768 if (!Installer.isEditionInitialized()) {
769 Installer.initializeEdition(new InstallProgressListener() {
770 @Override
771 public void installProgressUpdate(int done, int total,
772 String step) {
773 evt.setProgressEnd(total);
774 evt.setProgressValue(done);
775 evt.setProgressMessage(step);
776 }
777 });
778 }
779 }
780
781 private Vector<String> getBasicOniLaunchParams() {
782 Vector<String> params = new Vector<String>();
783 File exe = null;
784 switch (Settings.getPlatform()) {
785 case WIN:
786 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
787 if (exe.exists())
788 params.add(exe.getPath());
789 break;
790 case MACOS:
791 exe = new File(Paths.getEditionBasePath(),
792 "Oni.app/Contents/MacOS/Oni");
793 if (exe.exists())
794 params.add(exe.getPath());
795 break;
796 case LINUX:
797 String wine = Settings.getWinePath();
798 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
799 if (exe.exists()) {
800 if (wine != null) {
801 params.add(wine);
802 params.add(exe.getPath());
803 }
804 }
805 break;
806 default:
807 }
808 if (params.size() > 0) {
809 params.add("-debugfiles");
810 }
811 return params;
812 }
813
814 @SuppressWarnings("unused")
815 private void oniFull() {
816 Vector<String> params = getBasicOniLaunchParams();
817 if (params.size() > 0) {
818 AppExecution.execute(params, Paths.getEditionBasePath());
819 }
820 }
821
822 @SuppressWarnings("unused")
823 private void oniWin() {
824 Vector<String> params = getBasicOniLaunchParams();
825 if (params.size() > 0) {
826 params.add("-noswitch");
827 AppExecution.execute(params, Paths.getEditionBasePath());
828 }
829 }
830
831 @SuppressWarnings("unused")
832 private void openEditionFolder() {
833 try {
834 Desktop.getDesktop().open(Paths.getEditionBasePath());
835 } catch (Exception e) {
836 e.printStackTrace();
837 }
838 }
839
840 @Override
841 public void handleAbout(ApplicationEvent event) {
842 event.setHandled(true);
843 showAbout();
844 }
845
846 @Override
847 public void handleOpenApplication(ApplicationEvent event) {
848 }
849
850 @Override
851 public void handleOpenFile(ApplicationEvent event) {
852 }
853
854 @Override
855 public void handlePreferences(ApplicationEvent event) {
856 showSettings();
857 }
858
859 @Override
860 public void handlePrintFile(ApplicationEvent event) {
861 }
862
863 @Override
864 public void handleQuit(ApplicationEvent event) {
865 event.setHandled(true);
866 saveLocalData();
867 exit();
868 }
869
870 @Override
871 public void handleReOpenApplication(ApplicationEvent event) {
872 }
873
874}
Note: See TracBrowser for help on using the repository browser.