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