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