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