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.Date; |
13 |
import java.util.HashMap; |
14 |
import java.util.HashSet; |
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.JCheckBox; |
25 |
import javax.swing.JComboBox; |
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.JPanel; |
33 |
import javax.swing.JRadioButton; |
34 |
import javax.swing.JSplitPane; |
35 |
import javax.swing.SwingUtilities; |
36 |
import javax.swing.ToolTipManager; |
37 |
import javax.swing.filechooser.FileFilter; |
38 |
|
39 |
import net.oni2.aeinstaller.AEInstaller2; |
40 |
import net.oni2.aeinstaller.backend.AppExecution; |
41 |
import net.oni2.aeinstaller.backend.Paths; |
42 |
import net.oni2.aeinstaller.backend.Settings; |
43 |
import net.oni2.aeinstaller.backend.Settings.Platform; |
44 |
import net.oni2.aeinstaller.backend.SizeFormatter; |
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 |
long start = new Date().getTime(); |
168 |
|
169 |
try { |
170 |
DepotManager.getInstance().updateInformation(false); |
171 |
} catch (Exception e) { |
172 |
e.printStackTrace(); |
173 |
} |
174 |
|
175 |
System.out.println("Took: " + (new Date().getTime() - start) |
176 |
+ " msec"); |
177 |
} |
178 |
|
179 |
ModManager.getInstance().init(); |
180 |
tblMods.reloadData(); |
181 |
initModTypeBox(); |
182 |
|
183 |
tblMods.setVisible(true); |
184 |
} |
185 |
|
186 |
@SuppressWarnings("unused") |
187 |
private void checkUpdates(Object evtSource) { |
188 |
if ((evtSource != this) |
189 |
|| Settings.getInstance().get("notifyupdates", true)) { |
190 |
if (Settings.getInstance().isOfflineMode()) { |
191 |
if (evtSource != this) { |
192 |
JOptionPane.showMessageDialog(this, |
193 |
bundle.getString("offlineMode.text"), |
194 |
bundle.getString("offlineMode.title"), |
195 |
JOptionPane.WARNING_MESSAGE); |
196 |
} |
197 |
} else { |
198 |
TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods(); |
199 |
TreeSet<Mod> tools = ModManager.getInstance() |
200 |
.getUpdatableTools(); |
201 |
int size = 0; |
202 |
JPanel panPackages = new JPanel(new GridLayout(0, 1)); |
203 |
execUpdates = new TreeSet<Mod>(); |
204 |
execUpdates.addAll(mods); |
205 |
execUpdates.addAll(tools); |
206 |
for (final Mod m : mods) { |
207 |
size += m.getZipSize(); |
208 |
JCheckBox check = new JCheckBox("Mod: " + m.getName()); |
209 |
check.setSelected(true); |
210 |
check.addItemListener(new ItemListener() { |
211 |
@Override |
212 |
public void itemStateChanged(ItemEvent e) { |
213 |
if (e.getStateChange() == ItemEvent.SELECTED) |
214 |
execUpdates.add(m); |
215 |
else |
216 |
execUpdates.remove(m); |
217 |
} |
218 |
}); |
219 |
panPackages.add(check); |
220 |
} |
221 |
for (final Mod m : tools) { |
222 |
size += m.getZipSize(); |
223 |
JCheckBox check = new JCheckBox("Tool: " + m.getName()); |
224 |
check.setSelected(true); |
225 |
panPackages.add(check); |
226 |
} |
227 |
if (size > 0) { |
228 |
// Build info dialog content |
229 |
JPanel packages = new JPanel(new BorderLayout(0, 7)); |
230 |
JLabel lblIntro = new JLabel("<html>" |
231 |
+ bundle.getString("updatesAvailable.text") |
232 |
+ "</html>"); |
233 |
JLabel lblSize = new JLabel("<html>" |
234 |
+ String.format(bundle |
235 |
.getString("updatesAvailableSize.text"), |
236 |
SizeFormatter.format(size, 3)) + "</html>"); |
237 |
packages.add(lblIntro, BorderLayout.NORTH); |
238 |
packages.add(panPackages, BorderLayout.CENTER); |
239 |
packages.add(lblSize, BorderLayout.SOUTH); |
240 |
|
241 |
JPanel pan = new JPanel(new BorderLayout(0, 25)); |
242 |
pan.add(packages, BorderLayout.CENTER); |
243 |
JCheckBox checkFutureUpdates = new JCheckBox( |
244 |
bundle.getString("checkOnStartup.text")); |
245 |
checkFutureUpdates.setSelected(Settings.getInstance().get( |
246 |
"notifyupdates", true)); |
247 |
checkFutureUpdates.addItemListener(new ItemListener() { |
248 |
@Override |
249 |
public void itemStateChanged(ItemEvent evt) { |
250 |
Settings.getInstance().put("notifyupdates", |
251 |
evt.getStateChange() == ItemEvent.SELECTED); |
252 |
} |
253 |
}); |
254 |
pan.add(checkFutureUpdates, BorderLayout.SOUTH); |
255 |
|
256 |
// Show dialog |
257 |
int res = JOptionPane.showConfirmDialog(this, pan, |
258 |
bundle.getString("updatesAvailable.title"), |
259 |
JOptionPane.YES_NO_OPTION, |
260 |
JOptionPane.QUESTION_MESSAGE); |
261 |
if (res == JOptionPane.NO_OPTION) { |
262 |
execUpdates = null; |
263 |
} |
264 |
} |
265 |
} |
266 |
} |
267 |
} |
268 |
|
269 |
@SuppressWarnings("unused") |
270 |
private void doUpdate() { |
271 |
if (execUpdates != null && execUpdates.size() > 0) { |
272 |
Downloader dl = new Downloader(execUpdates); |
273 |
try { |
274 |
dl.setVisible(true); |
275 |
if (dl.isFinished()) { |
276 |
TreeSet<Integer> installed = Installer.getInstalledTools(); |
277 |
TreeSet<Mod> tools = new TreeSet<Mod>(); |
278 |
for (Mod m : execUpdates) |
279 |
if (m.isTool() |
280 |
&& installed.contains(m.getPackageNumber())) |
281 |
tools.add(m); |
282 |
if (tools.size() > 0) { |
283 |
Installer.installTools(tools); |
284 |
} |
285 |
} |
286 |
} finally { |
287 |
dl.dispose(); |
288 |
} |
289 |
} |
290 |
execUpdates = null; |
291 |
} |
292 |
|
293 |
@SuppressWarnings("unused") |
294 |
private void focus() { |
295 |
SwingUtilities.invokeLater(new Runnable() { |
296 |
|
297 |
@Override |
298 |
public void run() { |
299 |
toFront(); |
300 |
repaint(); |
301 |
} |
302 |
}); |
303 |
|
304 |
} |
305 |
|
306 |
private void showSettings() { |
307 |
new SettingsDialog().setVisible(true); |
308 |
} |
309 |
|
310 |
private void showAbout() { |
311 |
new AboutDialog().setVisible(true); |
312 |
} |
313 |
|
314 |
private JFileChooser getConfigOpenSaveDialog(boolean save) { |
315 |
JFileChooser fc = new JFileChooser(); |
316 |
fc.setCurrentDirectory(Paths.getEditionBasePath()); |
317 |
if (save) |
318 |
fc.setDialogType(JFileChooser.SAVE_DIALOG); |
319 |
else |
320 |
fc.setDialogType(JFileChooser.OPEN_DIALOG); |
321 |
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); |
322 |
fc.setFileFilter(new FileFilter() { |
323 |
@Override |
324 |
public String getDescription() { |
325 |
return "XML files"; |
326 |
} |
327 |
|
328 |
@Override |
329 |
public boolean accept(File arg0) { |
330 |
return (arg0.isDirectory()) |
331 |
|| (arg0.getName().toLowerCase().endsWith(".xml")); |
332 |
} |
333 |
}); |
334 |
fc.setMultiSelectionEnabled(false); |
335 |
return fc; |
336 |
} |
337 |
|
338 |
@SuppressWarnings("unused") |
339 |
private void loadConfig() { |
340 |
JFileChooser fc = getConfigOpenSaveDialog(false); |
341 |
int res = fc.showOpenDialog(this); |
342 |
if (res == JFileChooser.APPROVE_OPTION) { |
343 |
if (fc.getSelectedFile().exists()) |
344 |
tblMods.reloadSelection(fc.getSelectedFile()); |
345 |
} |
346 |
} |
347 |
|
348 |
@SuppressWarnings("unused") |
349 |
private void saveConfig() { |
350 |
JFileChooser fc = getConfigOpenSaveDialog(true); |
351 |
int res = fc.showSaveDialog(this); |
352 |
if (res == JFileChooser.APPROVE_OPTION) { |
353 |
File f = fc.getSelectedFile(); |
354 |
if (!f.getName().endsWith(".xml")) |
355 |
f = new File(f.getParentFile(), f.getName() + ".xml"); |
356 |
ModManager.getInstance().saveModSelection(f, |
357 |
tblMods.getSelectedMods()); |
358 |
} |
359 |
} |
360 |
|
361 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
362 |
private void reglobalize(final BackgroundEvent evt) { |
363 |
Installer.initializeEdition(new InstallProgressListener() { |
364 |
@Override |
365 |
public void installProgressUpdate(int done, int total, String step) { |
366 |
evt.setProgressEnd(total); |
367 |
evt.setProgressValue(done); |
368 |
evt.setProgressMessage(step); |
369 |
} |
370 |
}); |
371 |
} |
372 |
|
373 |
@SuppressWarnings("unused") |
374 |
private void tools() { |
375 |
new ToolManager().setVisible(true); |
376 |
} |
377 |
|
378 |
@SuppressWarnings("unused") |
379 |
private void refreshToolsMenu() { |
380 |
for (JMenuItem i : toolsMenuItems) { |
381 |
toolsMenu.remove(i); |
382 |
} |
383 |
toolsMenuItems.clear(); |
384 |
for (Mod m : ModManager.getInstance().getInstalledTools()) { |
385 |
if (m.getExeFile() != null && m.getExeFile().exists()) { |
386 |
JMenuItem item = new JMenuItem(); |
387 |
final Vector<String> params = new Vector<String>(); |
388 |
params.add(m.getExeFile().getPath()); |
389 |
final File wd = m.getWorkingDir(); |
390 |
Icon ico = null; |
391 |
if (m.getIconFile() != null && m.getIconFile().exists()) { |
392 |
ico = new ImageIcon(m.getIconFile().getPath()); |
393 |
} else { |
394 |
URL icon = AEInstaller2.class |
395 |
.getResource("images/transparent.png"); |
396 |
ico = new ImageIcon(icon); |
397 |
} |
398 |
item.setAction(new AbstractAction(m.getName(), ico) { |
399 |
private static final long serialVersionUID = 1L; |
400 |
|
401 |
@Override |
402 |
public void actionPerformed(ActionEvent e) { |
403 |
AppExecution.execute(params, wd); |
404 |
} |
405 |
}); |
406 |
toolsMenuItems.add(item); |
407 |
toolsMenu.add(item); |
408 |
} |
409 |
} |
410 |
} |
411 |
|
412 |
@SuppressWarnings("unused") |
413 |
private void revertSelection() { |
414 |
tblMods.revertSelection(); |
415 |
} |
416 |
|
417 |
@DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false) |
418 |
private void checkMandatoryFiles(final BackgroundEvent evt) { |
419 |
if (!Settings.getInstance().isOfflineMode()) { |
420 |
TreeSet<Mod> mand = new TreeSet<Mod>(); |
421 |
for (Mod m : ModManager.getInstance().getMandatoryTools()) { |
422 |
if (m.isNewerAvailable()) { |
423 |
mand.add(m); |
424 |
} |
425 |
} |
426 |
for (Mod m : ModManager.getInstance().getMandatoryMods()) { |
427 |
if (m.isNewerAvailable()) { |
428 |
mand.add(m); |
429 |
} |
430 |
} |
431 |
if (mand.size() > 0) { |
432 |
ModDownloader m = new ModDownloader(mand, |
433 |
new ModDownloaderListener() { |
434 |
@Override |
435 |
public void updateStatus(ModDownloader source, |
436 |
State state, int filesDown, int filesTotal, |
437 |
int bytesDown, int bytesTotal, |
438 |
int duration, int remaining, int speed) { |
439 |
evt.setProgressEnd(filesTotal); |
440 |
evt.setProgressValue(filesDown); |
441 |
} |
442 |
}); |
443 |
while (!m.isFinished()) { |
444 |
try { |
445 |
Thread.sleep(10); |
446 |
} catch (InterruptedException e) { |
447 |
e.printStackTrace(); |
448 |
} |
449 |
} |
450 |
} |
451 |
evt.setProgressMessage(bundle |
452 |
.getString("mandatoryToolsInstall.title")); |
453 |
Installer |
454 |
.installTools(ModManager.getInstance().getMandatoryTools()); |
455 |
} |
456 |
} |
457 |
|
458 |
@DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false) |
459 |
private void install(final BackgroundEvent evt) { |
460 |
TreeSet<Mod> mods = new TreeSet<Mod>(); |
461 |
mods.addAll(ModManager.getInstance().getMandatoryMods()); |
462 |
mods.addAll(tblMods.getSelectedMods()); |
463 |
|
464 |
boolean instReady = false; |
465 |
installDone = EInstallResult.DONE; |
466 |
|
467 |
while (!instReady) { |
468 |
TreeSet<Mod> toDownload = new TreeSet<Mod>(); |
469 |
for (Mod m : mods) { |
470 |
if (!m.isLocalAvailable()) |
471 |
toDownload.add(m); |
472 |
} |
473 |
if (Settings.getInstance().isOfflineMode()) { |
474 |
installDone = EInstallResult.OFFLINE; |
475 |
break; |
476 |
} |
477 |
if (toDownload.size() > 0) { |
478 |
Downloader dl = new Downloader(toDownload); |
479 |
try { |
480 |
dl.setVisible(true); |
481 |
if (!dl.isFinished()) |
482 |
break; |
483 |
} finally { |
484 |
dl.dispose(); |
485 |
} |
486 |
} |
487 |
HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance() |
488 |
.checkDependencies(mods); |
489 |
if (dependencies.size() > 0) { |
490 |
System.out.println("Unmet dependencies: " |
491 |
+ dependencies.toString()); |
492 |
for (Mod m : dependencies.keySet()) { |
493 |
for (Mod mDep : dependencies.get(m)) |
494 |
mods.add(mDep); |
495 |
} |
496 |
} else { |
497 |
HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance() |
498 |
.checkIncompabitilites(mods); |
499 |
if (conflicts.size() > 0) { |
500 |
installDone = EInstallResult.INCOMPATIBLE; |
501 |
System.err.println("Incompatible mods: " |
502 |
+ conflicts.toString()); |
503 |
break; |
504 |
} else { |
505 |
instReady = true; |
506 |
} |
507 |
} |
508 |
} |
509 |
|
510 |
if (instReady) { |
511 |
TreeSet<Mod> actuallyMods = new TreeSet<Mod>(); |
512 |
TreeSet<Mod> actuallyTools = new TreeSet<Mod>(); |
513 |
|
514 |
for (Mod m : mods) { |
515 |
if (m.isTool()) |
516 |
actuallyTools.add(m); |
517 |
else |
518 |
actuallyMods.add(m); |
519 |
} |
520 |
|
521 |
if (actuallyTools.size() > 0) { |
522 |
Installer.installTools(actuallyTools); |
523 |
} |
524 |
|
525 |
Installer.install(actuallyMods, new InstallProgressListener() { |
526 |
@Override |
527 |
public void installProgressUpdate(int done, int total, |
528 |
String step) { |
529 |
evt.setProgressEnd(total); |
530 |
evt.setProgressValue(done); |
531 |
evt.setProgressMessage(step); |
532 |
} |
533 |
}); |
534 |
installDone = EInstallResult.DONE; |
535 |
} |
536 |
} |
537 |
|
538 |
@SuppressWarnings("unused") |
539 |
private void installDone() { |
540 |
switch (installDone) { |
541 |
case DONE: |
542 |
JOptionPane.showMessageDialog(this, |
543 |
bundle.getString("installDone.text"), |
544 |
bundle.getString("installDone.title"), |
545 |
JOptionPane.INFORMATION_MESSAGE); |
546 |
break; |
547 |
case OFFLINE: |
548 |
JOptionPane.showMessageDialog(this, |
549 |
bundle.getString("offlineMode.text"), |
550 |
bundle.getString("offlineMode.title"), |
551 |
JOptionPane.WARNING_MESSAGE); |
552 |
break; |
553 |
case INCOMPATIBLE: |
554 |
break; |
555 |
} |
556 |
} |
557 |
|
558 |
@Override |
559 |
public void modSelectionChanged(ModTable source, Mod m) { |
560 |
lblSubmitterVal.setText(""); |
561 |
lblCreatorVal.setText(""); |
562 |
lblDescriptionVal.setText(""); |
563 |
lblTypesVal.setText(""); |
564 |
lblPlatformVal.setText(""); |
565 |
lblPackageNumberVal.setText(""); |
566 |
if (m != null) { |
567 |
lblSubmitterVal.setText(m.getName()); |
568 |
lblCreatorVal.setText(m.getCreator()); |
569 |
lblDescriptionVal.setText(m.getDescription()); |
570 |
|
571 |
String types = ""; |
572 |
for (Type t : m.getTypes()) { |
573 |
if (types.length() > 0) |
574 |
types += ", "; |
575 |
types += t.getName(); |
576 |
} |
577 |
lblTypesVal.setText(types); |
578 |
lblPlatformVal.setText(m.getPlatform().toString()); |
579 |
lblPackageNumberVal.setText(m.getPackageNumberString()); |
580 |
} |
581 |
} |
582 |
|
583 |
private void updateTableFilter() { |
584 |
Object o = cmbModTypes.getSelectedItem(); |
585 |
Type t = null; |
586 |
if (o instanceof Type) |
587 |
t = (Type) o; |
588 |
int downloadState = 0; |
589 |
if (radOnline.isSelected()) |
590 |
downloadState = 1; |
591 |
if (radLocal.isSelected()) |
592 |
downloadState = 2; |
593 |
tblMods.setFilter(t, downloadState); |
594 |
} |
595 |
|
596 |
@SuppressWarnings("unused") |
597 |
private void modTypeSelection() { |
598 |
updateTableFilter(); |
599 |
} |
600 |
|
601 |
@SuppressWarnings("unused") |
602 |
private void showTypeSelection() { |
603 |
updateTableFilter(); |
604 |
} |
605 |
|
606 |
@Override |
607 |
public void downloadSizeChanged(int newSize) { |
608 |
lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2)); |
609 |
} |
610 |
|
611 |
@SuppressWarnings("unused") |
612 |
private void checkInitialize() { |
613 |
if (!Installer.isEditionInitialized()) { |
614 |
if (!OniSplit.isOniSplitInstalled()) { |
615 |
JOptionPane.showMessageDialog(this, |
616 |
bundle.getString("noOniSplit.text"), |
617 |
bundle.getString("noOniSplit.title"), |
618 |
JOptionPane.ERROR_MESSAGE); |
619 |
exit(); |
620 |
} else { |
621 |
int res = JOptionPane |
622 |
.showConfirmDialog(this, |
623 |
bundle.getString("askInitialize.text"), |
624 |
bundle.getString("askInitialize.title"), |
625 |
JOptionPane.YES_NO_OPTION, |
626 |
JOptionPane.QUESTION_MESSAGE); |
627 |
if (res == JOptionPane.NO_OPTION) { |
628 |
saveLocalData(); |
629 |
exit(); |
630 |
} |
631 |
} |
632 |
} |
633 |
} |
634 |
|
635 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
636 |
private void initialize(final BackgroundEvent evt) { |
637 |
if (!Installer.isEditionInitialized()) { |
638 |
Installer.initializeEdition(new InstallProgressListener() { |
639 |
@Override |
640 |
public void installProgressUpdate(int done, int total, |
641 |
String step) { |
642 |
evt.setProgressEnd(total); |
643 |
evt.setProgressValue(done); |
644 |
evt.setProgressMessage(step); |
645 |
} |
646 |
}); |
647 |
} |
648 |
} |
649 |
|
650 |
private Vector<String> getBasicOniLaunchParams() { |
651 |
Vector<String> params = new Vector<String>(); |
652 |
File exe = null; |
653 |
switch (Settings.getPlatform()) { |
654 |
case WIN: |
655 |
exe = new File(Paths.getEditionBasePath(), "Oni.exe"); |
656 |
if (exe.exists()) |
657 |
params.add(exe.getPath()); |
658 |
break; |
659 |
case MACOS: |
660 |
exe = new File(Paths.getEditionBasePath(), |
661 |
"Oni.app/Contents/MacOS/Oni"); |
662 |
if (exe.exists()) |
663 |
params.add(exe.getPath()); |
664 |
break; |
665 |
case LINUX: |
666 |
String wine = Settings.getWinePath(); |
667 |
exe = new File(Paths.getEditionBasePath(), "Oni.exe"); |
668 |
if (exe.exists()) { |
669 |
if (wine != null) { |
670 |
params.add(wine); |
671 |
params.add(exe.getPath()); |
672 |
} |
673 |
} |
674 |
break; |
675 |
default: |
676 |
} |
677 |
if (params.size() > 0) { |
678 |
params.add("-debugfiles"); |
679 |
} |
680 |
return params; |
681 |
} |
682 |
|
683 |
@SuppressWarnings("unused") |
684 |
private void oniFull() { |
685 |
Vector<String> params = getBasicOniLaunchParams(); |
686 |
if (params.size() > 0) { |
687 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
688 |
} |
689 |
} |
690 |
|
691 |
@SuppressWarnings("unused") |
692 |
private void oniWin() { |
693 |
Vector<String> params = getBasicOniLaunchParams(); |
694 |
if (params.size() > 0) { |
695 |
params.add("-noswitch"); |
696 |
AppExecution.execute(params, Paths.getEditionBasePath()); |
697 |
} |
698 |
} |
699 |
|
700 |
@SuppressWarnings("unused") |
701 |
private void openEditionFolder() { |
702 |
try { |
703 |
Desktop.getDesktop().open(Paths.getEditionBasePath()); |
704 |
} catch (IOException e) { |
705 |
e.printStackTrace(); |
706 |
} |
707 |
} |
708 |
|
709 |
@Override |
710 |
public void handleAbout(ApplicationEvent event) { |
711 |
event.setHandled(true); |
712 |
showAbout(); |
713 |
} |
714 |
|
715 |
@Override |
716 |
public void handleOpenApplication(ApplicationEvent event) { |
717 |
} |
718 |
|
719 |
@Override |
720 |
public void handleOpenFile(ApplicationEvent event) { |
721 |
} |
722 |
|
723 |
@Override |
724 |
public void handlePreferences(ApplicationEvent event) { |
725 |
showSettings(); |
726 |
} |
727 |
|
728 |
@Override |
729 |
public void handlePrintFile(ApplicationEvent event) { |
730 |
} |
731 |
|
732 |
@Override |
733 |
public void handleQuit(ApplicationEvent event) { |
734 |
event.setHandled(true); |
735 |
saveLocalData(); |
736 |
exit(); |
737 |
} |
738 |
|
739 |
@Override |
740 |
public void handleReOpenApplication(ApplicationEvent event) { |
741 |
} |
742 |
|
743 |
} |