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.awt.event.KeyAdapter; |
10 |
import java.awt.event.KeyEvent; |
11 |
import java.io.File; |
12 |
import java.io.FileNotFoundException; |
13 |
import java.net.URL; |
14 |
import java.util.Date; |
15 |
import java.util.HashMap; |
16 |
import java.util.HashSet; |
17 |
import java.util.ResourceBundle; |
18 |
import java.util.TreeMap; |
19 |
import java.util.TreeSet; |
20 |
import java.util.Vector; |
21 |
|
22 |
import javax.swing.AbstractAction; |
23 |
import javax.swing.ImageIcon; |
24 |
import javax.swing.JButton; |
25 |
import javax.swing.JCheckBox; |
26 |
import javax.swing.JComboBox; |
27 |
import javax.swing.JFileChooser; |
28 |
import javax.swing.JFrame; |
29 |
import javax.swing.JLabel; |
30 |
import javax.swing.JMenu; |
31 |
import javax.swing.JMenuItem; |
32 |
import javax.swing.JOptionPane; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.JRadioButton; |
35 |
import javax.swing.JScrollPane; |
36 |
import javax.swing.JSplitPane; |
37 |
import javax.swing.JTextField; |
38 |
import javax.swing.SwingUtilities; |
39 |
import javax.swing.ToolTipManager; |
40 |
import javax.swing.filechooser.FileFilter; |
41 |
|
42 |
import net.oni2.SettingsManager; |
43 |
import net.oni2.aeinstaller.AEInstaller2; |
44 |
import net.oni2.aeinstaller.backend.ImageResizer; |
45 |
import net.oni2.aeinstaller.backend.Paths; |
46 |
import net.oni2.aeinstaller.backend.SizeFormatter; |
47 |
import net.oni2.aeinstaller.backend.depot.DepotManager; |
48 |
import net.oni2.aeinstaller.backend.oni.InstallProgressListener; |
49 |
import net.oni2.aeinstaller.backend.oni.Installer; |
50 |
import net.oni2.aeinstaller.backend.oni.OniLauncher; |
51 |
import net.oni2.aeinstaller.backend.oni.OniSplit; |
52 |
import net.oni2.aeinstaller.backend.packages.Package; |
53 |
import net.oni2.aeinstaller.backend.packages.PackageManager; |
54 |
import net.oni2.aeinstaller.backend.packages.Type; |
55 |
import net.oni2.aeinstaller.backend.packages.download.ModDownloader; |
56 |
import net.oni2.aeinstaller.backend.packages.download.ModDownloader.State; |
57 |
import net.oni2.aeinstaller.backend.packages.download.ModDownloaderListener; |
58 |
import net.oni2.aeinstaller.gui.about.AboutDialog; |
59 |
import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog; |
60 |
import net.oni2.aeinstaller.gui.downloadwindow.Downloader; |
61 |
import net.oni2.aeinstaller.gui.modtable.EApplyFilterTo; |
62 |
import net.oni2.aeinstaller.gui.modtable.ModInstallSelectionListener; |
63 |
import net.oni2.aeinstaller.gui.modtable.ModSelectionListener; |
64 |
import net.oni2.aeinstaller.gui.modtable.ModTable; |
65 |
import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType; |
66 |
import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox; |
67 |
import net.oni2.aeinstaller.gui.settings.SettingsDialog; |
68 |
import net.oni2.aeinstaller.gui.toolmanager.ToolManager; |
69 |
import net.oni2.platformtools.PlatformInformation; |
70 |
import net.oni2.platformtools.PlatformInformation.Platform; |
71 |
import net.oni2.platformtools.applicationinvoker.ApplicationInvoker; |
72 |
import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException; |
73 |
|
74 |
import org.javabuilders.BuildResult; |
75 |
import org.javabuilders.annotations.DoInBackground; |
76 |
import org.javabuilders.event.BackgroundEvent; |
77 |
import org.javabuilders.swing.SwingJavaBuilder; |
78 |
import org.simplericity.macify.eawt.ApplicationEvent; |
79 |
import org.simplericity.macify.eawt.ApplicationListener; |
80 |
|
81 |
/** |
82 |
* @author Christian Illy |
83 |
*/ |
84 |
public class MainWin extends JFrame implements ApplicationListener, |
85 |
ModInstallSelectionListener, ModSelectionListener { |
86 |
private static final long serialVersionUID = -4027395051382659650L; |
87 |
|
88 |
private ResourceBundle bundle = ResourceBundle |
89 |
.getBundle("net.oni2.aeinstaller.localization." |
90 |
+ getClass().getSimpleName()); |
91 |
@SuppressWarnings("unused") |
92 |
private BuildResult result = SwingJavaBuilder.build(this, bundle); |
93 |
|
94 |
private JMenu mainMenu; |
95 |
private JMenu toolsMenu; |
96 |
private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>(); |
97 |
|
98 |
private JSplitPane contents; |
99 |
|
100 |
private JComboBox cmbModTypes; |
101 |
private JRadioButton radAll; |
102 |
private JRadioButton radOnline; |
103 |
private JRadioButton radLocal; |
104 |
private JTextField txtShowFilter; |
105 |
private JComboBox cmbShowFilterTo; |
106 |
private JScrollPane scrollMods; |
107 |
private ModTable tblMods; |
108 |
private JLabel lblSelectedModsVal; |
109 |
private JLabel lblDownloadSizeVal; |
110 |
|
111 |
private PackageInfoBox pkgInfo; |
112 |
|
113 |
private JButton btnInstall; |
114 |
|
115 |
private TreeSet<Package> execCoreUpdates = new TreeSet<Package>(); |
116 |
private TreeSet<Package> execUpdates = null; |
117 |
|
118 |
private enum EInstallState { |
119 |
DONE, |
120 |
READY, |
121 |
ABORTED, |
122 |
OFFLINE, |
123 |
INCOMPATIBLE, |
124 |
CHECKING |
125 |
}; |
126 |
|
127 |
private EInstallState installState = EInstallState.DONE; |
128 |
private TreeSet<Package> installMods = null; |
129 |
private TreeSet<Package> installDeps = null; |
130 |
|
131 |
/** |
132 |
* Constructor of main window. |
133 |
*/ |
134 |
public MainWin() { |
135 |
this.setTitle(SwingJavaBuilder.getConfig().getResource("appname") |
136 |
+ " - v" |
137 |
+ SwingJavaBuilder.getConfig().getResource("appversion")); |
138 |
|
139 |
tblMods = new ModTable(ETableContentType.MODS); |
140 |
tblMods.setVisible(false); |
141 |
scrollMods.setViewportView(tblMods); |
142 |
|
143 |
contents.setDividerLocation(SettingsManager.getInstance().get( |
144 |
"win_main_divloc", 550)); |
145 |
contents.setResizeWeight(0.4); |
146 |
|
147 |
if (PlatformInformation.getPlatform() == Platform.MACOS) { |
148 |
mainMenu.setVisible(false); |
149 |
} |
150 |
|
151 |
ToolTipManager.sharedInstance().setInitialDelay(250); |
152 |
|
153 |
getRootPane().setDefaultButton(btnInstall); |
154 |
lblSelectedModsVal.setText("0"); |
155 |
lblDownloadSizeVal.setText(SizeFormatter.format(0, 2)); |
156 |
radAll.setSelected(true); |
157 |
|
158 |
for (EApplyFilterTo f : EApplyFilterTo.values()) { |
159 |
cmbShowFilterTo.addItem(f); |
160 |
} |
161 |
txtShowFilter.addKeyListener(new KeyAdapter() { |
162 |
@Override |
163 |
public void keyReleased(KeyEvent e) { |
164 |
super.keyReleased(e); |
165 |
updateTableFilter(); |
166 |
} |
167 |
}); |
168 |
|
169 |
tblMods.addModSelectionListener(this); |
170 |
tblMods.addDownloadSizeListener(this); |
171 |
|
172 |
setSize(SettingsManager.getInstance().get("win_main_width", 950), |
173 |
SettingsManager.getInstance().get("win_main_height", 600)); |
174 |
setLocationRelativeTo(null); |
175 |
} |
176 |
|
177 |
private void initModTypeBox() { |
178 |
cmbModTypes.removeAllItems(); |
179 |
|
180 |
TreeMap<String, Type> types = new TreeMap<String, Type>(); |
181 |
for (Type t : PackageManager.getInstance().getTypesWithContent()) { |
182 |
types.put(t.getName(), t); |
183 |
} |
184 |
cmbModTypes.addItem("-All-"); |
185 |
for (Type t : types.values()) { |
186 |
cmbModTypes.addItem(t); |
187 |
} |
188 |
cmbModTypes.setSelectedIndex(0); |
189 |
} |
190 |
|
191 |
private void exit() { |
192 |
dispose(); |
193 |
System.exit(0); |
194 |
} |
195 |
|
196 |
private void saveLocalData() { |
197 |
SettingsManager.getInstance().put("win_main_divloc", |
198 |
contents.getDividerLocation()); |
199 |
SettingsManager.getInstance().put("win_main_width", getWidth()); |
200 |
SettingsManager.getInstance().put("win_main_height", getHeight()); |
201 |
SettingsManager.getInstance().serializeToFile( |
202 |
Paths.getSettingsFilename()); |
203 |
} |
204 |
|
205 |
@DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) |
206 |
private void execDepotUpdate(final BackgroundEvent evt) { |
207 |
if (!SettingsManager.getInstance().isOfflineMode() |
208 |
&& !SettingsManager.getInstance().isNoCacheUpdateMode()) { |
209 |
long start = new Date().getTime(); |
210 |
|
211 |
try { |
212 |
DepotManager.getInstance().updateInformation(); |
213 |
} catch (Exception e) { |
214 |
e.printStackTrace(); |
215 |
} |
216 |
|
217 |
System.out.println("Took: " + (new Date().getTime() - start) |
218 |
+ " msec"); |
219 |
} |
220 |
|
221 |
PackageManager.getInstance().init(); |
222 |
tblMods.reloadData(); |
223 |
initModTypeBox(); |
224 |
|
225 |
tblMods.setVisible(true); |
226 |
} |
227 |
|
228 |
@SuppressWarnings("unused") |
229 |
private void checkUpdates(Object evtSource) { |
230 |
if ((evtSource != this) |
231 |
|| SettingsManager.getInstance().get("notifyupdates", true)) { |
232 |
if (SettingsManager.getInstance().isOfflineMode()) { |
233 |
if (evtSource != this) { |
234 |
JOptionPane.showMessageDialog( |
235 |
this, |
236 |
SwingJavaBuilder.getConfig().getResource( |
237 |
"offlineMode.text"), |
238 |
SwingJavaBuilder.getConfig().getResource( |
239 |
"offlineMode.title"), |
240 |
JOptionPane.WARNING_MESSAGE); |
241 |
} |
242 |
} else { |
243 |
TreeSet<Package> mods = PackageManager.getInstance() |
244 |
.getUpdatableMods(); |
245 |
TreeSet<Package> tools = PackageManager.getInstance() |
246 |
.getUpdatableTools(); |
247 |
JPanel panPackages = new JPanel(new GridLayout(0, 1)); |
248 |
execUpdates = new TreeSet<Package>(); |
249 |
execUpdates.addAll(mods); |
250 |
execUpdates.addAll(tools); |
251 |
final JLabel lblSize = new JLabel("<html>" |
252 |
+ String.format( |
253 |
bundle.getString("updatesAvailableSize.text"), |
254 |
SizeFormatter.format(0, 3)) + "</html>"); |
255 |
int size = 0; |
256 |
for (final Package m : mods) { |
257 |
size += m.getZipSize(); |
258 |
JCheckBox check = new JCheckBox("Mod: " + m.getName() |
259 |
+ " (" + SizeFormatter.format(m.getZipSize(), 1) |
260 |
+ ")"); |
261 |
check.setSelected(true); |
262 |
check.addItemListener(new ItemListener() { |
263 |
@Override |
264 |
public void itemStateChanged(ItemEvent e) { |
265 |
if (e.getStateChange() == ItemEvent.SELECTED) |
266 |
execUpdates.add(m); |
267 |
else |
268 |
execUpdates.remove(m); |
269 |
int s = 0; |
270 |
for (Package p : execUpdates) |
271 |
s += p.getZipSize(); |
272 |
lblSize.setText("<html>" |
273 |
+ String.format( |
274 |
bundle.getString("updatesAvailableSize.text"), |
275 |
SizeFormatter.format(s, 3)) |
276 |
+ "</html>"); |
277 |
} |
278 |
}); |
279 |
panPackages.add(check); |
280 |
} |
281 |
for (final Package m : tools) { |
282 |
size += m.getZipSize(); |
283 |
JCheckBox check = new JCheckBox("Tool: " + m.getName() |
284 |
+ " (" + SizeFormatter.format(m.getZipSize(), 1) |
285 |
+ ")"); |
286 |
check.setSelected(true); |
287 |
check.addItemListener(new ItemListener() { |
288 |
@Override |
289 |
public void itemStateChanged(ItemEvent e) { |
290 |
if (e.getStateChange() == ItemEvent.SELECTED) |
291 |
execUpdates.add(m); |
292 |
else |
293 |
execUpdates.remove(m); |
294 |
int s = 0; |
295 |
for (Package p : execUpdates) |
296 |
s += p.getZipSize(); |
297 |
lblSize.setText("<html>" |
298 |
+ String.format( |
299 |
bundle.getString("updatesAvailableSize.text"), |
300 |
SizeFormatter.format(s, 3)) |
301 |
+ "</html>"); |
302 |
} |
303 |
}); |
304 |
panPackages.add(check); |
305 |
} |
306 |
lblSize.setText("<html>" |
307 |
+ String.format( |
308 |
bundle.getString("updatesAvailableSize.text"), |
309 |
SizeFormatter.format(size, 3)) + "</html>"); |
310 |
if (size > 0) { |
311 |
// Build info dialog content |
312 |
JPanel packages = new JPanel(new BorderLayout(0, 7)); |
313 |
JLabel lblIntro = new JLabel("<html>" |
314 |
+ bundle.getString("updatesAvailable.text") |
315 |
+ "</html>"); |
316 |
packages.add(lblIntro, BorderLayout.NORTH); |
317 |
packages.add(panPackages, BorderLayout.CENTER); |
318 |
packages.add(lblSize, BorderLayout.SOUTH); |
319 |
|
320 |
JPanel pan = new JPanel(new BorderLayout(0, 25)); |
321 |
pan.add(packages, BorderLayout.CENTER); |
322 |
JCheckBox checkFutureUpdates = new JCheckBox( |
323 |
bundle.getString("checkOnStartup.text")); |
324 |
checkFutureUpdates.setSelected(SettingsManager |
325 |
.getInstance().get("notifyupdates", true)); |
326 |
checkFutureUpdates.addItemListener(new ItemListener() { |
327 |
@Override |
328 |
public void itemStateChanged(ItemEvent evt) { |
329 |
SettingsManager.getInstance().put("notifyupdates", |
330 |
evt.getStateChange() == ItemEvent.SELECTED); |
331 |
} |
332 |
}); |
333 |
pan.add(checkFutureUpdates, BorderLayout.SOUTH); |
334 |
|
335 |
// Show dialog |
336 |
int res = JOptionPane.showConfirmDialog(this, pan, |
337 |
bundle.getString("updatesAvailable.title"), |
338 |
JOptionPane.YES_NO_OPTION, |
339 |
JOptionPane.QUESTION_MESSAGE); |
340 |
if (res == JOptionPane.NO_OPTION) { |
341 |
execUpdates = null; |
342 |
} |
343 |
} else { |
344 |
if (evtSource != this) { |
345 |
JOptionPane.showMessageDialog(this, |
346 |
bundle.getString("updatesNotAvailable.text"), |
347 |
bundle.getString("updatesNotAvailable.title"), |
348 |
JOptionPane.INFORMATION_MESSAGE); |
349 |
} |
350 |
} |
351 |
} |
352 |
} |
353 |
} |
354 |
|
355 |
@SuppressWarnings("unused") |
356 |
private void doUpdate() { |
357 |
if (execUpdates != null && execUpdates.size() > 0) { |
358 |
Downloader dl = new Downloader(execUpdates, null); |
359 |
try { |
360 |
dl.setVisible(true); |
361 |
if (dl.isFinished()) { |
362 |
TreeSet<Integer> installed = Installer.getInstalledTools(); |
363 |
TreeSet<Package> tools = new TreeSet<Package>(); |
364 |
for (Package m : execUpdates) |
365 |
if (m.isTool() |
366 |
&& installed.contains(m.getPackageNumber())) |
367 |
tools.add(m); |
368 |
if (tools.size() > 0) { |
369 |
Installer.installTools(tools, false); |
370 |
} |
371 |
} |
372 |
} finally { |
373 |
dl.dispose(); |
374 |
} |
375 |
} |
376 |
execUpdates = null; |
377 |
} |
378 |
|
379 |
@SuppressWarnings("unused") |
380 |
private void focus() { |
381 |
SwingUtilities.invokeLater(new Runnable() { |
382 |
|
383 |
@Override |
384 |
public void run() { |
385 |
toFront(); |
386 |
repaint(); |
387 |
} |
388 |
}); |
389 |
|
390 |
} |
391 |
|
392 |
@SuppressWarnings("unused") |
393 |
private void showCorePackagesDialog() { |
394 |
new CorePackagesDialog().setVisible(true); |
395 |
} |
396 |
|
397 |
private void showSettings() { |
398 |
new SettingsDialog().setVisible(true); |
399 |
} |
400 |
|
401 |
private void showAbout() { |
402 |
new AboutDialog().setVisible(true); |
403 |
} |
404 |
|
405 |
private JFileChooser getConfigOpenSaveDialog(boolean save) { |
406 |
JFileChooser fc = new JFileChooser(); |
407 |
fc.setCurrentDirectory(Paths.getEditionBasePath()); |
408 |
if (save) |
409 |
fc.setDialogType(JFileChooser.SAVE_DIALOG); |
410 |
else |
411 |
fc.setDialogType(JFileChooser.OPEN_DIALOG); |
412 |
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); |
413 |
fc.setFileFilter(new FileFilter() { |
414 |
@Override |
415 |
public String getDescription() { |
416 |
return "XML files"; |
417 |
} |
418 |
|
419 |
@Override |
420 |
public boolean accept(File arg0) { |
421 |
return (arg0.isDirectory()) |
422 |
|| (arg0.getName().toLowerCase().endsWith(".xml")); |
423 |
} |
424 |
}); |
425 |
fc.setMultiSelectionEnabled(false); |
426 |
return fc; |
427 |
} |
428 |
|
429 |
@SuppressWarnings("unused") |
430 |
private void loadConfig() { |
431 |
JFileChooser fc = getConfigOpenSaveDialog(false); |
432 |
int res = fc.showOpenDialog(this); |
433 |
if (res == JFileChooser.APPROVE_OPTION) { |
434 |
if (fc.getSelectedFile().exists()) |
435 |
tblMods.reloadSelection(fc.getSelectedFile()); |
436 |
} |
437 |
} |
438 |
|
439 |
@SuppressWarnings("unused") |
440 |
private void saveConfig() { |
441 |
JFileChooser fc = getConfigOpenSaveDialog(true); |
442 |
int res = fc.showSaveDialog(this); |
443 |
if (res == JFileChooser.APPROVE_OPTION) { |
444 |
File f = fc.getSelectedFile(); |
445 |
if (!f.getName().endsWith(".xml")) |
446 |
f = new File(f.getParentFile(), f.getName() + ".xml"); |
447 |
PackageManager.getInstance().saveModSelection(f, |
448 |
tblMods.getSelectedMods()); |
449 |
} |
450 |
} |
451 |
|
452 |
@SuppressWarnings("unused") |
453 |
private boolean reglobalizeVerify() { |
454 |
int res = JOptionPane.showConfirmDialog(this, |
455 |
bundle.getString("rebuildCore.text"), |
456 |
bundle.getString("rebuildCore.title"), |
457 |
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
458 |
return res == JOptionPane.YES_OPTION; |
459 |
} |
460 |
|
461 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
462 |
private void reglobalize(final BackgroundEvent evt) { |
463 |
Installer.initializeEdition(new InstallProgressListener() { |
464 |
@Override |
465 |
public void installProgressUpdate(int done, int total, String step) { |
466 |
evt.setProgressEnd(total); |
467 |
evt.setProgressValue(done); |
468 |
evt.setProgressMessage(step); |
469 |
} |
470 |
}); |
471 |
} |
472 |
|
473 |
@SuppressWarnings("unused") |
474 |
private void tools() { |
475 |
new ToolManager().setVisible(true); |
476 |
} |
477 |
|
478 |
@SuppressWarnings("unused") |
479 |
private void refreshToolsMenu() { |
480 |
for (JMenuItem i : toolsMenuItems) { |
481 |
toolsMenu.remove(i); |
482 |
} |
483 |
toolsMenuItems.clear(); |
484 |
for (final Package m : PackageManager.getInstance().getInstalledTools()) { |
485 |
File exe = m.getExeFile(); |
486 |
if (exe != null && exe.exists()) { |
487 |
JMenuItem item = new JMenuItem(); |
488 |
ImageIcon ico = null; |
489 |
if (m.getIconFile() != null && m.getIconFile().exists()) { |
490 |
ico = new ImageIcon(m.getIconFile().getPath()); |
491 |
} else { |
492 |
URL icon = AEInstaller2.class |
493 |
.getResource("images/transparent.png"); |
494 |
ico = new ImageIcon(icon); |
495 |
} |
496 |
ico = ImageResizer.resizeImage(ico, 32, 32); |
497 |
item.setAction(new AbstractAction(m.getName(), ico) { |
498 |
private static final long serialVersionUID = 1L; |
499 |
|
500 |
@Override |
501 |
public void actionPerformed(ActionEvent evt) { |
502 |
try { |
503 |
ApplicationInvoker.execute(m.getExeType(), |
504 |
m.getWorkingDir(), m.getExeFile(), null); |
505 |
} catch (ERuntimeNotInstalledException e) { |
506 |
JOptionPane.showMessageDialog(null, |
507 |
bundle.getString("exeNotFound.text"), |
508 |
bundle.getString("exeNotFound.title"), |
509 |
JOptionPane.ERROR_MESSAGE); |
510 |
e.printStackTrace(); |
511 |
} catch (FileNotFoundException e) { |
512 |
if (e.getMessage().contains("JRE")) |
513 |
JOptionPane.showMessageDialog(null, |
514 |
bundle.getString("jreNotFound.text"), |
515 |
bundle.getString("jreNotFound.title"), |
516 |
JOptionPane.ERROR_MESSAGE); |
517 |
if (e.getMessage().contains(".NET")) |
518 |
JOptionPane.showMessageDialog( |
519 |
null, |
520 |
bundle.getString("dotNetNotFound.text"), |
521 |
bundle.getString("dotNetNotFound.title"), |
522 |
JOptionPane.ERROR_MESSAGE); |
523 |
if (e.getMessage().contains("Wine")) |
524 |
JOptionPane.showMessageDialog(null, |
525 |
bundle.getString("wineNotFound.text"), |
526 |
bundle.getString("wineNotFound.title"), |
527 |
JOptionPane.ERROR_MESSAGE); |
528 |
e.printStackTrace(); |
529 |
} |
530 |
} |
531 |
}); |
532 |
toolsMenuItems.add(item); |
533 |
toolsMenu.add(item); |
534 |
} |
535 |
} |
536 |
} |
537 |
|
538 |
private void revertSelection() { |
539 |
tblMods.revertSelection(); |
540 |
} |
541 |
|
542 |
@SuppressWarnings("unused") |
543 |
private void unSelectAll() { |
544 |
tblMods.unSelectAll(); |
545 |
} |
546 |
|
547 |
@DoInBackground(progressMessage = "checkCorePackages.title", cancelable = false, indeterminateProgress = false) |
548 |
private void checkCorePackages(final BackgroundEvent evt) { |
549 |
if (!SettingsManager.getInstance().isOfflineMode()) { |
550 |
for (Package m : PackageManager.getInstance().getCoreTools()) { |
551 |
if (m.isNewerAvailable()) { |
552 |
execCoreUpdates.add(m); |
553 |
} |
554 |
} |
555 |
for (Package m : PackageManager.getInstance().getCoreMods()) { |
556 |
if (m.isNewerAvailable()) { |
557 |
execCoreUpdates.add(m); |
558 |
} |
559 |
} |
560 |
if (execCoreUpdates.size() > 0) { |
561 |
ModDownloader m = new ModDownloader(execCoreUpdates, |
562 |
new ModDownloaderListener() { |
563 |
@Override |
564 |
public void updateStatus(ModDownloader source, |
565 |
Package currentDownload, State state, |
566 |
int filesDown, int filesTotal, |
567 |
int bytesDown, int bytesTotal, |
568 |
int duration, int remaining, int speed) { |
569 |
evt.setProgressEnd(filesTotal); |
570 |
evt.setProgressValue(filesDown); |
571 |
} |
572 |
}); |
573 |
while (!m.isFinished()) { |
574 |
try { |
575 |
Thread.sleep(10); |
576 |
} catch (InterruptedException e) { |
577 |
e.printStackTrace(); |
578 |
} |
579 |
} |
580 |
} |
581 |
evt.setProgressMessage(bundle.getString("coreToolsInstall.title")); |
582 |
Installer.installTools(PackageManager.getInstance().getCoreTools(), |
583 |
false); |
584 |
} |
585 |
} |
586 |
|
587 |
@SuppressWarnings("unused") |
588 |
private void infoCorePackages() { |
589 |
if (execCoreUpdates.size() > 0) { |
590 |
String packages = ""; |
591 |
for (Package m : execCoreUpdates) { |
592 |
packages += String.format("\n - %s (%s)", m.getName(), |
593 |
m.getVersion()); |
594 |
} |
595 |
JOptionPane.showMessageDialog(this, String.format( |
596 |
bundle.getString("corePackagesUpdated.text"), packages), |
597 |
bundle.getString("corePackagesUpdated.title"), |
598 |
JOptionPane.INFORMATION_MESSAGE); |
599 |
} |
600 |
} |
601 |
|
602 |
@SuppressWarnings("unused") |
603 |
private void install() { |
604 |
TreeSet<Package> mods = new TreeSet<Package>(); |
605 |
mods.addAll(PackageManager.getInstance().getCoreMods()); |
606 |
mods.addAll(tblMods.getSelectedMods()); |
607 |
|
608 |
installDeps = new TreeSet<Package>(); |
609 |
|
610 |
installState = EInstallState.CHECKING; |
611 |
|
612 |
while (installState == EInstallState.CHECKING) { |
613 |
TreeSet<Package> toDownload = new TreeSet<Package>(); |
614 |
for (Package m : mods) { |
615 |
if (!m.isLocalAvailable()) |
616 |
toDownload.add(m); |
617 |
} |
618 |
|
619 |
if (toDownload.size() > 0 |
620 |
&& SettingsManager.getInstance().isOfflineMode()) { |
621 |
installState = EInstallState.OFFLINE; |
622 |
break; |
623 |
} |
624 |
|
625 |
if (toDownload.size() > 0) { |
626 |
Downloader dl = new Downloader(toDownload, installDeps); |
627 |
try { |
628 |
dl.setVisible(true); |
629 |
if (!dl.isFinished()) { |
630 |
installState = EInstallState.ABORTED; |
631 |
break; |
632 |
} |
633 |
} finally { |
634 |
dl.dispose(); |
635 |
} |
636 |
} |
637 |
|
638 |
HashMap<Package, HashSet<Package>> dependencies = PackageManager |
639 |
.getInstance().checkDependencies(mods); |
640 |
if (dependencies.size() > 0) { |
641 |
for (HashSet<Package> hm : dependencies.values()) { |
642 |
installDeps.addAll(hm); |
643 |
} |
644 |
|
645 |
int size = 0; |
646 |
String depsLocalString = ""; |
647 |
String depsDownloadString = ""; |
648 |
for (Package m : dependencies.keySet()) { |
649 |
for (Package mDep : dependencies.get(m)) { |
650 |
if (!mods.contains(mDep)) { |
651 |
mods.add(mDep); |
652 |
if (!mDep.isLocalAvailable()) { |
653 |
size += mDep.getZipSize(); |
654 |
if (depsDownloadString.length() > 0) |
655 |
depsDownloadString += "\n"; |
656 |
depsDownloadString += " - " + mDep.getName(); |
657 |
} else { |
658 |
if (depsLocalString.length() > 0) |
659 |
depsLocalString += "\n"; |
660 |
depsLocalString += " - " + mDep.getName(); |
661 |
} |
662 |
} |
663 |
} |
664 |
} |
665 |
|
666 |
if (depsLocalString.length() == 0) |
667 |
depsLocalString = bundle |
668 |
.getString("installDependencies.none"); |
669 |
if (depsDownloadString.length() == 0) |
670 |
depsDownloadString = bundle |
671 |
.getString("installDependencies.none"); |
672 |
|
673 |
if (!SettingsManager.getInstance().get( |
674 |
"notifyDepsAfterInstall", false)) { |
675 |
int res = JOptionPane.showConfirmDialog(this, String |
676 |
.format(bundle |
677 |
.getString("installDependencies.text"), |
678 |
depsLocalString, depsDownloadString, |
679 |
SizeFormatter.format(size, 3)), bundle |
680 |
.getString("installDependencies.title"), |
681 |
JOptionPane.YES_NO_OPTION, |
682 |
JOptionPane.INFORMATION_MESSAGE); |
683 |
|
684 |
if (res == JOptionPane.NO_OPTION) { |
685 |
installState = EInstallState.ABORTED; |
686 |
break; |
687 |
} |
688 |
} |
689 |
} else { |
690 |
HashMap<Package, HashSet<Package>> incompatibilities = PackageManager |
691 |
.getInstance().checkIncompabitilites(mods); |
692 |
if (incompatibilities.size() > 0) { |
693 |
installState = EInstallState.INCOMPATIBLE; |
694 |
|
695 |
String incompatString = ""; |
696 |
for (Package m : incompatibilities.keySet()) { |
697 |
if (incompatString.length() > 0) |
698 |
incompatString += "\n"; |
699 |
incompatString += m.getName() + ": "; |
700 |
String confMods = ""; |
701 |
for (Package mConf : incompatibilities.get(m)) { |
702 |
if (confMods.length() > 0) |
703 |
confMods += ", "; |
704 |
confMods += mConf.getName(); |
705 |
} |
706 |
incompatString += confMods; |
707 |
} |
708 |
|
709 |
JOptionPane.showMessageDialog(this, String.format( |
710 |
bundle.getString("installIncompatibilities.text"), |
711 |
incompatString), bundle |
712 |
.getString("installIncompatibilities.title"), |
713 |
JOptionPane.ERROR_MESSAGE); |
714 |
break; |
715 |
} else { |
716 |
installState = EInstallState.READY; |
717 |
} |
718 |
} |
719 |
} |
720 |
|
721 |
if (installState == EInstallState.READY) { |
722 |
installMods = new TreeSet<Package>(); |
723 |
TreeSet<Package> actuallyTools = new TreeSet<Package>(); |
724 |
|
725 |
for (Package m : mods) { |
726 |
if (m.isTool()) |
727 |
actuallyTools.add(m); |
728 |
else |
729 |
installMods.add(m); |
730 |
} |
731 |
|
732 |
if (actuallyTools.size() > 0) { |
733 |
Installer.installTools(actuallyTools, false); |
734 |
} |
735 |
} |
736 |
} |
737 |
|
738 |
@DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false) |
739 |
private void installExec(final BackgroundEvent evt) { |
740 |
if (installState == EInstallState.READY) { |
741 |
Installer.install(installMods, new InstallProgressListener() { |
742 |
@Override |
743 |
public void installProgressUpdate(int done, int total, |
744 |
String step) { |
745 |
evt.setProgressEnd(total); |
746 |
evt.setProgressValue(done); |
747 |
evt.setProgressMessage(step); |
748 |
} |
749 |
}); |
750 |
installState = EInstallState.DONE; |
751 |
} |
752 |
installMods = null; |
753 |
} |
754 |
|
755 |
@SuppressWarnings("unused") |
756 |
private void installDone() { |
757 |
PackageManager.getInstance().updateInstalledMods(); |
758 |
switch (installState) { |
759 |
case DONE: |
760 |
revertSelection(); |
761 |
if (installDeps.size() > 0 |
762 |
&& SettingsManager.getInstance().get( |
763 |
"notifyDepsAfterInstall", false)) { |
764 |
String installedDeps = ""; |
765 |
for (Package m : installDeps) { |
766 |
if (installedDeps.length() > 0) |
767 |
installedDeps += "\n"; |
768 |
installedDeps += " - " + m.getName(); |
769 |
} |
770 |
JOptionPane.showMessageDialog(this, String.format( |
771 |
bundle.getString("installDoneDeps.text"), |
772 |
installedDeps), bundle |
773 |
.getString("installDone.title"), |
774 |
JOptionPane.INFORMATION_MESSAGE); |
775 |
} else { |
776 |
JOptionPane.showMessageDialog(this, |
777 |
bundle.getString("installDone.text"), |
778 |
bundle.getString("installDone.title"), |
779 |
JOptionPane.INFORMATION_MESSAGE); |
780 |
} |
781 |
break; |
782 |
case OFFLINE: |
783 |
JOptionPane.showMessageDialog( |
784 |
this, |
785 |
SwingJavaBuilder.getConfig().getResource( |
786 |
"offlineMode.text"), |
787 |
SwingJavaBuilder.getConfig().getResource( |
788 |
"offlineMode.title"), |
789 |
JOptionPane.WARNING_MESSAGE); |
790 |
break; |
791 |
default: |
792 |
break; |
793 |
} |
794 |
installDeps = null; |
795 |
} |
796 |
|
797 |
@Override |
798 |
public void modSelectionChanged(ModTable source, Package m) { |
799 |
pkgInfo.updateInfo(m); |
800 |
} |
801 |
|
802 |
private void updateTableFilter() { |
803 |
Object o = cmbModTypes.getSelectedItem(); |
804 |
Type t = null; |
805 |
if (o instanceof Type) |
806 |
t = (Type) o; |
807 |
int downloadState = 0; |
808 |
if (radOnline.isSelected()) |
809 |
downloadState = 1; |
810 |
if (radLocal.isSelected()) |
811 |
downloadState = 2; |
812 |
tblMods.setFilter(t, downloadState, txtShowFilter.getText(), |
813 |
(EApplyFilterTo) cmbShowFilterTo.getSelectedItem()); |
814 |
} |
815 |
|
816 |
@Override |
817 |
public void modInstallSelectionChanged(int newSize, int newCount) { |
818 |
lblSelectedModsVal.setText(String.valueOf(newCount)); |
819 |
lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2)); |
820 |
} |
821 |
|
822 |
@SuppressWarnings("unused") |
823 |
private void checkInitialize() { |
824 |
if (!Installer.isEditionInitialized()) { |
825 |
if (!OniSplit.isOniSplitInstalled()) { |
826 |
JOptionPane.showMessageDialog(this, |
827 |
bundle.getString("noOniSplit.text"), |
828 |
bundle.getString("noOniSplit.title"), |
829 |
JOptionPane.ERROR_MESSAGE); |
830 |
exit(); |
831 |
} else { |
832 |
int res = JOptionPane |
833 |
.showConfirmDialog(this, |
834 |
bundle.getString("askInitialize.text"), |
835 |
bundle.getString("askInitialize.title"), |
836 |
JOptionPane.YES_NO_OPTION, |
837 |
JOptionPane.QUESTION_MESSAGE); |
838 |
if (res == JOptionPane.NO_OPTION) { |
839 |
saveLocalData(); |
840 |
exit(); |
841 |
} |
842 |
} |
843 |
} |
844 |
} |
845 |
|
846 |
@DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) |
847 |
private void initialize(final BackgroundEvent evt) { |
848 |
if (!Installer.isEditionInitialized()) { |
849 |
Installer.initializeEdition(new InstallProgressListener() { |
850 |
@Override |
851 |
public void installProgressUpdate(int done, int total, |
852 |
String step) { |
853 |
evt.setProgressEnd(total); |
854 |
evt.setProgressValue(done); |
855 |
evt.setProgressMessage(step); |
856 |
} |
857 |
}); |
858 |
} |
859 |
} |
860 |
|
861 |
private void oni(boolean windowed) { |
862 |
try { |
863 |
OniLauncher.launch(windowed); |
864 |
} catch (FileNotFoundException e) { |
865 |
JOptionPane.showMessageDialog(this, |
866 |
bundle.getString("oniExeNotFound.text"), |
867 |
bundle.getString("oniExeNotFound.title"), |
868 |
JOptionPane.ERROR_MESSAGE); |
869 |
e.printStackTrace(); |
870 |
} catch (ERuntimeNotInstalledException e) { |
871 |
JOptionPane.showMessageDialog(this, |
872 |
bundle.getString("wineNotFound.text"), |
873 |
bundle.getString("wineNotFound.title"), |
874 |
JOptionPane.ERROR_MESSAGE); |
875 |
e.printStackTrace(); |
876 |
} |
877 |
} |
878 |
|
879 |
@SuppressWarnings("unused") |
880 |
private void oniFull() { |
881 |
oni(false); |
882 |
} |
883 |
|
884 |
@SuppressWarnings("unused") |
885 |
private void oniWin() { |
886 |
oni(true); |
887 |
} |
888 |
|
889 |
@SuppressWarnings("unused") |
890 |
private void openEditionFolder() { |
891 |
try { |
892 |
Desktop.getDesktop().open(Paths.getEditionBasePath()); |
893 |
} catch (Exception e) { |
894 |
e.printStackTrace(); |
895 |
} |
896 |
} |
897 |
|
898 |
@Override |
899 |
public void handleAbout(ApplicationEvent event) { |
900 |
event.setHandled(true); |
901 |
showAbout(); |
902 |
} |
903 |
|
904 |
@Override |
905 |
public void handleOpenApplication(ApplicationEvent event) { |
906 |
} |
907 |
|
908 |
@Override |
909 |
public void handleOpenFile(ApplicationEvent event) { |
910 |
} |
911 |
|
912 |
@Override |
913 |
public void handlePreferences(ApplicationEvent event) { |
914 |
showSettings(); |
915 |
} |
916 |
|
917 |
@Override |
918 |
public void handlePrintFile(ApplicationEvent event) { |
919 |
} |
920 |
|
921 |
@Override |
922 |
public void handleQuit(ApplicationEvent event) { |
923 |
event.setHandled(true); |
924 |
saveLocalData(); |
925 |
exit(); |
926 |
} |
927 |
|
928 |
@Override |
929 |
public void handleReOpenApplication(ApplicationEvent event) { |
930 |
} |
931 |
|
932 |
} |