⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pluginmanager.java~

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
    }    /**     * 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() {            Socket socket = null;            BufferedReader in = null;            PrintWriter out = null;            pluginList = new ArrayList();            try {                socket = new Socket(mirror, 80);                out = new PrintWriter(socket.getOutputStream(), true);                in = new BufferedReader(new InputStreamReader(socket                        .getInputStream()));                out.println("GET " + script + "?command=pluginList&apiVersion="                        + PluginLoader.getAPIVersion() + " HTTP/1.0");                out.println("Host: " + mirror + "\n");                String line = null;                String names[] = null;                int lineCount = 0;                while ((line = in.readLine()) != null) {                    if (line.equals(""))                        break;                }                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);                            com.valhalla.Logger.debug(line);                            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() + "")) {                                if (!pluginInstalled(props))                                    pluginList.add(props);                                else if (pluginUpgradable(props))                                    pluginList.add(props);                            }                        } else {                            com.valhalla.Logger.debug("Invalid plugin found.");                        }                    }                    lineCount++;                }                socket.close();            } 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(thisPointer, resources                        .getString("pluginManager"), tempMessage);                setStatusText(tempMessage);            }        });    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -