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