1 |
package net.oni2.aeinstaller.gui; |
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Desktop; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.awt.event.ItemEvent; |
8 |
import java.awt.event.ItemListener; |
9 |
import java.awt.event.MouseAdapter; |
10 |
import java.awt.event.MouseEvent; |
11 |
import java.io.File; |
12 |
import java.io.IOException; |
13 |
import java.net.URL; |
14 |
import java.util.ArrayList; |
15 |
import java.util.HashMap; |
16 |
import java.util.HashSet; |
17 |
import java.util.List; |
18 |
import java.util.ResourceBundle; |
19 |
import java.util.TreeMap; |
20 |
import java.util.TreeSet; |
21 |
import java.util.Vector; |
22 |
|
23 |
import javax.swing.AbstractAction; |
24 |
import javax.swing.Icon; |
25 |
import javax.swing.ImageIcon; |
26 |
import javax.swing.JButton; |
27 |
import javax.swing.JCheckBox; |
28 |
import javax.swing.JComboBox; |
29 |
import javax.swing.JComponent; |
30 |
import javax.swing.JFileChooser; |
31 |
import javax.swing.JFrame; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JMenu; |
34 |
import javax.swing.JMenuItem; |
35 |
import javax.swing.JOptionPane; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JPopupMenu; |
38 |
import javax.swing.JSplitPane; |
39 |
import javax.swing.JTable; |
40 |
import javax.swing.ListSelectionModel; |
41 |
import javax.swing.RowSorter; |
42 |
import javax.swing.SortOrder; |
43 |
import javax.swing.SwingUtilities; |
44 |
import javax.swing.event.ListSelectionEvent; |
45 |
import javax.swing.event.ListSelectionListener; |
46 |
import javax.swing.filechooser.FileFilter; |
47 |
import javax.swing.table.TableRowSorter; |
48 |
|
49 |
import net.oni2.aeinstaller.AEInstaller2; |
50 |
import net.oni2.aeinstaller.backend.AppExecution; |
51 |
import net.oni2.aeinstaller.backend.Paths; |
52 |
import net.oni2.aeinstaller.backend.Settings; |
53 |
import net.oni2.aeinstaller.backend.Settings.Platform; |
54 |
import net.oni2.aeinstaller.backend.SizeFormatter; |
55 |
import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener; |
56 |
import net.oni2.aeinstaller.backend.depot.DepotManager; |
57 |
import net.oni2.aeinstaller.backend.mods.Mod; |
58 |
import net.oni2.aeinstaller.backend.mods.ModManager; |
59 |
import net.oni2.aeinstaller.backend.mods.Type; |
60 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloader; |
61 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State; |
62 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener; |
63 |
import net.oni2.aeinstaller.backend.oni.InstallProgressListener; |
64 |
import net.oni2.aeinstaller.backend.oni.Installer; |
65 |
import net.oni2.aeinstaller.backend.oni.OniSplit; |
66 |
import net.oni2.aeinstaller.gui.about.AboutDialog; |
67 |
import net.oni2.aeinstaller.gui.downloadwindow.Downloader; |
68 |
import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener; |
69 |
import net.oni2.aeinstaller.gui.modtable.ModTableFilter; |
70 |
import net.oni2.aeinstaller.gui.modtable.ModTableModel; |
71 |
import net.oni2.aeinstaller.gui.settings.SettingsDialog; |
72 |
import net.oni2.aeinstaller.gui.toolmanager.ToolManager; |
73 |
|
74 |
import org.javabuilders.BuildResult; |
75 |
import org.javabuilders.annotations.DoInBackground; |
76 |
import org.javabuilders.event.BackgroundEvent; |
77 |
import org.javabuilders.swing.SwingJavaBuilder; |
78 |
import org.simplericity.macify.eawt.ApplicationEvent; |
79 |
import org.simplericity.macify.eawt.ApplicationListener; |
80 |
|
81 |
/** |
82 |
* @author Christian Illy |
83 |
*/ |
84 |
public class MainWin extends JFrame implements ApplicationListener, |
85 |
DownloadSizeListener { |
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 |
|
93 |
private JMenu mainMenu; |
94 |
private JMenu toolsMenu; |
95 |
private TreeSet<JMenuItem> toolsMenuItems = new TreeSet<JMenuItem>(); |
96 |
|
97 |
private JSplitPane contents; |
98 |
|
99 |
private JComboBox cmbModTypes; |
100 |
private JTable tblMods; |
101 |
private ModTableModel model; |
102 |
private TableRowSorter<ModTableModel> sorter; |
103 |
private JLabel lblDownloadSizeVal; |
104 |
|
105 |
private JLabel lblSubmitterVal; |
106 |
private JLabel lblCreatorVal; |
107 |
private JLabel lblTypesVal; |
108 |
private JLabel lblPlatformVal; |
109 |
private JLabel lblPackageNumberVal; |
110 |
private HTMLLinkLabel lblDescriptionVal; |
111 |
|
112 |
private JButton btnInstall; |
113 |
|
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 |
|
124 |
/** |
125 |
* Constructor of main window. |
126 |
*/ |
127 |
public MainWin() { |
128 |
this.setTitle(SwingJavaBuilder.getConfig().getResource("appname") |
129 |
+ " - v" |
130 |
+ SwingJavaBuilder.getConfig().getResource("appversion")); |
131 |
|
132 |
contents.setDividerLocation(400); |
133 |
|
134 |
if (Settings.getPlatform() == Platform.MACOS) { |
135 |
mainMenu.setVisible(false); |
136 |
} |
137 |
|
138 |
getRootPane().setDefaultButton(btnInstall); |
139 |
lblDownloadSizeVal.setText(SizeFormatter.format(0, 2)); |
140 |
} |
141 |
|
142 |
private void initModTypeBox() { |
143 |
cmbModTypes.removeAllItems(); |
144 |
|
145 |
TreeMap<String, Type> types = new TreeMap<String, Type>(); |
146 |
for (Type t : ModManager.getInstance().getTypesWithContent()) { |
147 |
types.put(t.getName(), t); |
148 |
} |
149 |
for (Type t : types.values()) { |
150 |
cmbModTypes.addItem(t); |
151 |
} |
152 |
cmbModTypes.setSelectedIndex(0); |
153 |
} |
154 |
|
155 |
private void initTable() { |
156 |
tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
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); |
167 |
Mod mod = (Mod) model.getValueAt(modelRow, -1); |
168 |
modSelection(mod); |
169 |
} |
170 |
} |
171 |
}); |
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(); |
179 |
|
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 |
}); |
221 |
// To get checkbox-cells with background of row |
222 |
((JComponent) tblMods.getDefaultRenderer(Boolean.class)) |
223 |
.setOpaque(true); |
224 |
|
225 |
model = new ModTableModel(); |
226 |
model.addDownloadSizeListener(this); |
227 |
|
228 |
tblMods.setModel(model); |
229 |
|
230 |
sorter = new TableRowSorter<ModTableModel>(model); |
231 |
tblMods.setRowSorter(sorter); |
232 |
|
233 |
sorter.setRowFilter(new ModTableFilter(null)); |
234 |
|
235 |
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); |
236 |
sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING)); |
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(); |
246 |
System.exit(0); |
247 |
} |
248 |
|
249 |
private void saveLocalData() { |
250 |
Settings.getInstance().serializeToFile(); |
251 |
DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename()); |
252 |
} |
253 |
|
254 |
@DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) |
255 |
private void execDepotUpdate(final BackgroundEvent evt) { |
256 |
if (!Settings.getInstance().isOfflineMode()) { |
257 |
try { |
258 |
DepotManager.getInstance().updateInformation(false, |
259 |
new DepotCacheUpdateProgressListener() { |
260 |
|
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(); |
276 |
|
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 |
} |
310 |
if (size > 0) { |
311 |
// Build info dialog content |
312 |
String message = "<html>"; |
313 |
message += String.format( |
314 |
bundle.getString("updatesAvailable.text"), strMods, |
315 |
strTools, SizeFormatter.format(size, 3)); |
316 |
message += "</html>"; |
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, |
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 |
} |
345 |
} |
346 |
} |
347 |
} |
348 |
} |
349 |
|
350 |
@SuppressWarnings("unused") |
351 |
private void doUpdate() { |
352 |
if (execUpdates != null) { |
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 |
} |
370 |
} |
371 |
execUpdates = null; |
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() { |
388 |
new SettingsDialog().setVisible(true); |
389 |
} |
390 |
|
391 |
private void showAbout() { |
392 |
new AboutDialog().setVisible(true); |
393 |
} |
394 |
|
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 |
|
419 |
@SuppressWarnings("unused") |
420 |
private void loadConfig() { |
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 |
} |
427 |
} |
428 |
|
429 |
@SuppressWarnings("unused") |
430 |
private void saveConfig() { |
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 |
} |
440 |
} |
441 |
|
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 |
|
454 |
@SuppressWarnings("unused") |
455 |
private void tools() { |
456 |
new ToolManager().setVisible(true); |
457 |
} |
458 |
|
459 |
@SuppressWarnings("unused") |
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 { |
475 |
URL icon = AEInstaller2.class |
476 |
.getResource("images/transparent.png"); |
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") |
494 |
private void revertSelection() { |
495 |
model.revertSelection(); |
496 |
} |
497 |
|
498 |
@DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false) |
499 |
private void checkMandatoryFiles(final BackgroundEvent evt) { |
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 |
} |
506 |
} |
507 |
for (Mod m : ModManager.getInstance().getMandatoryMods()) { |
508 |
if (m.isNewerAvailable()) { |
509 |
mand.add(m); |
510 |
} |
511 |
} |
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 |
} |
530 |
} |
531 |
} |
532 |
evt.setProgressMessage(bundle |
533 |
.getString("mandatoryToolsInstall.title")); |
534 |
Installer |
535 |
.installTools(ModManager.getInstance().getMandatoryTools()); |
536 |
} |
537 |
} |
538 |
|
539 |
@DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false) |
540 |
private void install(final BackgroundEvent evt) { |
541 |
TreeSet<Mod> mods = new TreeSet<Mod>(); |
542 |
mods.addAll(ModManager.getInstance().getMandatoryMods()); |
543 |
mods.addAll(model.getSelectedMods()); |
544 |
|
545 |
boolean instReady = false; |
546 |
installDone = EInstallResult.DONE; |
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 |
} |
554 |
if (Settings.getInstance().isOfflineMode()) { |
555 |
installDone = EInstallResult.OFFLINE; |
556 |
break; |
557 |
} |
558 |
if (toDownload.size() > 0) { |
559 |
Downloader dl = new Downloader(toDownload); |
560 |
try { |
561 |
dl.setVisible(true); |
562 |
if (!dl.isFinished()) |
563 |
break; |
564 |
} finally { |
565 |
dl.dispose(); |
566 |
} |
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() |
579 |
.checkIncompabitilites(mods); |
580 |
if (conflicts.size() > 0) { |
581 |
installDone = EInstallResult.INCOMPATIBLE; |
582 |
System.err.println("Incompatible mods: " |
583 |
+ conflicts.toString()); |
584 |
break; |
585 |
} else { |
586 |
instReady = true; |
587 |
} |
588 |
} |
589 |
} |
590 |
|
591 |
if (instReady) { |
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() { |
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 |
}); |
615 |
installDone = EInstallResult.DONE; |
616 |
} |
617 |
} |
618 |
|
619 |
@SuppressWarnings("unused") |
620 |
private void installDone() { |
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 |
} |
637 |
} |
638 |
|
639 |
private void modSelection(Mod m) { |
640 |
lblSubmitterVal.setText(""); |
641 |
lblCreatorVal.setText(""); |
642 |
lblDescriptionVal.setText(""); |
643 |
lblTypesVal.setText(""); |
644 |
lblPlatformVal.setText(""); |
645 |
lblPackageNumberVal.setText(""); |
646 |
if (m != null) { |
647 |
lblSubmitterVal.setText(m.getName()); |
648 |
lblCreatorVal.setText(m.getCreator()); |
649 |
lblDescriptionVal.setText(m.getDescription()); |
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()); |
659 |
lblPackageNumberVal.setText(m.getPackageNumberString()); |
660 |
} |
661 |
} |
662 |
|
663 |
@SuppressWarnings("unused") |
664 |
private void modTypeSelection() { |
665 |
Type t = (Type) cmbModTypes.getSelectedItem(); |
666 |
if (t != null) |
667 |
sorter.setRowFilter(new ModTableFilter(t)); |
668 |
else |
669 |
sorter.setRowFilter(new ModTableFilter(null)); |
670 |
} |
671 |
|
672 |
@Override |
673 |
public void downloadSizeChanged(int newSize) { |
674 |
lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2)); |
675 |
} |
676 |
|
677 |
@SuppressWarnings("unused") |
678 |
private void checkInitialize() { |
679 |
if (!Installer.isEditionInitialized()) { |
680 |
if (!OniSplit.isOniSplitInstalled()) { |
681 |
JOptionPane.showMessageDialog(this, |
682 |
bundle.getString("noOniSplit.text"), |
683 |
bundle.getString("noOniSplit.title"), |
684 |
JOptionPane.ERROR_MESSAGE); |
685 |
exit(); |
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 |
} |
697 |
} |
698 |
} |
699 |
} |
700 |
|
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 |
|
716 |
private Vector<String> getBasicOniLaunchParams() { |
717 |
Vector<String> params = new Vector<String>(); |
718 |
File exe = null; |
719 |
switch (Settings.getPlatform()) { |
720 |
case WIN: |
721 |
exe = new File(Paths.getEditionBasePath(), "Oni.exe"); |
722 |
if (exe.exists()) |
723 |
params.add(exe.getPath()); |
724 |
break; |
725 |
case MACOS: |
726 |
exe = new File(Paths.getEditionBasePath(), |
727 |
"Oni.app/Contents/MacOS/Oni"); |
728 |
if (exe.exists()) |
729 |
params.add(exe.getPath()); |
730 |
break; |
731 |
case LINUX: |
732 |
String wine = Settings.getWinePath(); |
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 |
} |
739 |
} |
740 |
break; |
741 |
default: |
742 |
} |
743 |
if (params.size() > 0) { |
744 |
params.add("-debugfiles"); |
745 |
} |
746 |
return params; |
747 |
} |
748 |
|
749 |
@SuppressWarnings("unused") |
750 |
private void oniFull() { |
751 |
Vector<String> params = getBasicOniLaunchParams(); |
752 |
if (params.size() > 0) { |
753 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
754 |
} |
755 |
} |
756 |
|
757 |
@SuppressWarnings("unused") |
758 |
private void oniWin() { |
759 |
Vector<String> params = getBasicOniLaunchParams(); |
760 |
if (params.size() > 0) { |
761 |
params.add("-noswitch"); |
762 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
763 |
} |
764 |
} |
765 |
|
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 |
|
775 |
@Override |
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) { |
800 |
event.setHandled(true); |
801 |
saveLocalData(); |
802 |
exit(); |
803 |
} |
804 |
|
805 |
@Override |
806 |
public void handleReOpenApplication(ApplicationEvent event) { |
807 |
} |
808 |
|
809 |
} |