| 1 | package net.oni2.aeinstaller.gui; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | import java.awt.Desktop; | 
 
 
 
 
 | 4 | import java.awt.event.ActionEvent; | 
 
 
 
 
 | 5 | import java.awt.event.ActionListener; | 
 
 
 
 
 | 6 | import java.awt.event.MouseAdapter; | 
 
 
 
 
 | 7 | import java.awt.event.MouseEvent; | 
 
 
 
 
 | 8 | import java.io.File; | 
 
 
 
 
 | 9 | import java.io.IOException; | 
 
 
 
 
 | 10 | import java.util.ArrayList; | 
 
 
 
 
 | 11 | import java.util.HashMap; | 
 
 
 
 
 | 12 | import java.util.HashSet; | 
 
 
 
 
 | 13 | import java.util.List; | 
 
 
 
 
 | 14 | import java.util.ResourceBundle; | 
 
 
 
 
 | 15 | import java.util.TreeMap; | 
 
 
 
 
 | 16 | import java.util.TreeSet; | 
 
 
 
 
 | 17 | import java.util.Vector; | 
 
 
 
 
 | 18 |  | 
 
 
 
 
 | 19 | import javax.swing.JButton; | 
 
 
 
 
 | 20 | import javax.swing.JComboBox; | 
 
 
 
 
 | 21 | import javax.swing.JComponent; | 
 
 
 
 
 | 22 | import javax.swing.JFileChooser; | 
 
 
 
 
 | 23 | import javax.swing.JFrame; | 
 
 
 
 
 | 24 | import javax.swing.JLabel; | 
 
 
 
 
 | 25 | import javax.swing.JMenu; | 
 
 
 
 
 | 26 | import javax.swing.JMenuItem; | 
 
 
 
 
 | 27 | import javax.swing.JOptionPane; | 
 
 
 
 
 | 28 | import javax.swing.JPopupMenu; | 
 
 
 
 
 | 29 | import javax.swing.JSplitPane; | 
 
 
 
 
 | 30 | import javax.swing.JTable; | 
 
 
 
 
 | 31 | import javax.swing.ListSelectionModel; | 
 
 
 
 
 | 32 | import javax.swing.RowSorter; | 
 
 
 
 
 | 33 | import javax.swing.SortOrder; | 
 
 
 
 
 | 34 | import javax.swing.SwingUtilities; | 
 
 
 
 
 | 35 | import javax.swing.event.ListSelectionEvent; | 
 
 
 
 
 | 36 | import javax.swing.event.ListSelectionListener; | 
 
 
 
 
 | 37 | import javax.swing.filechooser.FileFilter; | 
 
 
 
 
 | 38 | import javax.swing.table.TableRowSorter; | 
 
 
 
 
 | 39 |  | 
 
 
 
 
 | 40 | import net.oni2.aeinstaller.backend.Paths; | 
 
 
 
 
 | 41 | import net.oni2.aeinstaller.backend.Settings; | 
 
 
 
 
 | 42 | import net.oni2.aeinstaller.backend.Settings.Platform; | 
 
 
 
 
 | 43 | import net.oni2.aeinstaller.backend.SizeFormatter; | 
 
 
 
 
 | 44 | import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener; | 
 
 
 
 
 | 45 | import net.oni2.aeinstaller.backend.depot.DepotManager; | 
 
 
 
 
 | 46 | import net.oni2.aeinstaller.backend.mods.Mod; | 
 
 
 
 
 | 47 | import net.oni2.aeinstaller.backend.mods.ModManager; | 
 
 
 
 
 | 48 | import net.oni2.aeinstaller.backend.mods.Type; | 
 
 
 
 
 | 49 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader; | 
 
 
 
 
 | 50 | import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State; | 
 
 
 
 
 | 51 | import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener; | 
 
 
 
 
 | 52 | import net.oni2.aeinstaller.backend.oni.InstallProgressListener; | 
 
 
 
 
 | 53 | import net.oni2.aeinstaller.backend.oni.Installer; | 
 
 
 
 
 | 54 | import net.oni2.aeinstaller.backend.oni.OniSplit; | 
 
 
 
 
 | 55 | import net.oni2.aeinstaller.gui.about.AboutDialog; | 
 
 
 
 
 | 56 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader; | 
 
 
 
 
 | 57 | import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener; | 
 
 
 
 
 | 58 | import net.oni2.aeinstaller.gui.modtable.ModTableFilter; | 
 
 
 
 
 | 59 | import net.oni2.aeinstaller.gui.modtable.ModTableModel; | 
 
 
 
 
 | 60 | import net.oni2.aeinstaller.gui.settings.SettingsDialog; | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 | import org.javabuilders.BuildResult; | 
 
 
 
 
 | 63 | import org.javabuilders.annotations.DoInBackground; | 
 
 
 
 
 | 64 | import org.javabuilders.event.BackgroundEvent; | 
 
 
 
 
 | 65 | import org.javabuilders.swing.SwingJavaBuilder; | 
 
 
 
 
 | 66 | import org.simplericity.macify.eawt.ApplicationEvent; | 
 
 
 
 
 | 67 | import org.simplericity.macify.eawt.ApplicationListener; | 
 
 
 
 
 | 68 |  | 
 
 
 
 
 | 69 | /** | 
 
 
 
 
 | 70 | * @author Christian Illy | 
 
 
 
 
 | 71 | */ | 
 
 
 
 
 | 72 | public class MainWin extends JFrame implements ApplicationListener, | 
 
 
 
 
 | 73 | DownloadSizeListener { | 
 
 
 
 
 | 74 | private static final long serialVersionUID = -4027395051382659650L; | 
 
 
 
 
 | 75 |  | 
 
 
 
 
 | 76 | private ResourceBundle bundle = ResourceBundle.getBundle(getClass() | 
 
 
 
 
 | 77 | .getName()); | 
 
 
 
 
 | 78 | @SuppressWarnings("unused") | 
 
 
 
 
 | 79 | private BuildResult result = SwingJavaBuilder.build(this, bundle); | 
 
 
 
 
 | 80 |  | 
 
 
 
 
 | 81 | private JMenu mainMenu; | 
 
 
 
 
 | 82 |  | 
 
 
 
 
 | 83 | private JSplitPane contents; | 
 
 
 
 
 | 84 |  | 
 
 
 
 
 | 85 | private JComboBox cmbModTypes; | 
 
 
 
 
 | 86 | private JTable tblMods; | 
 
 
 
 
 | 87 | private ModTableModel model; | 
 
 
 
 
 | 88 | private TableRowSorter<ModTableModel> sorter; | 
 
 
 
 
 | 89 | private JLabel lblDownloadSizeVal; | 
 
 
 
 
 | 90 |  | 
 
 
 
 
 | 91 | private JLabel lblSubmitterVal; | 
 
 
 
 
 | 92 | private JLabel lblCreatorVal; | 
 
 
 
 
 | 93 | private JLabel lblTypesVal; | 
 
 
 
 
 | 94 | private JLabel lblPlatformVal; | 
 
 
 
 
 | 95 | private HTMLLinkLabel lblDescriptionVal; | 
 
 
 
 
 | 96 |  | 
 
 
 
 
 | 97 | private JButton btnInstall; | 
 
 
 
 
 | 98 |  | 
 
 
 
 
 | 99 | /** | 
 
 
 
 
 | 100 | * Constructor of main window. | 
 
 
 
 
 | 101 | */ | 
 
 
 
 
 | 102 | public MainWin() { | 
 
 
 
 
 | 103 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname") | 
 
 
 
 
 | 104 | + " - v" | 
 
 
 
 
 | 105 | + SwingJavaBuilder.getConfig().getResource("appversion")); | 
 
 
 
 
 | 106 |  | 
 
 
 
 
 | 107 | contents.setDividerLocation(400); | 
 
 
 
 
 | 108 |  | 
 
 
 
 
 | 109 | if (Settings.getPlatform() == Platform.MACOS) { | 
 
 
 
 
 | 110 | mainMenu.setVisible(false); | 
 
 
 
 
 | 111 | } | 
 
 
 
 
 | 112 |  | 
 
 
 
 
 | 113 | getRootPane().setDefaultButton(btnInstall); | 
 
 
 
 
 | 114 | lblDownloadSizeVal.setText(SizeFormatter.format(0, 2)); | 
 
 
 
 
 | 115 | } | 
 
 
 
 
 | 116 |  | 
 
 
 
 
 | 117 | private void initModTypeBox() { | 
 
 
 
 
 | 118 | cmbModTypes.removeAllItems(); | 
 
 
 
 
 | 119 |  | 
 
 
 
 
 | 120 | TreeMap<String, Type> types = new TreeMap<String, Type>(); | 
 
 
 
 
 | 121 | for (Type t : ModManager.getInstance().getTypesWithContent()) { | 
 
 
 
 
 | 122 | types.put(t.getName(), t); | 
 
 
 
 
 | 123 | } | 
 
 
 
 
 | 124 | for (Type t : types.values()) { | 
 
 
 
 
 | 125 | cmbModTypes.addItem(t); | 
 
 
 
 
 | 126 | } | 
 
 
 
 
 | 127 | cmbModTypes.setSelectedIndex(0); | 
 
 
 
 
 | 128 | } | 
 
 
 
 
 | 129 |  | 
 
 
 
 
 | 130 | private void initTable() { | 
 
 
 
 
 | 131 | tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | 
 
 
 
 
 | 132 | tblMods.getSelectionModel().addListSelectionListener( | 
 
 
 
 
 | 133 | new ListSelectionListener() { | 
 
 
 
 
 | 134 | @Override | 
 
 
 
 
 | 135 | public void valueChanged(ListSelectionEvent e) { | 
 
 
 
 
 | 136 | int viewRow = tblMods.getSelectedRow(); | 
 
 
 
 
 | 137 | if (viewRow < 0) { | 
 
 
 
 
 | 138 | modSelection(null); | 
 
 
 
 
 | 139 | } else { | 
 
 
 
 
 | 140 | int modelRow = tblMods | 
 
 
 
 
 | 141 | .convertRowIndexToModel(viewRow); | 
 
 
 
 
 | 142 | Mod mod = (Mod) model.getValueAt(modelRow, -1); | 
 
 
 
 
 | 143 | modSelection(mod); | 
 
 
 
 
 | 144 | } | 
 
 
 
 
 | 145 | } | 
 
 
 
 
 | 146 | }); | 
 
 
 
 
 | 147 | tblMods.addMouseListener(new MouseAdapter() { | 
 
 
 
 
 | 148 | private void common(MouseEvent e) { | 
 
 
 
 
 | 149 | int r = tblMods.rowAtPoint(e.getPoint()); | 
 
 
 
 
 | 150 | if (r >= 0 && r < tblMods.getRowCount()) | 
 
 
 
 
 | 151 | tblMods.setRowSelectionInterval(r, r); | 
 
 
 
 
 | 152 | else | 
 
 
 
 
 | 153 | tblMods.clearSelection(); | 
 
 
 
 
 | 154 |  | 
 
 
 
 
 | 155 | int rowindex = tblMods.getSelectedRow(); | 
 
 
 
 
 | 156 | if (rowindex >= 0) { | 
 
 
 
 
 | 157 | if (e.isPopupTrigger() | 
 
 
 
 
 | 158 | && e.getComponent() instanceof JTable) { | 
 
 
 
 
 | 159 | int modelRow = tblMods.convertRowIndexToModel(rowindex); | 
 
 
 
 
 | 160 | final Mod mod = (Mod) model.getValueAt(modelRow, -1); | 
 
 
 
 
 | 161 |  | 
 
 
 
 
 | 162 | if (mod.isLocalAvailable()) { | 
 
 
 
 
 | 163 | JPopupMenu popup = new JPopupMenu(); | 
 
 
 
 
 | 164 | JMenuItem openModFolder = new JMenuItem(bundle | 
 
 
 
 
 | 165 | .getString("openModFolder.text")); | 
 
 
 
 
 | 166 | openModFolder | 
 
 
 
 
 | 167 | .addActionListener(new ActionListener() { | 
 
 
 
 
 | 168 | @Override | 
 
 
 
 
 | 169 | public void actionPerformed( | 
 
 
 
 
 | 170 | ActionEvent arg0) { | 
 
 
 
 
 | 171 | try { | 
 
 
 
 
 | 172 | Desktop.getDesktop().open( | 
 
 
 
 
 | 173 | mod.getLocalPath()); | 
 
 
 
 
 | 174 | } catch (IOException e) { | 
 
 
 
 
 | 175 | e.printStackTrace(); | 
 
 
 
 
 | 176 | } | 
 
 
 
 
 | 177 | } | 
 
 
 
 
 | 178 | }); | 
 
 
 
 
 | 179 | popup.add(openModFolder); | 
 
 
 
 
 | 180 | popup.show(e.getComponent(), e.getX(), e.getY()); | 
 
 
 
 
 | 181 | } | 
 
 
 
 
 | 182 | } | 
 
 
 
 
 | 183 | } | 
 
 
 
 
 | 184 | } | 
 
 
 
 
 | 185 |  | 
 
 
 
 
 | 186 | @Override | 
 
 
 
 
 | 187 | public void mousePressed(MouseEvent e) { | 
 
 
 
 
 | 188 | common(e); | 
 
 
 
 
 | 189 | } | 
 
 
 
 
 | 190 |  | 
 
 
 
 
 | 191 | @Override | 
 
 
 
 
 | 192 | public void mouseReleased(MouseEvent e) { | 
 
 
 
 
 | 193 | common(e); | 
 
 
 
 
 | 194 | } | 
 
 
 
 
 | 195 | }); | 
 
 
 
 
 | 196 | // To get checkbox-cells with background of row | 
 
 
 
 
 | 197 | ((JComponent) tblMods.getDefaultRenderer(Boolean.class)) | 
 
 
 
 
 | 198 | .setOpaque(true); | 
 
 
 
 
 | 199 |  | 
 
 
 
 
 | 200 | model = new ModTableModel(); | 
 
 
 
 
 | 201 | model.addDownloadSizeListener(this); | 
 
 
 
 
 | 202 |  | 
 
 
 
 
 | 203 | tblMods.setModel(model); | 
 
 
 
 
 | 204 |  | 
 
 
 
 
 | 205 | sorter = new TableRowSorter<ModTableModel>(model); | 
 
 
 
 
 | 206 | tblMods.setRowSorter(sorter); | 
 
 
 
 
 | 207 |  | 
 
 
 
 
 | 208 | sorter.setRowFilter(new ModTableFilter(null)); | 
 
 
 
 
 | 209 |  | 
 
 
 
 
 | 210 | List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); | 
 
 
 
 
 | 211 | sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING)); | 
 
 
 
 
 | 212 | sorter.setSortKeys(sortKeys); | 
 
 
 
 
 | 213 |  | 
 
 
 
 
 | 214 | for (int i = 0; i < model.getColumnCount(); i++) { | 
 
 
 
 
 | 215 | model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i)); | 
 
 
 
 
 | 216 | } | 
 
 
 
 
 | 217 | } | 
 
 
 
 
 | 218 |  | 
 
 
 
 
 | 219 | private void exit() { | 
 
 
 
 
 | 220 | dispose(); | 
 
 
 
 
 | 221 | System.exit(0); | 
 
 
 
 
 | 222 | } | 
 
 
 
 
 | 223 |  | 
 
 
 
 
 | 224 | private void saveLocalData() { | 
 
 
 
 
 | 225 | Settings.getInstance().serializeToFile(); | 
 
 
 
 
 | 226 | DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename()); | 
 
 
 
 
 | 227 | } | 
 
 
 
 
 | 228 |  | 
 
 
 
 
 | 229 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 230 | private void execDepotUpdate(final BackgroundEvent evt) { | 
 
 
 
 
 | 231 | try { | 
 
 
 
 
 | 232 | DepotManager.getInstance().updateInformation(false, | 
 
 
 
 
 | 233 | new DepotCacheUpdateProgressListener() { | 
 
 
 
 
 | 234 |  | 
 
 
 
 
 | 235 | @Override | 
 
 
 
 
 | 236 | public void cacheUpdateProgress(String stepName, | 
 
 
 
 
 | 237 | int current, int total) { | 
 
 
 
 
 | 238 | evt.setProgressEnd(total); | 
 
 
 
 
 | 239 | evt.setProgressValue(current); | 
 
 
 
 
 | 240 | evt.setProgressMessage(stepName); | 
 
 
 
 
 | 241 | } | 
 
 
 
 
 | 242 | }); | 
 
 
 
 
 | 243 | ModManager.getInstance().init(); | 
 
 
 
 
 | 244 | initTable(); | 
 
 
 
 
 | 245 | initModTypeBox(); | 
 
 
 
 
 | 246 |  | 
 
 
 
 
 | 247 | tblMods.setVisible(true); | 
 
 
 
 
 | 248 | } catch (Exception e) { | 
 
 
 
 
 | 249 | e.printStackTrace(); | 
 
 
 
 
 | 250 | } | 
 
 
 
 
 | 251 | } | 
 
 
 
 
 | 252 |  | 
 
 
 
 
 | 253 | @SuppressWarnings("unused") | 
 
 
 
 
 | 254 | private void checkUpdates() { | 
 
 
 
 
 | 255 | if (Settings.getInstance().get("notifyupdates", true)) { | 
 
 
 
 
 | 256 | // TODO | 
 
 
 
 
 | 257 | } | 
 
 
 
 
 | 258 | } | 
 
 
 
 
 | 259 |  | 
 
 
 
 
 | 260 | @SuppressWarnings("unused") | 
 
 
 
 
 | 261 | private void focus() { | 
 
 
 
 
 | 262 | SwingUtilities.invokeLater(new Runnable() { | 
 
 
 
 
 | 263 |  | 
 
 
 
 
 | 264 | @Override | 
 
 
 
 
 | 265 | public void run() { | 
 
 
 
 
 | 266 | toFront(); | 
 
 
 
 
 | 267 | repaint(); | 
 
 
 
 
 | 268 | } | 
 
 
 
 
 | 269 | }); | 
 
 
 
 
 | 270 |  | 
 
 
 
 
 | 271 | } | 
 
 
 
 
 | 272 |  | 
 
 
 
 
 | 273 | private void showSettings() { | 
 
 
 
 
 | 274 | new SettingsDialog().setVisible(true); | 
 
 
 
 
 | 275 | } | 
 
 
 
 
 | 276 |  | 
 
 
 
 
 | 277 | private void showAbout() { | 
 
 
 
 
 | 278 | new AboutDialog().setVisible(true); | 
 
 
 
 
 | 279 | } | 
 
 
 
 
 | 280 |  | 
 
 
 
 
 | 281 | private JFileChooser getConfigOpenSaveDialog(boolean save) { | 
 
 
 
 
 | 282 | JFileChooser fc = new JFileChooser(); | 
 
 
 
 
 | 283 | fc.setCurrentDirectory(Paths.getEditionBasePath()); | 
 
 
 
 
 | 284 | if (save) | 
 
 
 
 
 | 285 | fc.setDialogType(JFileChooser.SAVE_DIALOG); | 
 
 
 
 
 | 286 | else | 
 
 
 
 
 | 287 | fc.setDialogType(JFileChooser.OPEN_DIALOG); | 
 
 
 
 
 | 288 | fc.setFileSelectionMode(JFileChooser.FILES_ONLY); | 
 
 
 
 
 | 289 | fc.setFileFilter(new FileFilter() { | 
 
 
 
 
 | 290 | @Override | 
 
 
 
 
 | 291 | public String getDescription() { | 
 
 
 
 
 | 292 | return "XML files"; | 
 
 
 
 
 | 293 | } | 
 
 
 
 
 | 294 |  | 
 
 
 
 
 | 295 | @Override | 
 
 
 
 
 | 296 | public boolean accept(File arg0) { | 
 
 
 
 
 | 297 | return (arg0.isDirectory()) | 
 
 
 
 
 | 298 | || (arg0.getName().toLowerCase().endsWith(".xml")); | 
 
 
 
 
 | 299 | } | 
 
 
 
 
 | 300 | }); | 
 
 
 
 
 | 301 | fc.setMultiSelectionEnabled(false); | 
 
 
 
 
 | 302 | return fc; | 
 
 
 
 
 | 303 | } | 
 
 
 
 
 | 304 |  | 
 
 
 
 
 | 305 | @SuppressWarnings("unused") | 
 
 
 
 
 | 306 | private void loadConfig() { | 
 
 
 
 
 | 307 | JFileChooser fc = getConfigOpenSaveDialog(false); | 
 
 
 
 
 | 308 | int res = fc.showOpenDialog(this); | 
 
 
 
 
 | 309 | if (res == JFileChooser.APPROVE_OPTION) { | 
 
 
 
 
 | 310 | if (fc.getSelectedFile().exists()) | 
 
 
 
 
 | 311 | model.reloadSelection(fc.getSelectedFile()); | 
 
 
 
 
 | 312 | } | 
 
 
 
 
 | 313 | } | 
 
 
 
 
 | 314 |  | 
 
 
 
 
 | 315 | @SuppressWarnings("unused") | 
 
 
 
 
 | 316 | private void saveConfig() { | 
 
 
 
 
 | 317 | JFileChooser fc = getConfigOpenSaveDialog(true); | 
 
 
 
 
 | 318 | int res = fc.showSaveDialog(this); | 
 
 
 
 
 | 319 | if (res == JFileChooser.APPROVE_OPTION) { | 
 
 
 
 
 | 320 | File f = fc.getSelectedFile(); | 
 
 
 
 
 | 321 | if (!f.getName().endsWith(".xml")) | 
 
 
 
 
 | 322 | f = new File(f.getParentFile(), f.getName() + ".xml"); | 
 
 
 
 
 | 323 | ModManager.getInstance().saveModSelection(f, | 
 
 
 
 
 | 324 | model.getSelectedMods()); | 
 
 
 
 
 | 325 | } | 
 
 
 
 
 | 326 | } | 
 
 
 
 
 | 327 |  | 
 
 
 
 
 | 328 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 329 | private void reglobalize(final BackgroundEvent evt) { | 
 
 
 
 
 | 330 | Installer.initializeEdition(new InstallProgressListener() { | 
 
 
 
 
 | 331 | @Override | 
 
 
 
 
 | 332 | public void installProgressUpdate(int done, int total, String step) { | 
 
 
 
 
 | 333 | evt.setProgressEnd(total); | 
 
 
 
 
 | 334 | evt.setProgressValue(done); | 
 
 
 
 
 | 335 | evt.setProgressMessage(step); | 
 
 
 
 
 | 336 | } | 
 
 
 
 
 | 337 | }); | 
 
 
 
 
 | 338 | } | 
 
 
 
 
 | 339 |  | 
 
 
 
 
 | 340 | @SuppressWarnings("unused") | 
 
 
 
 
 | 341 | private void tools() { | 
 
 
 
 
 | 342 | // TODO method stub | 
 
 
 
 
 | 343 | JOptionPane.showMessageDialog(this, "tools", "todo", | 
 
 
 
 
 | 344 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 345 | } | 
 
 
 
 
 | 346 |  | 
 
 
 
 
 | 347 | @SuppressWarnings("unused") | 
 
 
 
 
 | 348 | private void revertSelection() { | 
 
 
 
 
 | 349 | model.revertSelection(); | 
 
 
 
 
 | 350 | } | 
 
 
 
 
 | 351 |  | 
 
 
 
 
 | 352 | @SuppressWarnings("unused") | 
 
 
 
 
 | 353 | private void checkDotNet() { | 
 
 
 
 
 | 354 | if (!OniSplit.isDotNETInstalled()) { | 
 
 
 
 
 | 355 | HTMLLinkLabel hll = new HTMLLinkLabel(); | 
 
 
 
 
 | 356 | String dlUrl = ""; | 
 
 
 
 
 | 357 | switch (Settings.getPlatform()) { | 
 
 
 
 
 | 358 | case WIN: | 
 
 
 
 
 | 359 | switch (Settings.getArchitecture()) { | 
 
 
 
 
 | 360 | case X86: | 
 
 
 
 
 | 361 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe"; | 
 
 
 
 
 | 362 | break; | 
 
 
 
 
 | 363 | case AMD64: | 
 
 
 
 
 | 364 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe"; | 
 
 
 
 
 | 365 | break; | 
 
 
 
 
 | 366 | } | 
 
 
 
 
 | 367 | break; | 
 
 
 
 
 | 368 | default: | 
 
 
 
 
 | 369 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html"; | 
 
 
 
 
 | 370 | } | 
 
 
 
 
 | 371 | hll.setText(bundle.getString("dotNetMissing.text").replaceAll("%1", | 
 
 
 
 
 | 372 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl))); | 
 
 
 
 
 | 373 | JOptionPane.showMessageDialog(this, hll, | 
 
 
 
 
 | 374 | bundle.getString("dotNetMissing.title"), | 
 
 
 
 
 | 375 | JOptionPane.ERROR_MESSAGE); | 
 
 
 
 
 | 376 | exit(); | 
 
 
 
 
 | 377 | } | 
 
 
 
 
 | 378 | } | 
 
 
 
 
 | 379 |  | 
 
 
 
 
 | 380 | @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 381 | private void checkMandatoryFiles(final BackgroundEvent evt) { | 
 
 
 
 
 | 382 | TreeSet<Mod> mand = new TreeSet<Mod>(); | 
 
 
 
 
 | 383 | for (Mod m : ModManager.getInstance().getMandatoryTools()) { | 
 
 
 
 
 | 384 | if (m.isNewerAvailable()) { | 
 
 
 
 
 | 385 | mand.add(m); | 
 
 
 
 
 | 386 | } | 
 
 
 
 
 | 387 | } | 
 
 
 
 
 | 388 | for (Mod m : ModManager.getInstance().getMandatoryMods()) { | 
 
 
 
 
 | 389 | if (m.isNewerAvailable()) { | 
 
 
 
 
 | 390 | mand.add(m); | 
 
 
 
 
 | 391 | } | 
 
 
 
 
 | 392 | } | 
 
 
 
 
 | 393 | if (mand.size() > 0) { | 
 
 
 
 
 | 394 | ModDownloader m = new ModDownloader(mand, | 
 
 
 
 
 | 395 | new ModDownloaderListener() { | 
 
 
 
 
 | 396 | @Override | 
 
 
 
 
 | 397 | public void updateStatus(ModDownloader source, | 
 
 
 
 
 | 398 | State state, int filesDown, int filesTotal, | 
 
 
 
 
 | 399 | int bytesDown, int bytesTotal, int duration, | 
 
 
 
 
 | 400 | int remaining, int speed) { | 
 
 
 
 
 | 401 | evt.setProgressEnd(filesTotal); | 
 
 
 
 
 | 402 | evt.setProgressValue(filesDown); | 
 
 
 
 
 | 403 | } | 
 
 
 
 
 | 404 | }); | 
 
 
 
 
 | 405 | while (!m.isFinished()) { | 
 
 
 
 
 | 406 | try { | 
 
 
 
 
 | 407 | Thread.sleep(10); | 
 
 
 
 
 | 408 | } catch (InterruptedException e) { | 
 
 
 
 
 | 409 | // TODO Auto-generated catch block | 
 
 
 
 
 | 410 | e.printStackTrace(); | 
 
 
 
 
 | 411 | } | 
 
 
 
 
 | 412 | } | 
 
 
 
 
 | 413 | } | 
 
 
 
 
 | 414 | evt.setProgressMessage(bundle.getString("mandatoryToolsInstall.title")); | 
 
 
 
 
 | 415 | Installer.installTools(ModManager.getInstance().getMandatoryTools()); | 
 
 
 
 
 | 416 | } | 
 
 
 
 
 | 417 |  | 
 
 
 
 
 | 418 | @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 419 | private void install(final BackgroundEvent evt) { | 
 
 
 
 
 | 420 | TreeSet<Mod> mods = new TreeSet<Mod>(); | 
 
 
 
 
 | 421 | mods.addAll(ModManager.getInstance().getMandatoryMods()); | 
 
 
 
 
 | 422 | mods.addAll(model.getSelectedMods()); | 
 
 
 
 
 | 423 |  | 
 
 
 
 
 | 424 | boolean instReady = false; | 
 
 
 
 
 | 425 |  | 
 
 
 
 
 | 426 | while (!instReady) { | 
 
 
 
 
 | 427 | System.out.println("Checking downloads:"); | 
 
 
 
 
 | 428 | TreeSet<Mod> toDownload = new TreeSet<Mod>(); | 
 
 
 
 
 | 429 | for (Mod m : mods) { | 
 
 
 
 
 | 430 | if (!m.isLocalAvailable()) | 
 
 
 
 
 | 431 | toDownload.add(m); | 
 
 
 
 
 | 432 | } | 
 
 
 
 
 | 433 | if (toDownload.size() > 0) { | 
 
 
 
 
 | 434 | System.out.println("Download files: " + toDownload.toString()); | 
 
 
 
 
 | 435 | Downloader dl = new Downloader(toDownload); | 
 
 
 
 
 | 436 | dl.setVisible(true); | 
 
 
 
 
 | 437 | if (!dl.isFinished()) | 
 
 
 
 
 | 438 | break; | 
 
 
 
 
 | 439 | } | 
 
 
 
 
 | 440 | HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance() | 
 
 
 
 
 | 441 | .checkDependencies(mods); | 
 
 
 
 
 | 442 | if (dependencies.size() > 0) { | 
 
 
 
 
 | 443 | System.out.println("Unmet dependencies: " | 
 
 
 
 
 | 444 | + dependencies.toString()); | 
 
 
 
 
 | 445 | for (Mod m : dependencies.keySet()) { | 
 
 
 
 
 | 446 | for (Mod mDep : dependencies.get(m)) | 
 
 
 
 
 | 447 | mods.add(mDep); | 
 
 
 
 
 | 448 | } | 
 
 
 
 
 | 449 | } else { | 
 
 
 
 
 | 450 | HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance() | 
 
 
 
 
 | 451 | .checkIncompabitilites(mods); | 
 
 
 
 
 | 452 | if (conflicts.size() > 0) { | 
 
 
 
 
 | 453 | System.err.println("Incompatible mods: " | 
 
 
 
 
 | 454 | + conflicts.toString()); | 
 
 
 
 
 | 455 | break; | 
 
 
 
 
 | 456 | } else { | 
 
 
 
 
 | 457 | instReady = true; | 
 
 
 
 
 | 458 | } | 
 
 
 
 
 | 459 | } | 
 
 
 
 
 | 460 | } | 
 
 
 
 
 | 461 |  | 
 
 
 
 
 | 462 | if (instReady) { | 
 
 
 
 
 | 463 | System.out.println("Install mods: " + mods.toString()); | 
 
 
 
 
 | 464 |  | 
 
 
 
 
 | 465 | Installer.install(mods, new InstallProgressListener() { | 
 
 
 
 
 | 466 | @Override | 
 
 
 
 
 | 467 | public void installProgressUpdate(int done, int total, | 
 
 
 
 
 | 468 | String step) { | 
 
 
 
 
 | 469 | evt.setProgressEnd(total); | 
 
 
 
 
 | 470 | evt.setProgressValue(done); | 
 
 
 
 
 | 471 | evt.setProgressMessage(step); | 
 
 
 
 
 | 472 | } | 
 
 
 
 
 | 473 | }); | 
 
 
 
 
 | 474 |  | 
 
 
 
 
 | 475 | JOptionPane.showMessageDialog(this, | 
 
 
 
 
 | 476 | bundle.getString("installDone.text"), | 
 
 
 
 
 | 477 | bundle.getString("installDone.title"), | 
 
 
 
 
 | 478 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 479 | } | 
 
 
 
 
 | 480 | } | 
 
 
 
 
 | 481 |  | 
 
 
 
 
 | 482 | private void modSelection(Mod m) { | 
 
 
 
 
 | 483 | lblSubmitterVal.setText(""); | 
 
 
 
 
 | 484 | lblCreatorVal.setText(""); | 
 
 
 
 
 | 485 | lblDescriptionVal.setText(""); | 
 
 
 
 
 | 486 | lblTypesVal.setText(""); | 
 
 
 
 
 | 487 | lblPlatformVal.setText(""); | 
 
 
 
 
 | 488 | if (m != null) { | 
 
 
 
 
 | 489 | lblSubmitterVal.setText(m.getName()); | 
 
 
 
 
 | 490 | lblCreatorVal.setText(m.getCreator()); | 
 
 
 
 
 | 491 | lblDescriptionVal.setText(m.getDescription()); | 
 
 
 
 
 | 492 |  | 
 
 
 
 
 | 493 | String types = ""; | 
 
 
 
 
 | 494 | for (Type t : m.getTypes()) { | 
 
 
 
 
 | 495 | if (types.length() > 0) | 
 
 
 
 
 | 496 | types += ", "; | 
 
 
 
 
 | 497 | types += t.getName(); | 
 
 
 
 
 | 498 | } | 
 
 
 
 
 | 499 | lblTypesVal.setText(types); | 
 
 
 
 
 | 500 | lblPlatformVal.setText(m.getPlatform().toString()); | 
 
 
 
 
 | 501 | } | 
 
 
 
 
 | 502 | // TODO | 
 
 
 
 
 | 503 | } | 
 
 
 
 
 | 504 |  | 
 
 
 
 
 | 505 | @SuppressWarnings("unused") | 
 
 
 
 
 | 506 | private void modTypeSelection() { | 
 
 
 
 
 | 507 | Type t = (Type) cmbModTypes.getSelectedItem(); | 
 
 
 
 
 | 508 | if (t != null) | 
 
 
 
 
 | 509 | sorter.setRowFilter(new ModTableFilter(t)); | 
 
 
 
 
 | 510 | else | 
 
 
 
 
 | 511 | sorter.setRowFilter(new ModTableFilter(null)); | 
 
 
 
 
 | 512 | } | 
 
 
 
 
 | 513 |  | 
 
 
 
 
 | 514 | @Override | 
 
 
 
 
 | 515 | public void downloadSizeChanged(int newSize) { | 
 
 
 
 
 | 516 | lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2)); | 
 
 
 
 
 | 517 | } | 
 
 
 
 
 | 518 |  | 
 
 
 
 
 | 519 | @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 520 | private void initialize(final BackgroundEvent evt) { | 
 
 
 
 
 | 521 | if (!Installer.isEditionInitialized()) { | 
 
 
 
 
 | 522 | int res = JOptionPane.showConfirmDialog(this, | 
 
 
 
 
 | 523 | bundle.getString("askInitialize.text"), | 
 
 
 
 
 | 524 | bundle.getString("askInitialize.title"), | 
 
 
 
 
 | 525 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); | 
 
 
 
 
 | 526 | if (res == JOptionPane.NO_OPTION) { | 
 
 
 
 
 | 527 | exit(); | 
 
 
 
 
 | 528 | } else { | 
 
 
 
 
 | 529 | Installer.initializeEdition(new InstallProgressListener() { | 
 
 
 
 
 | 530 | @Override | 
 
 
 
 
 | 531 | public void installProgressUpdate(int done, int total, | 
 
 
 
 
 | 532 | String step) { | 
 
 
 
 
 | 533 | evt.setProgressEnd(total); | 
 
 
 
 
 | 534 | evt.setProgressValue(done); | 
 
 
 
 
 | 535 | evt.setProgressMessage(step); | 
 
 
 
 
 | 536 | } | 
 
 
 
 
 | 537 | }); | 
 
 
 
 
 | 538 | } | 
 
 
 
 
 | 539 | } | 
 
 
 
 
 | 540 | } | 
 
 
 
 
 | 541 |  | 
 
 
 
 
 | 542 | private Vector<String> getBasicOniLaunchParams() { | 
 
 
 
 
 | 543 | Vector<String> params = new Vector<String>(); | 
 
 
 
 
 | 544 | switch (Settings.getPlatform()) { | 
 
 
 
 
 | 545 | case WIN: | 
 
 
 
 
 | 546 | params.add(new File(Paths.getEditionBasePath(), "Oni.exe") | 
 
 
 
 
 | 547 | .getPath()); | 
 
 
 
 
 | 548 | break; | 
 
 
 
 
 | 549 | case MACOS: | 
 
 
 
 
 | 550 | params.add(new File(Paths.getEditionBasePath(), | 
 
 
 
 
 | 551 | "Oni.app/Contents/MacOS/Oni").getPath()); | 
 
 
 
 
 | 552 | break; | 
 
 
 
 
 | 553 | case LINUX: | 
 
 
 
 
 | 554 | String wine = Settings.getWinePath(); | 
 
 
 
 
 | 555 | if (wine != null) { | 
 
 
 
 
 | 556 | params.add(wine); | 
 
 
 
 
 | 557 | params.add(new File(Paths.getEditionBasePath(), "Oni.exe") | 
 
 
 
 
 | 558 | .getPath()); | 
 
 
 
 
 | 559 | } | 
 
 
 
 
 | 560 | break; | 
 
 
 
 
 | 561 | default: | 
 
 
 
 
 | 562 | } | 
 
 
 
 
 | 563 | if (params.size() > 0) { | 
 
 
 
 
 | 564 | params.add("-debugfiles"); | 
 
 
 
 
 | 565 | } | 
 
 
 
 
 | 566 | return params; | 
 
 
 
 
 | 567 | } | 
 
 
 
 
 | 568 |  | 
 
 
 
 
 | 569 | @SuppressWarnings("unused") | 
 
 
 
 
 | 570 | private void oniFull() { | 
 
 
 
 
 | 571 | Vector<String> params = getBasicOniLaunchParams(); | 
 
 
 
 
 | 572 | if (params.size() > 0) { | 
 
 
 
 
 | 573 | try { | 
 
 
 
 
 | 574 | ProcessBuilder pb = new ProcessBuilder(params); | 
 
 
 
 
 | 575 | pb.directory(Paths.getEditionBasePath()); | 
 
 
 
 
 | 576 | pb.start(); | 
 
 
 
 
 | 577 | } catch (IOException e) { | 
 
 
 
 
 | 578 | // TODO Auto-generated catch block | 
 
 
 
 
 | 579 | e.printStackTrace(); | 
 
 
 
 
 | 580 | } | 
 
 
 
 
 | 581 | } | 
 
 
 
 
 | 582 | } | 
 
 
 
 
 | 583 |  | 
 
 
 
 
 | 584 | @SuppressWarnings("unused") | 
 
 
 
 
 | 585 | private void oniWin() { | 
 
 
 
 
 | 586 | Vector<String> params = getBasicOniLaunchParams(); | 
 
 
 
 
 | 587 | if (params.size() > 0) { | 
 
 
 
 
 | 588 | params.add("-noswitch"); | 
 
 
 
 
 | 589 | try { | 
 
 
 
 
 | 590 | ProcessBuilder pb = new ProcessBuilder(params); | 
 
 
 
 
 | 591 | pb.directory(Paths.getEditionBasePath()); | 
 
 
 
 
 | 592 | pb.start(); | 
 
 
 
 
 | 593 | } catch (IOException e) { | 
 
 
 
 
 | 594 | // TODO Auto-generated catch block | 
 
 
 
 
 | 595 | e.printStackTrace(); | 
 
 
 
 
 | 596 | } | 
 
 
 
 
 | 597 | } | 
 
 
 
 
 | 598 | } | 
 
 
 
 
 | 599 |  | 
 
 
 
 
 | 600 | @SuppressWarnings("unused") | 
 
 
 
 
 | 601 | private void openEditionFolder() { | 
 
 
 
 
 | 602 | try { | 
 
 
 
 
 | 603 | Desktop.getDesktop().open(Paths.getEditionBasePath()); | 
 
 
 
 
 | 604 | } catch (IOException e) { | 
 
 
 
 
 | 605 | e.printStackTrace(); | 
 
 
 
 
 | 606 | } | 
 
 
 
 
 | 607 | } | 
 
 
 
 
 | 608 |  | 
 
 
 
 
 | 609 | @Override | 
 
 
 
 
 | 610 | public void handleAbout(ApplicationEvent event) { | 
 
 
 
 
 | 611 | event.setHandled(true); | 
 
 
 
 
 | 612 | showAbout(); | 
 
 
 
 
 | 613 | } | 
 
 
 
 
 | 614 |  | 
 
 
 
 
 | 615 | @Override | 
 
 
 
 
 | 616 | public void handleOpenApplication(ApplicationEvent event) { | 
 
 
 
 
 | 617 | } | 
 
 
 
 
 | 618 |  | 
 
 
 
 
 | 619 | @Override | 
 
 
 
 
 | 620 | public void handleOpenFile(ApplicationEvent event) { | 
 
 
 
 
 | 621 | } | 
 
 
 
 
 | 622 |  | 
 
 
 
 
 | 623 | @Override | 
 
 
 
 
 | 624 | public void handlePreferences(ApplicationEvent event) { | 
 
 
 
 
 | 625 | showSettings(); | 
 
 
 
 
 | 626 | } | 
 
 
 
 
 | 627 |  | 
 
 
 
 
 | 628 | @Override | 
 
 
 
 
 | 629 | public void handlePrintFile(ApplicationEvent event) { | 
 
 
 
 
 | 630 | } | 
 
 
 
 
 | 631 |  | 
 
 
 
 
 | 632 | @Override | 
 
 
 
 
 | 633 | public void handleQuit(ApplicationEvent event) { | 
 
 
 
 
 | 634 | event.setHandled(true); | 
 
 
 
 
 | 635 | saveLocalData(); | 
 
 
 
 
 | 636 | exit(); | 
 
 
 
 
 | 637 | } | 
 
 
 
 
 | 638 |  | 
 
 
 
 
 | 639 | @Override | 
 
 
 
 
 | 640 | public void handleReOpenApplication(ApplicationEvent event) { | 
 
 
 
 
 | 641 | } | 
 
 
 
 
 | 642 |  | 
 
 
 
 
 | 643 | } |