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