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