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

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

AEI2 0.87:

  • Checkbox on update notification dialog to select whether to check for updates on startup
File size: 22.9 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui;
2
[627]3import java.awt.BorderLayout;
[608]4import java.awt.Desktop;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
[627]7import java.awt.event.ItemEvent;
8import java.awt.event.ItemListener;
[608]9import java.awt.event.MouseAdapter;
10import java.awt.event.MouseEvent;
[604]11import java.io.File;
[605]12import java.io.IOException;
[623]13import java.net.URL;
[591]14import java.util.ArrayList;
[605]15import java.util.HashMap;
16import java.util.HashSet;
[591]17import java.util.List;
18import java.util.ResourceBundle;
19import java.util.TreeMap;
[600]20import java.util.TreeSet;
[605]21import java.util.Vector;
[591]22
[623]23import javax.swing.AbstractAction;
24import javax.swing.Icon;
25import javax.swing.ImageIcon;
[600]26import javax.swing.JButton;
[627]27import javax.swing.JCheckBox;
[591]28import javax.swing.JComboBox;
[593]29import javax.swing.JComponent;
[604]30import javax.swing.JFileChooser;
[591]31import javax.swing.JFrame;
[592]32import javax.swing.JLabel;
[593]33import javax.swing.JMenu;
[608]34import javax.swing.JMenuItem;
[593]35import javax.swing.JOptionPane;
[627]36import javax.swing.JPanel;
[608]37import javax.swing.JPopupMenu;
[592]38import javax.swing.JSplitPane;
[591]39import javax.swing.JTable;
40import javax.swing.ListSelectionModel;
41import javax.swing.RowSorter;
42import javax.swing.SortOrder;
43import javax.swing.SwingUtilities;
44import javax.swing.event.ListSelectionEvent;
45import javax.swing.event.ListSelectionListener;
[604]46import javax.swing.filechooser.FileFilter;
[591]47import javax.swing.table.TableRowSorter;
48
[623]49import net.oni2.aeinstaller.AEInstaller2;
50import net.oni2.aeinstaller.backend.AppExecution;
[604]51import net.oni2.aeinstaller.backend.Paths;
[591]52import net.oni2.aeinstaller.backend.Settings;
[593]53import net.oni2.aeinstaller.backend.Settings.Platform;
[600]54import net.oni2.aeinstaller.backend.SizeFormatter;
[591]55import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener;
56import net.oni2.aeinstaller.backend.depot.DepotManager;
[600]57import net.oni2.aeinstaller.backend.mods.Mod;
58import net.oni2.aeinstaller.backend.mods.ModManager;
59import net.oni2.aeinstaller.backend.mods.Type;
[604]60import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
61import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
62import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
[600]63import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
64import net.oni2.aeinstaller.backend.oni.Installer;
[621]65import net.oni2.aeinstaller.backend.oni.OniSplit;
[593]66import net.oni2.aeinstaller.gui.about.AboutDialog;
[605]67import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
[600]68import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
[591]69import net.oni2.aeinstaller.gui.modtable.ModTableFilter;
70import net.oni2.aeinstaller.gui.modtable.ModTableModel;
71import net.oni2.aeinstaller.gui.settings.SettingsDialog;
[625]72import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
[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,
85 DownloadSizeListener {
[591]86 private static final long serialVersionUID = -4027395051382659650L;
87
88 private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
89 .getName());
90 @SuppressWarnings("unused")
91 private BuildResult result = SwingJavaBuilder.build(this, bundle);
92
[593]93 private JMenu mainMenu;
[623]94 private JMenu toolsMenu;
95 private TreeSet<JMenuItem> toolsMenuItems = new TreeSet<JMenuItem>();
[593]96
[592]97 private JSplitPane contents;
98
[591]99 private JComboBox cmbModTypes;
100 private JTable tblMods;
101 private ModTableModel model;
102 private TableRowSorter<ModTableModel> sorter;
[600]103 private JLabel lblDownloadSizeVal;
[591]104
[592]105 private JLabel lblSubmitterVal;
106 private JLabel lblCreatorVal;
[606]107 private JLabel lblTypesVal;
108 private JLabel lblPlatformVal;
[621]109 private JLabel lblPackageNumberVal;
[592]110 private HTMLLinkLabel lblDescriptionVal;
111
[600]112 private JButton btnInstall;
113
[621]114 private TreeSet<Mod> execUpdates = null;
115
116 private enum EInstallResult {
117 DONE,
118 OFFLINE,
119 INCOMPATIBLE
120 };
121
122 private EInstallResult installDone = EInstallResult.DONE;
123
[591]124 /**
125 * Constructor of main window.
126 */
127 public MainWin() {
[593]128 this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
129 + " - v"
130 + SwingJavaBuilder.getConfig().getResource("appversion"));
[591]131
[592]132 contents.setDividerLocation(400);
[593]133
134 if (Settings.getPlatform() == Platform.MACOS) {
135 mainMenu.setVisible(false);
136 }
[600]137
138 getRootPane().setDefaultButton(btnInstall);
[605]139 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
[591]140 }
141
142 private void initModTypeBox() {
[592]143 cmbModTypes.removeAllItems();
144
[600]145 TreeMap<String, Type> types = new TreeMap<String, Type>();
146 for (Type t : ModManager.getInstance().getTypesWithContent()) {
147 types.put(t.getName(), t);
[591]148 }
[600]149 for (Type t : types.values()) {
[591]150 cmbModTypes.addItem(t);
151 }
152 cmbModTypes.setSelectedIndex(0);
153 }
154
155 private void initTable() {
156 tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
[592]157 tblMods.getSelectionModel().addListSelectionListener(
158 new ListSelectionListener() {
159 @Override
160 public void valueChanged(ListSelectionEvent e) {
161 int viewRow = tblMods.getSelectedRow();
162 if (viewRow < 0) {
163 modSelection(null);
164 } else {
165 int modelRow = tblMods
166 .convertRowIndexToModel(viewRow);
[600]167 Mod mod = (Mod) model.getValueAt(modelRow, -1);
[592]168 modSelection(mod);
169 }
170 }
171 });
[608]172 tblMods.addMouseListener(new MouseAdapter() {
173 private void common(MouseEvent e) {
174 int r = tblMods.rowAtPoint(e.getPoint());
175 if (r >= 0 && r < tblMods.getRowCount())
176 tblMods.setRowSelectionInterval(r, r);
177 else
178 tblMods.clearSelection();
[592]179
[608]180 int rowindex = tblMods.getSelectedRow();
181 if (rowindex >= 0) {
182 if (e.isPopupTrigger()
183 && e.getComponent() instanceof JTable) {
184 int modelRow = tblMods.convertRowIndexToModel(rowindex);
185 final Mod mod = (Mod) model.getValueAt(modelRow, -1);
186
187 if (mod.isLocalAvailable()) {
188 JPopupMenu popup = new JPopupMenu();
189 JMenuItem openModFolder = new JMenuItem(bundle
190 .getString("openModFolder.text"));
191 openModFolder
192 .addActionListener(new ActionListener() {
193 @Override
194 public void actionPerformed(
195 ActionEvent arg0) {
196 try {
197 Desktop.getDesktop().open(
198 mod.getLocalPath());
199 } catch (IOException e) {
200 e.printStackTrace();
201 }
202 }
203 });
204 popup.add(openModFolder);
205 popup.show(e.getComponent(), e.getX(), e.getY());
206 }
207 }
208 }
209 }
210
211 @Override
212 public void mousePressed(MouseEvent e) {
213 common(e);
214 }
215
216 @Override
217 public void mouseReleased(MouseEvent e) {
218 common(e);
219 }
220 });
[593]221 // To get checkbox-cells with background of row
222 ((JComponent) tblMods.getDefaultRenderer(Boolean.class))
223 .setOpaque(true);
224
[591]225 model = new ModTableModel();
[600]226 model.addDownloadSizeListener(this);
[591]227
228 tblMods.setModel(model);
229
230 sorter = new TableRowSorter<ModTableModel>(model);
231 tblMods.setRowSorter(sorter);
232
[600]233 sorter.setRowFilter(new ModTableFilter(null));
[591]234
235 List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
[606]236 sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
[591]237 sorter.setSortKeys(sortKeys);
238
239 for (int i = 0; i < model.getColumnCount(); i++) {
240 model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i));
241 }
242 }
243
244 private void exit() {
245 dispose();
[608]246 System.exit(0);
[591]247 }
248
249 private void saveLocalData() {
250 Settings.getInstance().serializeToFile();
[596]251 DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename());
[591]252 }
253
254 @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
255 private void execDepotUpdate(final BackgroundEvent evt) {
[621]256 if (!Settings.getInstance().isOfflineMode()) {
257 try {
258 DepotManager.getInstance().updateInformation(false,
259 new DepotCacheUpdateProgressListener() {
[591]260
[621]261 @Override
262 public void cacheUpdateProgress(String stepName,
263 int current, int total) {
264 evt.setProgressEnd(total);
265 evt.setProgressValue(current);
266 evt.setProgressMessage(stepName);
267 }
268 });
269 } catch (Exception e) {
270 e.printStackTrace();
271 }
272 }
273 ModManager.getInstance().init();
274 initTable();
275 initModTypeBox();
[600]276
[621]277 tblMods.setVisible(true);
278 }
279
280 @SuppressWarnings("unused")
281 private void checkUpdates(Object evtSource) {
282 if ((evtSource != this)
283 || Settings.getInstance().get("notifyupdates", true)) {
284 if (Settings.getInstance().isOfflineMode()) {
285 if (evtSource != this) {
286 JOptionPane.showMessageDialog(this,
287 bundle.getString("offlineMode.text"),
288 bundle.getString("offlineMode.title"),
289 JOptionPane.WARNING_MESSAGE);
290 }
291 } else {
292 TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
293 TreeSet<Mod> tools = ModManager.getInstance()
294 .getUpdatableTools();
295 int size = 0;
296 String strMods = "";
297 for (Mod m : mods) {
298 size += m.getZipSize();
299 if (strMods.length() > 0)
300 strMods += "<br>";
301 strMods += " - " + m.getName();
302 }
303 String strTools = "";
304 for (Mod m : tools) {
305 size += m.getZipSize();
306 if (strTools.length() > 0)
307 strTools += "<br>";
308 strTools += " - " + m.getName();
309 }
[622]310 if (size > 0) {
[627]311 // Build info dialog content
[622]312 String message = "<html>";
313 message += String.format(
314 bundle.getString("updatesAvailable.text"), strMods,
315 strTools, SizeFormatter.format(size, 3));
316 message += "</html>";
[627]317
318 JPanel pan = new JPanel();
319 pan.setLayout(new BorderLayout(0, 20));
320 JLabel lab = new JLabel(message);
321 pan.add(lab, BorderLayout.CENTER);
322 JCheckBox checkFutureUpdates = new JCheckBox(
323 bundle.getString("checkOnStartup.text"));
324 checkFutureUpdates.setSelected(Settings.getInstance().get(
325 "notifyupdates", true));
326 checkFutureUpdates.addItemListener(new ItemListener() {
327 @Override
328 public void itemStateChanged(ItemEvent evt) {
329 Settings.getInstance().put("notifyupdates",
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);
340 if (res == JOptionPane.YES_OPTION) {
341 execUpdates = new TreeSet<Mod>();
342 execUpdates.addAll(mods);
343 execUpdates.addAll(tools);
344 }
[621]345 }
346 }
[591]347 }
348 }
349
[624]350 @SuppressWarnings("unused")
351 private void doUpdate() {
[621]352 if (execUpdates != null) {
[624]353 Downloader dl = new Downloader(execUpdates);
354 try {
355 dl.setVisible(true);
356 if (dl.isFinished()) {
357 TreeSet<Integer> installed = Installer.getInstalledTools();
358 TreeSet<Mod> tools = new TreeSet<Mod>();
359 for (Mod m : execUpdates)
360 if (m.isTool()
361 && installed.contains(m.getPackageNumber()))
362 tools.add(m);
363 if (tools.size() > 0) {
364 Installer.installTools(tools);
365 }
366 }
367 } finally {
368 dl.dispose();
369 }
[591]370 }
[621]371 execUpdates = null;
[591]372 }
373
374 @SuppressWarnings("unused")
375 private void focus() {
376 SwingUtilities.invokeLater(new Runnable() {
377
378 @Override
379 public void run() {
380 toFront();
381 repaint();
382 }
383 });
384
385 }
386
387 private void showSettings() {
[593]388 new SettingsDialog().setVisible(true);
[591]389 }
390
[593]391 private void showAbout() {
392 new AboutDialog().setVisible(true);
393 }
394
[604]395 private JFileChooser getConfigOpenSaveDialog(boolean save) {
396 JFileChooser fc = new JFileChooser();
397 fc.setCurrentDirectory(Paths.getEditionBasePath());
398 if (save)
399 fc.setDialogType(JFileChooser.SAVE_DIALOG);
400 else
401 fc.setDialogType(JFileChooser.OPEN_DIALOG);
402 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
403 fc.setFileFilter(new FileFilter() {
404 @Override
405 public String getDescription() {
406 return "XML files";
407 }
408
409 @Override
410 public boolean accept(File arg0) {
411 return (arg0.isDirectory())
412 || (arg0.getName().toLowerCase().endsWith(".xml"));
413 }
414 });
415 fc.setMultiSelectionEnabled(false);
416 return fc;
417 }
418
[593]419 @SuppressWarnings("unused")
420 private void loadConfig() {
[604]421 JFileChooser fc = getConfigOpenSaveDialog(false);
422 int res = fc.showOpenDialog(this);
423 if (res == JFileChooser.APPROVE_OPTION) {
424 if (fc.getSelectedFile().exists())
425 model.reloadSelection(fc.getSelectedFile());
426 }
[593]427 }
428
429 @SuppressWarnings("unused")
430 private void saveConfig() {
[604]431 JFileChooser fc = getConfigOpenSaveDialog(true);
432 int res = fc.showSaveDialog(this);
433 if (res == JFileChooser.APPROVE_OPTION) {
434 File f = fc.getSelectedFile();
435 if (!f.getName().endsWith(".xml"))
436 f = new File(f.getParentFile(), f.getName() + ".xml");
437 ModManager.getInstance().saveModSelection(f,
438 model.getSelectedMods());
439 }
[593]440 }
441
[600]442 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
443 private void reglobalize(final BackgroundEvent evt) {
444 Installer.initializeEdition(new InstallProgressListener() {
445 @Override
446 public void installProgressUpdate(int done, int total, String step) {
447 evt.setProgressEnd(total);
448 evt.setProgressValue(done);
449 evt.setProgressMessage(step);
450 }
451 });
452 }
453
[593]454 @SuppressWarnings("unused")
[600]455 private void tools() {
[625]456 new ToolManager().setVisible(true);
[593]457 }
[596]458
[593]459 @SuppressWarnings("unused")
[623]460 private void refreshToolsMenu() {
461 for (JMenuItem i : toolsMenuItems) {
462 toolsMenu.remove(i);
463 }
464 toolsMenuItems.clear();
465 for (Mod m : ModManager.getInstance().getInstalledTools()) {
466 if (m.getExeFile() != null && m.getExeFile().exists()) {
467 JMenuItem item = new JMenuItem();
468 final Vector<String> params = new Vector<String>();
469 params.add(m.getExeFile().getPath());
470 final File wd = m.getWorkingDir();
471 Icon ico = null;
472 if (m.getIconFile() != null && m.getIconFile().exists()) {
473 ico = new ImageIcon(m.getIconFile().getPath());
474 } else {
[624]475 URL icon = AEInstaller2.class
476 .getResource("images/transparent.png");
[623]477 ico = new ImageIcon(icon);
478 }
479 item.setAction(new AbstractAction(m.getName(), ico) {
480 private static final long serialVersionUID = 1L;
481
482 @Override
483 public void actionPerformed(ActionEvent e) {
484 AppExecution.execute(params, wd);
485 }
486 });
487 toolsMenuItems.add(item);
488 toolsMenu.add(item);
489 }
490 }
491 }
492
493 @SuppressWarnings("unused")
[593]494 private void revertSelection() {
[604]495 model.revertSelection();
[593]496 }
497
[602]498 @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
499 private void checkMandatoryFiles(final BackgroundEvent evt) {
[621]500 if (!Settings.getInstance().isOfflineMode()) {
501 TreeSet<Mod> mand = new TreeSet<Mod>();
502 for (Mod m : ModManager.getInstance().getMandatoryTools()) {
503 if (m.isNewerAvailable()) {
504 mand.add(m);
505 }
[604]506 }
[621]507 for (Mod m : ModManager.getInstance().getMandatoryMods()) {
508 if (m.isNewerAvailable()) {
509 mand.add(m);
510 }
[604]511 }
[621]512 if (mand.size() > 0) {
513 ModDownloader m = new ModDownloader(mand,
514 new ModDownloaderListener() {
515 @Override
516 public void updateStatus(ModDownloader source,
517 State state, int filesDown, int filesTotal,
518 int bytesDown, int bytesTotal,
519 int duration, int remaining, int speed) {
520 evt.setProgressEnd(filesTotal);
521 evt.setProgressValue(filesDown);
522 }
523 });
524 while (!m.isFinished()) {
525 try {
526 Thread.sleep(10);
527 } catch (InterruptedException e) {
528 e.printStackTrace();
529 }
[604]530 }
531 }
[621]532 evt.setProgressMessage(bundle
533 .getString("mandatoryToolsInstall.title"));
534 Installer
535 .installTools(ModManager.getInstance().getMandatoryTools());
[604]536 }
[602]537 }
538
[600]539 @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
[621]540 private void install(final BackgroundEvent evt) {
[600]541 TreeSet<Mod> mods = new TreeSet<Mod>();
[602]542 mods.addAll(ModManager.getInstance().getMandatoryMods());
[600]543 mods.addAll(model.getSelectedMods());
544
[605]545 boolean instReady = false;
[621]546 installDone = EInstallResult.DONE;
[605]547
548 while (!instReady) {
549 TreeSet<Mod> toDownload = new TreeSet<Mod>();
550 for (Mod m : mods) {
551 if (!m.isLocalAvailable())
552 toDownload.add(m);
553 }
[621]554 if (Settings.getInstance().isOfflineMode()) {
555 installDone = EInstallResult.OFFLINE;
556 break;
557 }
[605]558 if (toDownload.size() > 0) {
559 Downloader dl = new Downloader(toDownload);
[617]560 try {
561 dl.setVisible(true);
562 if (!dl.isFinished())
563 break;
564 } finally {
565 dl.dispose();
566 }
[605]567 }
568 HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
569 .checkDependencies(mods);
570 if (dependencies.size() > 0) {
571 System.out.println("Unmet dependencies: "
572 + dependencies.toString());
573 for (Mod m : dependencies.keySet()) {
574 for (Mod mDep : dependencies.get(m))
575 mods.add(mDep);
576 }
577 } else {
578 HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
[608]579 .checkIncompabitilites(mods);
[605]580 if (conflicts.size() > 0) {
[621]581 installDone = EInstallResult.INCOMPATIBLE;
[608]582 System.err.println("Incompatible mods: "
[605]583 + conflicts.toString());
584 break;
585 } else {
586 instReady = true;
587 }
588 }
[600]589 }
[618]590
[605]591 if (instReady) {
[623]592 TreeSet<Mod> actuallyMods = new TreeSet<Mod>();
593 TreeSet<Mod> actuallyTools = new TreeSet<Mod>();
594
595 for (Mod m : mods) {
596 if (m.isTool())
597 actuallyTools.add(m);
598 else
599 actuallyMods.add(m);
600 }
601
602 if (actuallyTools.size() > 0) {
603 Installer.installTools(actuallyTools);
604 }
605
606 Installer.install(actuallyMods, new InstallProgressListener() {
[605]607 @Override
608 public void installProgressUpdate(int done, int total,
609 String step) {
610 evt.setProgressEnd(total);
611 evt.setProgressValue(done);
612 evt.setProgressMessage(step);
613 }
614 });
[621]615 installDone = EInstallResult.DONE;
[605]616 }
[600]617 }
[618]618
[617]619 @SuppressWarnings("unused")
620 private void installDone() {
[621]621 switch (installDone) {
622 case DONE:
623 JOptionPane.showMessageDialog(this,
624 bundle.getString("installDone.text"),
625 bundle.getString("installDone.title"),
626 JOptionPane.INFORMATION_MESSAGE);
627 break;
628 case OFFLINE:
629 JOptionPane.showMessageDialog(this,
630 bundle.getString("offlineMode.text"),
631 bundle.getString("offlineMode.title"),
632 JOptionPane.WARNING_MESSAGE);
633 break;
634 case INCOMPATIBLE:
635 break;
636 }
[617]637 }
[600]638
639 private void modSelection(Mod m) {
[592]640 lblSubmitterVal.setText("");
641 lblCreatorVal.setText("");
642 lblDescriptionVal.setText("");
[606]643 lblTypesVal.setText("");
644 lblPlatformVal.setText("");
[621]645 lblPackageNumberVal.setText("");
[600]646 if (m != null) {
647 lblSubmitterVal.setText(m.getName());
648 lblCreatorVal.setText(m.getCreator());
649 lblDescriptionVal.setText(m.getDescription());
[606]650
651 String types = "";
652 for (Type t : m.getTypes()) {
653 if (types.length() > 0)
654 types += ", ";
655 types += t.getName();
656 }
657 lblTypesVal.setText(types);
658 lblPlatformVal.setText(m.getPlatform().toString());
[621]659 lblPackageNumberVal.setText(m.getPackageNumberString());
[591]660 }
661 }
662
663 @SuppressWarnings("unused")
[592]664 private void modTypeSelection() {
[600]665 Type t = (Type) cmbModTypes.getSelectedItem();
[592]666 if (t != null)
[600]667 sorter.setRowFilter(new ModTableFilter(t));
[592]668 else
[600]669 sorter.setRowFilter(new ModTableFilter(null));
[591]670 }
[593]671
672 @Override
[600]673 public void downloadSizeChanged(int newSize) {
674 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
675 }
676
[616]677 @SuppressWarnings("unused")
678 private void checkInitialize() {
[600]679 if (!Installer.isEditionInitialized()) {
[621]680 if (!OniSplit.isOniSplitInstalled()) {
681 JOptionPane.showMessageDialog(this,
682 bundle.getString("noOniSplit.text"),
683 bundle.getString("noOniSplit.title"),
684 JOptionPane.ERROR_MESSAGE);
[600]685 exit();
[621]686 } else {
687 int res = JOptionPane
688 .showConfirmDialog(this,
689 bundle.getString("askInitialize.text"),
690 bundle.getString("askInitialize.title"),
691 JOptionPane.YES_NO_OPTION,
692 JOptionPane.QUESTION_MESSAGE);
693 if (res == JOptionPane.NO_OPTION) {
694 saveLocalData();
695 exit();
696 }
[600]697 }
698 }
699 }
[606]700
[616]701 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
702 private void initialize(final BackgroundEvent evt) {
703 if (!Installer.isEditionInitialized()) {
704 Installer.initializeEdition(new InstallProgressListener() {
705 @Override
706 public void installProgressUpdate(int done, int total,
707 String step) {
708 evt.setProgressEnd(total);
709 evt.setProgressValue(done);
710 evt.setProgressMessage(step);
711 }
712 });
713 }
714 }
715
[605]716 private Vector<String> getBasicOniLaunchParams() {
717 Vector<String> params = new Vector<String>();
[618]718 File exe = null;
[605]719 switch (Settings.getPlatform()) {
720 case WIN:
[618]721 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
722 if (exe.exists())
723 params.add(exe.getPath());
[605]724 break;
725 case MACOS:
[618]726 exe = new File(Paths.getEditionBasePath(),
727 "Oni.app/Contents/MacOS/Oni");
728 if (exe.exists())
729 params.add(exe.getPath());
[605]730 break;
731 case LINUX:
732 String wine = Settings.getWinePath();
[618]733 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
734 if (exe.exists()) {
735 if (wine != null) {
736 params.add(wine);
737 params.add(exe.getPath());
738 }
[605]739 }
740 break;
741 default:
742 }
743 if (params.size() > 0) {
744 params.add("-debugfiles");
745 }
746 return params;
747 }
[600]748
[605]749 @SuppressWarnings("unused")
750 private void oniFull() {
751 Vector<String> params = getBasicOniLaunchParams();
752 if (params.size() > 0) {
[623]753 AppExecution.execute(params, Paths.getEditionBasePath());
[605]754 }
755 }
756
757 @SuppressWarnings("unused")
758 private void oniWin() {
759 Vector<String> params = getBasicOniLaunchParams();
760 if (params.size() > 0) {
761 params.add("-noswitch");
[623]762 AppExecution.execute(params, Paths.getEditionBasePath());
[605]763 }
764 }
765
[608]766 @SuppressWarnings("unused")
767 private void openEditionFolder() {
768 try {
769 Desktop.getDesktop().open(Paths.getEditionBasePath());
770 } catch (IOException e) {
771 e.printStackTrace();
772 }
773 }
774
[600]775 @Override
[593]776 public void handleAbout(ApplicationEvent event) {
777 event.setHandled(true);
778 showAbout();
779 }
780
781 @Override
782 public void handleOpenApplication(ApplicationEvent event) {
783 }
784
785 @Override
786 public void handleOpenFile(ApplicationEvent event) {
787 }
788
789 @Override
790 public void handlePreferences(ApplicationEvent event) {
791 showSettings();
792 }
793
794 @Override
795 public void handlePrintFile(ApplicationEvent event) {
796 }
797
798 @Override
799 public void handleQuit(ApplicationEvent event) {
[605]800 event.setHandled(true);
801 saveLocalData();
802 exit();
[593]803 }
804
805 @Override
806 public void handleReOpenApplication(ApplicationEvent event) {
807 }
[600]808
[592]809}
Note: See TracBrowser for help on using the repository browser.