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