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