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