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