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