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