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