installer.java

来自「开源项目openfire的完整源程序」· Java 代码 · 共 114 行

JAVA
114
字号
/** * $Revision: $ * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Lesser Public License (LGPL), * a copy of which is included in this distribution. */package org.jivesoftware.launcher;import com.install4j.api.actions.InstallAction;import com.install4j.api.context.Context;import com.install4j.api.context.InstallerContext;import com.install4j.api.context.UserCanceledException;import com.install4j.api.windows.RegistryRoot;import com.install4j.api.windows.WinRegistry;import java.io.File;import javax.swing.JOptionPane;/** * The installer class is used by the Install4j Installer to setup registry entries * during the setup process. */public class Installer implements InstallAction {    private InstallerContext context;    public int getPercentOfTotalInstallation() {        return 0;    }    public void init(Context context) {    }    public boolean install(InstallerContext installerContext) throws UserCanceledException {        context = installerContext;        final String osName = System.getProperty("os.name").toLowerCase();        boolean isWindows = osName.startsWith("windows");        if (!isWindows) {            return true;        }        final File sparkDirectory;        String sparkPath = "";        try {            sparkDirectory = new File(installerContext.getInstallationDirectory(), "Spark.exe");            sparkPath = sparkDirectory.getCanonicalPath();        }        catch (Exception e) {            e.printStackTrace();        }        if (sparkPath != null && sparkPath.length() > 0) {            // Add Spark to startup            addSparkToStartup(sparkPath);            // Add Spark XMPP:URI mapping            setURI(sparkPath);        }        return true;    }    public void rollback(InstallerContext installerContext) {        WinRegistry.deleteValue(RegistryRoot.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "Spark");    }    /**     * Adds Spark to the users registry.     *     * @param sparkPath the canonical path to spark.     */    public void addSparkToStartup(String sparkPath) {        try {            WinRegistry.setValue(RegistryRoot.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "Spark", sparkPath);        }        catch (Exception e) {            e.printStackTrace();        }    }    /**     * Adds Spark to the users registry to allow for XMPP URI mapping.     *     * @param path the installation directory of spark.     */    private void setURI(String path) {        boolean exists = WinRegistry.keyExists(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp");        if (exists) {        }        //   JOptionPane.showConfirmDialog(null, "Another application is currently registered to handle XMPP instant messaging. Make Spark the default XMPP instant messaging client?", "Confirmation",         }        WinRegistry.deleteKey(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp", true);        WinRegistry.createKey(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp");        WinRegistry.setValue(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp", "", "URL:XMPP Address");        WinRegistry.setValue(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp", "URL Protocol", "");        WinRegistry.createKey(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp\\shell\\open\\command");        WinRegistry.setValue(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp\\shell\\open\\command", "", path + " %1");    }}

⌨️ 快捷键说明

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