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