📄 pluginmanager.java
字号:
thread.start(); } /** * Removes the plugins that are selected in the manage panel */ private void removeHandler() { int result = JOptionPane.showConfirmDialog(null, resources .getString("pluginRemoveConfirmation"), resources .getString("pluginManager"), JOptionPane.YES_NO_OPTION); if (result != 0) return; int rows[] = managePanel.getTable().getSelectedRows(); ArrayList remove = new ArrayList(); for (int i = 0; i < rows.length; i++) { Properties props = (Properties) installedPlugins.get(rows[i]); props.setProperty("selected", "true"); remove.add(props); } unloadPluginHandler(remove, false, null); System.gc(); remove = new ArrayList(); for (int i = 0; i < rows.length; i++) { Properties props = (Properties) installedPlugins.get(rows[i]); Hashtable loadedPlugins = PluginLoader.getInstance() .getLoadedPlugins(); String name = props.getProperty("fileName"); File file = new File(name); if (file.delete()) { remove.add(props); } else { throwError("Could not unload plugin!", false); return; } } for (int i = 0; i < remove.size(); i++) { installedPlugins.remove(remove.get(i)); } managePanel.setPlugins(installedPlugins); downloadPluginList(); } /** * Downloads a list of plugins */ private void downloadPluginList() { PluginLoader loader = PluginLoader.getInstance(); loader.findPlugins(installDir + File.separatorChar + "plugins"); installedPlugins = loader.getInstalledPlugins(); managePanel.setPlugins(installedPlugins); managePanel.getTable().setEnabled(false); listPanel.getTable().setEnabled(false); setStatusText(resources.getString("gettingPluginList")); Thread thread = new Thread(new DownloadListThread()); thread.start(); } /** * Called when the download thread is done downloading selected plugins */ protected void doneDownloadingPlugins(ArrayList list) { File cacheDir = new File(installDir, "downloadcache"); File pluginDir = new File(installDir, "plugins"); if (!pluginDir.isDirectory() && !pluginDir.mkdirs()) { throwError("pluginDirectoryCreationError", true); return; } unloadPluginHandler(list, false, null); System.gc(); for (int i = 0; i < list.size(); i++) { Properties props = (Properties) list.get(i); if (props.getProperty("selected") != null) { File file = new File(cacheDir, props.getProperty("fileName")); File newFile = new File(pluginDir, props .getProperty("fileName")); if (newFile.exists() && !newFile.delete()) { com.valhalla.Logger.debug("Could not delete old plugin!"); } if (!file.renameTo(newFile)) { com.valhalla.Logger.debug("Could not rename to new plugin"); } } } PluginLoader.getNewInstance(); System.gc(); PluginLoader.getInstance().findPlugins( installDir + File.separatorChar + "plugins"); loadPluginHandler(list, null); downloadPluginList(); } /** * Called when the downloader thread is done downloading the list of * available plugins */ protected void doneDownloadingList() { listPanel.setPlugins(pluginList); managePanel.getTable().setEnabled(true); listPanel.getTable().setEnabled(true); setStatusText(resources.getString("doneDownloading")); } /** * Sets the text in the status label * * @param text * the text to set */ private void setStatusText(String text) { statusLabel.setText("<html><b>" + resources.getString("status") + "</b>: " + text); } /** * Returns true if a plugin is already installed * * @return <tt>true</tt> if a plugin is already installed */ private boolean pluginInstalled(Properties props) { boolean check = false; if (props.getProperty("name") == null) return check; for (int i = 0; i < installedPlugins.size(); i++) { Properties p = (Properties) installedPlugins.get(i); if (p.getProperty("name") != null && p.getProperty("name").equals(props.getProperty("name"))) check = true; } return check; } /** * Returns true if a plugin is upgradable * * @return <tt>true</tt> if a plugin is already upgradable */ private boolean pluginUpgradable(Properties props) { boolean check = false; if (props.getProperty("name") == null) return check; for (int i = 0; i < installedPlugins.size(); i++) { Properties p = (Properties) installedPlugins.get(i); if (p.getProperty("name") != null && p.getProperty("name").equals(props.getProperty("name"))) { try { String installedVersion = p.getProperty("version"); String remoteVersion = props.getProperty("version"); int comp = remoteVersion.compareTo(installedVersion); if (comp > 0) check = true; String installedAPI = p.getProperty("APIVersion"); String apiVersion = PluginLoader.getAPIVersion() + ""; comp = apiVersion.compareTo(installedAPI); if( comp > 0 ) check = true; } catch (Exception e) { } } } return check; } /** * Collects the list of available plugins in their versions */ class DownloadListThread implements Runnable { public void run() { BufferedReader in = null; pluginList = new ArrayList(); try { URL url = new URL("http://" + mirror + script + "?command=pluginList&apiVersion=" + PluginLoader.getAPIVersion()); in = new BufferedReader(new InputStreamReader(url.openStream())); String line = null; String names[] = null; int lineCount = 0; while ((line = in.readLine()) != null) { // the first line will indicate if we've connected // successfully if (lineCount == 0) { if (!line.equals("Plugin list will follow")) { throwError("invalidResponse", true); break; } } // second line gets a list of available arguments for each // plugin else if (lineCount == 1) names = line.split("\t"); // all lines after are plugin information lines else { String de[] = line.split("\t"); //com.valhalla.Logger.debug( line ); if (de.length == names.length) { Properties props = new Properties(); for (int i = 0; i < names.length; i++) { props.setProperty(names[i], de[i]); } // make sure the plugin platform is compatible and // the plugin api version is the same, // otherwise // ignore this plugin if (PluginLoader.checkPlatform (props) && props.getProperty("APIVersion").equals( PluginLoader.getAPIVersion() + "")) { com.valhalla.Logger.debug( props.getProperty("APIVersion")); if (!pluginInstalled(props)) pluginList.add(props); else if (pluginUpgradable(props)) pluginList.add(props); } } else { com.valhalla.Logger.debug("Invalid plugin found."); } } lineCount++; } } catch (Exception e) { throwError(e.getMessage(), false); e.printStackTrace(); } doneDownloadingList(); } } /** * Displays an error dialog * * @param message * the message to display */ void throwError(String message, boolean useResources) { if (useResources) message = resources.getString(message); final String tempMessage = message; SwingUtilities.invokeLater(new Runnable() { public void run() { Standard.warningMessage(PluginManager.this, resources .getString("pluginManager"), tempMessage); setStatusText(tempMessage); } }); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -