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