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.io.IOException; |
11 |
import java.net.URL; |
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.DepotCacheUpdateProgressListener; |
45 |
import net.oni2.aeinstaller.backend.depot.DepotManager; |
46 |
import net.oni2.aeinstaller.backend.mods.Mod; |
47 |
import net.oni2.aeinstaller.backend.mods.ModManager; |
48 |
import net.oni2.aeinstaller.backend.mods.Type; |
49 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloader; |
50 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State; |
51 |
import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener; |
52 |
import net.oni2.aeinstaller.backend.oni.InstallProgressListener; |
53 |
import net.oni2.aeinstaller.backend.oni.Installer; |
54 |
import net.oni2.aeinstaller.backend.oni.OniSplit; |
55 |
import net.oni2.aeinstaller.gui.about.AboutDialog; |
56 |
import net.oni2.aeinstaller.gui.downloadwindow.Downloader; |
57 |
import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener; |
58 |
import net.oni2.aeinstaller.gui.modtable.ModSelectionListener; |
59 |
import net.oni2.aeinstaller.gui.modtable.ModTable; |
60 |
import net.oni2.aeinstaller.gui.settings.SettingsDialog; |
61 |
import net.oni2.aeinstaller.gui.toolmanager.ToolManager; |
62 |
|
63 |
import org.javabuilders.BuildResult; |
64 |
import org.javabuilders.annotations.DoInBackground; |
65 |
import org.javabuilders.event.BackgroundEvent; |
66 |
import org.javabuilders.swing.SwingJavaBuilder; |
67 |
import org.simplericity.macify.eawt.ApplicationEvent; |
68 |
import org.simplericity.macify.eawt.ApplicationListener; |
69 |
|
70 |
/** |
71 |
* @author Christian Illy |
72 |
*/ |
73 |
public class MainWin extends JFrame implements ApplicationListener, |
74 |
DownloadSizeListener, ModSelectionListener { |
75 |
private static final long serialVersionUID = -4027395051382659650L; |
76 |
|
77 |
private ResourceBundle bundle = ResourceBundle |
78 |
.getBundle("net.oni2.aeinstaller.localization." |
79 |
+ getClass().getSimpleName()); |
80 |
@SuppressWarnings("unused") |
81 |
private BuildResult result = SwingJavaBuilder.build(this, bundle); |
82 |
|
83 |
private JMenu mainMenu; |
84 |
private JMenu toolsMenu; |
85 |
private TreeSet<JMenuItem> toolsMenuItems = new TreeSet<JMenuItem>(); |
86 |
|
87 |
private JSplitPane contents; |
88 |
|
89 |
private JComboBox cmbModTypes; |
90 |
private JRadioButton radAll; |
91 |
private JRadioButton radOnline; |
92 |
private JRadioButton radLocal; |
93 |
private ModTable tblMods; |
94 |
private JLabel lblDownloadSizeVal; |
95 |
|
96 |
private JLabel lblSubmitterVal; |
97 |
private JLabel lblCreatorVal; |
98 |
private JLabel lblTypesVal; |
99 |
private JLabel lblPlatformVal; |
100 |
private JLabel lblPackageNumberVal; |
101 |
private HTMLLinkLabel lblDescriptionVal; |
102 |
|
103 |
private JButton btnInstall; |
104 |
|
105 |
private TreeSet<Mod> execUpdates = null; |
106 |
|
107 |
private enum EInstallResult { |
108 |
DONE, |
109 |
OFFLINE, |
110 |
INCOMPATIBLE |
111 |
}; |
112 |
|
113 |
private EInstallResult installDone = EInstallResult.DONE; |
114 |
|
115 |
/** |
116 |
* Constructor of main window. |
117 |
*/ |
118 |
public MainWin() { |
119 |
this.setTitle(SwingJavaBuilder.getConfig().getResource("appname") |
120 |
+ " - v" |
121 |
+ SwingJavaBuilder.getConfig().getResource("appversion")); |
122 |
|
123 |
contents.setDividerLocation(400); |
124 |
contents.setResizeWeight(0.4); |
125 |
|
126 |
if (Settings.getPlatform() == Platform.MACOS) { |
127 |
mainMenu.setVisible(false); |
128 |
} |
129 |
|
130 |
ToolTipManager.sharedInstance().setInitialDelay(250); |
131 |
|
132 |
getRootPane().setDefaultButton(btnInstall); |
133 |
lblDownloadSizeVal.setText(SizeFormatter.format(0, 2)); |
134 |
radAll.setSelected(true); |
135 |
|
136 |
tblMods.addModSelectionListener(this); |
137 |
tblMods.addDownloadSizeListener(this); |
138 |
} |
139 |
|
140 |
private void initModTypeBox() { |
141 |
cmbModTypes.removeAllItems(); |
142 |
|
143 |
TreeMap<String, Type> types = new TreeMap<String, Type>(); |
144 |
for (Type t : ModManager.getInstance().getTypesWithContent()) { |
145 |
types.put(t.getName(), t); |
146 |
} |
147 |
cmbModTypes.addItem("-All-"); |
148 |
for (Type t : types.values()) { |
149 |
cmbModTypes.addItem(t); |
150 |
} |
151 |
cmbModTypes.setSelectedIndex(0); |
152 |
} |
153 |
|
154 |
private void exit() { |
155 |
dispose(); |
156 |
System.exit(0); |
157 |
} |
158 |
|
159 |
private void saveLocalData() { |
160 |
Settings.getInstance().serializeToFile(); |
161 |
DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename()); |
162 |
} |
163 |
|
164 |
@DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) |
165 |
private void execDepotUpdate(final BackgroundEvent evt) { |
166 |
if (!Settings.getInstance().isOfflineMode()) { |
167 |
try { |
168 |
DepotManager.getInstance().updateInformation(false, |
169 |
new DepotCacheUpdateProgressListener() { |
170 |
|
171 |
@Override |
172 |
public void cacheUpdateProgress(String stepName, |
173 |
int current, int total) { |
174 |
evt.setProgressEnd(total); |
175 |
evt.setProgressValue(current); |
176 |
evt.setProgressMessage(stepName); |
177 |
} |
178 |
}); |
179 |
} catch (Exception e) { |
180 |
e.printStackTrace(); |
181 |
} |
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 |
private void showSettings() { |
312 |
new SettingsDialog().setVisible(true); |
313 |
} |
314 |
|
315 |
private void showAbout() { |
316 |
new AboutDialog().setVisible(true); |
317 |
} |
318 |
|
319 |
private JFileChooser getConfigOpenSaveDialog(boolean save) { |
320 |
JFileChooser fc = new JFileChooser(); |
321 |
fc.setCurrentDirectory(Paths.getEditionBasePath()); |
322 |
if (save) |
323 |
fc.setDialogType(JFileChooser.SAVE_DIALOG); |
324 |
else |
325 |
fc.setDialogType(JFileChooser.OPEN_DIALOG); |
326 |
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); |
327 |
fc.setFileFilter(new FileFilter() { |
328 |
@Override |
329 |
public String getDescription() { |
330 |
return "XML files"; |
331 |
} |
332 |
|
333 |
@Override |
334 |
public boolean accept(File arg0) { |
335 |
return (arg0.isDirectory()) |
336 |
|| (arg0.getName().toLowerCase().endsWith(".xml")); |
337 |
} |
338 |
}); |
339 |
fc.setMultiSelectionEnabled(false); |
340 |
return fc; |
341 |
} |
342 |
|
343 |
@SuppressWarnings("unused") |
344 |
private void loadConfig() { |
345 |
JFileChooser fc = getConfigOpenSaveDialog(false); |
346 |
int res = fc.showOpenDialog(this); |
347 |
if (res == JFileChooser.APPROVE_OPTION) { |
348 |
if (fc.getSelectedFile().exists()) |
349 |
tblMods.reloadSelection(fc.getSelectedFile()); |
350 |
} |
351 |
} |
352 |
|
353 |
@SuppressWarnings("unused") |
354 |
private void saveConfig() { |
355 |
JFileChooser fc = getConfigOpenSaveDialog(true); |
356 |
int res = fc.showSaveDialog(this); |
357 |
if (res == JFileChooser.APPROVE_OPTION) { |
358 |
File f = fc.getSelectedFile(); |
359 |
if (!f.getName().endsWith(".xml")) |
360 |
f = new File(f.getParentFile(), f.getName() + ".xml"); |
361 |
ModManager.getInstance().saveModSelection(f, |
362 |
tblMods.getSelectedMods()); |
363 |
} |
364 |
} |
365 |
|
366 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
367 |
private void reglobalize(final BackgroundEvent evt) { |
368 |
Installer.initializeEdition(new InstallProgressListener() { |
369 |
@Override |
370 |
public void installProgressUpdate(int done, int total, String step) { |
371 |
evt.setProgressEnd(total); |
372 |
evt.setProgressValue(done); |
373 |
evt.setProgressMessage(step); |
374 |
} |
375 |
}); |
376 |
} |
377 |
|
378 |
@SuppressWarnings("unused") |
379 |
private void tools() { |
380 |
new ToolManager().setVisible(true); |
381 |
} |
382 |
|
383 |
@SuppressWarnings("unused") |
384 |
private void refreshToolsMenu() { |
385 |
for (JMenuItem i : toolsMenuItems) { |
386 |
toolsMenu.remove(i); |
387 |
} |
388 |
toolsMenuItems.clear(); |
389 |
for (Mod m : ModManager.getInstance().getInstalledTools()) { |
390 |
if (m.getExeFile() != null && m.getExeFile().exists()) { |
391 |
JMenuItem item = new JMenuItem(); |
392 |
final Vector<String> params = new Vector<String>(); |
393 |
params.add(m.getExeFile().getPath()); |
394 |
final File wd = m.getWorkingDir(); |
395 |
Icon ico = null; |
396 |
if (m.getIconFile() != null && m.getIconFile().exists()) { |
397 |
ico = new ImageIcon(m.getIconFile().getPath()); |
398 |
} else { |
399 |
URL icon = AEInstaller2.class |
400 |
.getResource("images/transparent.png"); |
401 |
ico = new ImageIcon(icon); |
402 |
} |
403 |
item.setAction(new AbstractAction(m.getName(), ico) { |
404 |
private static final long serialVersionUID = 1L; |
405 |
|
406 |
@Override |
407 |
public void actionPerformed(ActionEvent e) { |
408 |
AppExecution.execute(params, wd); |
409 |
} |
410 |
}); |
411 |
toolsMenuItems.add(item); |
412 |
toolsMenu.add(item); |
413 |
} |
414 |
} |
415 |
} |
416 |
|
417 |
@SuppressWarnings("unused") |
418 |
private void revertSelection() { |
419 |
tblMods.revertSelection(); |
420 |
} |
421 |
|
422 |
@DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false) |
423 |
private void checkMandatoryFiles(final BackgroundEvent evt) { |
424 |
if (!Settings.getInstance().isOfflineMode()) { |
425 |
TreeSet<Mod> mand = new TreeSet<Mod>(); |
426 |
for (Mod m : ModManager.getInstance().getMandatoryTools()) { |
427 |
if (m.isNewerAvailable()) { |
428 |
mand.add(m); |
429 |
} |
430 |
} |
431 |
for (Mod m : ModManager.getInstance().getMandatoryMods()) { |
432 |
if (m.isNewerAvailable()) { |
433 |
mand.add(m); |
434 |
} |
435 |
} |
436 |
if (mand.size() > 0) { |
437 |
ModDownloader m = new ModDownloader(mand, |
438 |
new ModDownloaderListener() { |
439 |
@Override |
440 |
public void updateStatus(ModDownloader source, |
441 |
State state, int filesDown, int filesTotal, |
442 |
int bytesDown, int bytesTotal, |
443 |
int duration, int remaining, int speed) { |
444 |
evt.setProgressEnd(filesTotal); |
445 |
evt.setProgressValue(filesDown); |
446 |
} |
447 |
}); |
448 |
while (!m.isFinished()) { |
449 |
try { |
450 |
Thread.sleep(10); |
451 |
} catch (InterruptedException e) { |
452 |
e.printStackTrace(); |
453 |
} |
454 |
} |
455 |
} |
456 |
evt.setProgressMessage(bundle |
457 |
.getString("mandatoryToolsInstall.title")); |
458 |
Installer |
459 |
.installTools(ModManager.getInstance().getMandatoryTools()); |
460 |
} |
461 |
} |
462 |
|
463 |
@DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false) |
464 |
private void install(final BackgroundEvent evt) { |
465 |
TreeSet<Mod> mods = new TreeSet<Mod>(); |
466 |
mods.addAll(ModManager.getInstance().getMandatoryMods()); |
467 |
mods.addAll(tblMods.getSelectedMods()); |
468 |
|
469 |
boolean instReady = false; |
470 |
installDone = EInstallResult.DONE; |
471 |
|
472 |
while (!instReady) { |
473 |
TreeSet<Mod> toDownload = new TreeSet<Mod>(); |
474 |
for (Mod m : mods) { |
475 |
if (!m.isLocalAvailable()) |
476 |
toDownload.add(m); |
477 |
} |
478 |
if (Settings.getInstance().isOfflineMode()) { |
479 |
installDone = EInstallResult.OFFLINE; |
480 |
break; |
481 |
} |
482 |
if (toDownload.size() > 0) { |
483 |
Downloader dl = new Downloader(toDownload); |
484 |
try { |
485 |
dl.setVisible(true); |
486 |
if (!dl.isFinished()) |
487 |
break; |
488 |
} finally { |
489 |
dl.dispose(); |
490 |
} |
491 |
} |
492 |
HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance() |
493 |
.checkDependencies(mods); |
494 |
if (dependencies.size() > 0) { |
495 |
System.out.println("Unmet dependencies: " |
496 |
+ dependencies.toString()); |
497 |
for (Mod m : dependencies.keySet()) { |
498 |
for (Mod mDep : dependencies.get(m)) |
499 |
mods.add(mDep); |
500 |
} |
501 |
} else { |
502 |
HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance() |
503 |
.checkIncompabitilites(mods); |
504 |
if (conflicts.size() > 0) { |
505 |
installDone = EInstallResult.INCOMPATIBLE; |
506 |
System.err.println("Incompatible mods: " |
507 |
+ conflicts.toString()); |
508 |
break; |
509 |
} else { |
510 |
instReady = true; |
511 |
} |
512 |
} |
513 |
} |
514 |
|
515 |
if (instReady) { |
516 |
TreeSet<Mod> actuallyMods = new TreeSet<Mod>(); |
517 |
TreeSet<Mod> actuallyTools = new TreeSet<Mod>(); |
518 |
|
519 |
for (Mod m : mods) { |
520 |
if (m.isTool()) |
521 |
actuallyTools.add(m); |
522 |
else |
523 |
actuallyMods.add(m); |
524 |
} |
525 |
|
526 |
if (actuallyTools.size() > 0) { |
527 |
Installer.installTools(actuallyTools); |
528 |
} |
529 |
|
530 |
Installer.install(actuallyMods, new InstallProgressListener() { |
531 |
@Override |
532 |
public void installProgressUpdate(int done, int total, |
533 |
String step) { |
534 |
evt.setProgressEnd(total); |
535 |
evt.setProgressValue(done); |
536 |
evt.setProgressMessage(step); |
537 |
} |
538 |
}); |
539 |
installDone = EInstallResult.DONE; |
540 |
} |
541 |
} |
542 |
|
543 |
@SuppressWarnings("unused") |
544 |
private void installDone() { |
545 |
switch (installDone) { |
546 |
case DONE: |
547 |
JOptionPane.showMessageDialog(this, |
548 |
bundle.getString("installDone.text"), |
549 |
bundle.getString("installDone.title"), |
550 |
JOptionPane.INFORMATION_MESSAGE); |
551 |
break; |
552 |
case OFFLINE: |
553 |
JOptionPane.showMessageDialog(this, |
554 |
bundle.getString("offlineMode.text"), |
555 |
bundle.getString("offlineMode.title"), |
556 |
JOptionPane.WARNING_MESSAGE); |
557 |
break; |
558 |
case INCOMPATIBLE: |
559 |
break; |
560 |
} |
561 |
} |
562 |
|
563 |
@Override |
564 |
public void modSelectionChanged(ModTable source, Mod m) { |
565 |
lblSubmitterVal.setText(""); |
566 |
lblCreatorVal.setText(""); |
567 |
lblDescriptionVal.setText(""); |
568 |
lblTypesVal.setText(""); |
569 |
lblPlatformVal.setText(""); |
570 |
lblPackageNumberVal.setText(""); |
571 |
if (m != null) { |
572 |
lblSubmitterVal.setText(m.getName()); |
573 |
lblCreatorVal.setText(m.getCreator()); |
574 |
lblDescriptionVal.setText(m.getDescription()); |
575 |
|
576 |
String types = ""; |
577 |
for (Type t : m.getTypes()) { |
578 |
if (types.length() > 0) |
579 |
types += ", "; |
580 |
types += t.getName(); |
581 |
} |
582 |
lblTypesVal.setText(types); |
583 |
lblPlatformVal.setText(m.getPlatform().toString()); |
584 |
lblPackageNumberVal.setText(m.getPackageNumberString()); |
585 |
} |
586 |
} |
587 |
|
588 |
private void updateTableFilter() { |
589 |
Object o = cmbModTypes.getSelectedItem(); |
590 |
Type t = null; |
591 |
if (o instanceof Type) |
592 |
t = (Type) o; |
593 |
int downloadState = 0; |
594 |
if (radOnline.isSelected()) |
595 |
downloadState = 1; |
596 |
if (radLocal.isSelected()) |
597 |
downloadState = 2; |
598 |
tblMods.setFilter(t, downloadState); |
599 |
} |
600 |
|
601 |
@SuppressWarnings("unused") |
602 |
private void modTypeSelection() { |
603 |
updateTableFilter(); |
604 |
} |
605 |
|
606 |
@SuppressWarnings("unused") |
607 |
private void showTypeSelection() { |
608 |
updateTableFilter(); |
609 |
} |
610 |
|
611 |
@Override |
612 |
public void downloadSizeChanged(int newSize) { |
613 |
lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2)); |
614 |
} |
615 |
|
616 |
@SuppressWarnings("unused") |
617 |
private void checkInitialize() { |
618 |
if (!Installer.isEditionInitialized()) { |
619 |
if (!OniSplit.isOniSplitInstalled()) { |
620 |
JOptionPane.showMessageDialog(this, |
621 |
bundle.getString("noOniSplit.text"), |
622 |
bundle.getString("noOniSplit.title"), |
623 |
JOptionPane.ERROR_MESSAGE); |
624 |
exit(); |
625 |
} else { |
626 |
int res = JOptionPane |
627 |
.showConfirmDialog(this, |
628 |
bundle.getString("askInitialize.text"), |
629 |
bundle.getString("askInitialize.title"), |
630 |
JOptionPane.YES_NO_OPTION, |
631 |
JOptionPane.QUESTION_MESSAGE); |
632 |
if (res == JOptionPane.NO_OPTION) { |
633 |
saveLocalData(); |
634 |
exit(); |
635 |
} |
636 |
} |
637 |
} |
638 |
} |
639 |
|
640 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
641 |
private void initialize(final BackgroundEvent evt) { |
642 |
if (!Installer.isEditionInitialized()) { |
643 |
Installer.initializeEdition(new InstallProgressListener() { |
644 |
@Override |
645 |
public void installProgressUpdate(int done, int total, |
646 |
String step) { |
647 |
evt.setProgressEnd(total); |
648 |
evt.setProgressValue(done); |
649 |
evt.setProgressMessage(step); |
650 |
} |
651 |
}); |
652 |
} |
653 |
} |
654 |
|
655 |
private Vector<String> getBasicOniLaunchParams() { |
656 |
Vector<String> params = new Vector<String>(); |
657 |
File exe = null; |
658 |
switch (Settings.getPlatform()) { |
659 |
case WIN: |
660 |
exe = new File(Paths.getEditionBasePath(), "Oni.exe"); |
661 |
if (exe.exists()) |
662 |
params.add(exe.getPath()); |
663 |
break; |
664 |
case MACOS: |
665 |
exe = new File(Paths.getEditionBasePath(), |
666 |
"Oni.app/Contents/MacOS/Oni"); |
667 |
if (exe.exists()) |
668 |
params.add(exe.getPath()); |
669 |
break; |
670 |
case LINUX: |
671 |
String wine = Settings.getWinePath(); |
672 |
exe = new File(Paths.getEditionBasePath(), "Oni.exe"); |
673 |
if (exe.exists()) { |
674 |
if (wine != null) { |
675 |
params.add(wine); |
676 |
params.add(exe.getPath()); |
677 |
} |
678 |
} |
679 |
break; |
680 |
default: |
681 |
} |
682 |
if (params.size() > 0) { |
683 |
params.add("-debugfiles"); |
684 |
} |
685 |
return params; |
686 |
} |
687 |
|
688 |
@SuppressWarnings("unused") |
689 |
private void oniFull() { |
690 |
Vector<String> params = getBasicOniLaunchParams(); |
691 |
if (params.size() > 0) { |
692 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
693 |
} |
694 |
} |
695 |
|
696 |
@SuppressWarnings("unused") |
697 |
private void oniWin() { |
698 |
Vector<String> params = getBasicOniLaunchParams(); |
699 |
if (params.size() > 0) { |
700 |
params.add("-noswitch"); |
701 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
702 |
} |
703 |
} |
704 |
|
705 |
@SuppressWarnings("unused") |
706 |
private void openEditionFolder() { |
707 |
try { |
708 |
Desktop.getDesktop().open(Paths.getEditionBasePath()); |
709 |
} catch (IOException e) { |
710 |
e.printStackTrace(); |
711 |
} |
712 |
} |
713 |
|
714 |
@Override |
715 |
public void handleAbout(ApplicationEvent event) { |
716 |
event.setHandled(true); |
717 |
showAbout(); |
718 |
} |
719 |
|
720 |
@Override |
721 |
public void handleOpenApplication(ApplicationEvent event) { |
722 |
} |
723 |
|
724 |
@Override |
725 |
public void handleOpenFile(ApplicationEvent event) { |
726 |
} |
727 |
|
728 |
@Override |
729 |
public void handlePreferences(ApplicationEvent event) { |
730 |
showSettings(); |
731 |
} |
732 |
|
733 |
@Override |
734 |
public void handlePrintFile(ApplicationEvent event) { |
735 |
} |
736 |
|
737 |
@Override |
738 |
public void handleQuit(ApplicationEvent event) { |
739 |
event.setHandled(true); |
740 |
saveLocalData(); |
741 |
exit(); |
742 |
} |
743 |
|
744 |
@Override |
745 |
public void handleReOpenApplication(ApplicationEvent event) { |
746 |
} |
747 |
|
748 |
} |