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

📄 msipackagegenerator.java

📁 jdic,显著提高swing性能的插件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                       + "'Removing', '1', 2)");        sqlStrings.add("INSERT INTO ControlEvent (Dialog_, Control_, Event, "                       + "Argument, Condition, Ordering) VALUES "                       + "('MaintenanceWelcomeDlg', 'Next', '[Progress2]', "                       + "'removes', '1', 3)");        sqlStrings.add("INSERT INTO ControlEvent (Dialog_, Control_, Event, "                       + "Argument, Condition, Ordering) VALUES "                       + "('MaintenanceWelcomeDlg', 'Next', 'SpawnWaitDialog', "                       + "'WaitForCostingDlg', 'CostingComplete = 1', 4)");        sqlStrings.add("INSERT INTO ControlEvent (Dialog_, Control_, Event, "                       + "Argument, Condition, Ordering) VALUES "                       + "('MaintenanceWelcomeDlg', 'Next', 'Remove', "                       + "'All', '1', 5)");        sqlStrings.add("INSERT INTO ControlEvent (Dialog_, Control_, Event, "                       + "Argument, Condition, Ordering) VALUES "                       + "('MaintenanceWelcomeDlg', 'Next', 'EndDialog', "                       + "'Return', '1', 6)");        WinMsiUtility.runSql(msiFilePath, sqlStrings);        // Create a temp place.txt file with certain content in it.        File tempTxtFile = new File(pkgInfo.getUniqueTmpDirPath()                                    + "place.txt");        FileOutputStream fis = new FileOutputStream(tempTxtFile);        String contentString = new String(AUTHOR_INFO);        byte[] bits = contentString.getBytes();        fis.write(bits, 0, contentString.length());        fis.close();        // Insert the place.txt into msi, in form of cab        // Evaluate if makecab.exe and msidb.exe exist in MSSDKPath.        String makecabFullPath = pkgInfo.getMSSDKDirPath() + MAKECAB_EXE_PATH;        String msidbFullPath = pkgInfo.getMSSDKDirPath() + MSIDB_EXE_PATH;         File temFile = new File(makecabFullPath);        if (!temFile.exists()) {            throw new IOException("Can not locate makecab.exe at" +                                   makecabFullPath);        }        temFile = new File(msidbFullPath);        if (!temFile.exists()) {            throw new IOException(                "Can not locate msidb.exe at" +                msidbFullPath);        }        String tempCabFilePath = pkgInfo.getUniqueTmpDirPath() + "Data1.cab";        Process proc = Runtime.getRuntime().exec(                "\"" + makecabFullPath + "\" " + tempTxtFile.toString()                + " " + tempCabFilePath);        try {            proc.waitFor();        } catch (InterruptedException e) {            throw new IOException(e.getMessage());        }        proc = Runtime.getRuntime().exec(                "\"" + msidbFullPath + "\" -d " + msiFilePath +                " -a " + tempCabFilePath);        try {            proc.waitFor();        } catch (InterruptedException e) {            throw new IOException(e.getMessage());        }                //Import the localized WelcomeMsg table into the template MSI file.        String tempWelcomeMsgFilePath = pkgInfo.getUniqueTmpDirPath()                                        + LOCALIZED_WELCOME_MSG_FILE_NAME;        String sysWelcomeMsgFilePath = MSI_SUPPORT_FILES_HIERARCHY_PATH                                        + LOCALIZED_WELCOME_MSG_FILE_NAME;        WinUtility.extractFileFromJarFile(                    packagerJarFilePath,                    sysWelcomeMsgFilePath,                    tempWelcomeMsgFilePath);        WinMsiUtility.importTableFromFile(                    msiFilePath,                    pkgInfo.getUniqueTmpDirPath(),                    LOCALIZED_WELCOME_MSG_FILE_NAME);    }    /**     * Generates the msi installation package.     *     * @param pkgInfo The given jnlp package info.     * @throws IOException If failed to generate the MSi package.     */    public final void generatePackage(JnlpPackageInfo pkgInfo)                throws IOException {        //get the location of packager.jar        getPackagerJarFilePath();        // Get common Info for all locale packages        // Copy user defined raw Msi file to the temp dir as en.msi        String enMsiFilePath = pkgInfo.getUniqueTmpDirPath() + "en.msi";        String rawMsiFilePath = pkgInfo.getRawMsiFilePath();        FileOperUtility.copyLocalFile(rawMsiFilePath, enMsiFilePath);        //Generate the en.msi        createTemplateMsiFile(enMsiFilePath, pkgInfo);        customizeNonLocalizedMsiFields(enMsiFilePath, pkgInfo);        //Put JavaWS product name into MSI file        putProductNameIntoMsi(enMsiFilePath, pkgInfo, JnlpConstants.LOCALE_EN);        // Adjust the relevant fields to reflect current show license setting        adjustMsiLicenseFields(enMsiFilePath, pkgInfo, JnlpConstants.LOCALE_EN);        //Generate the localized MSI file if required        if (pkgInfo.getLocalizationEnabled()) {            // Genreate a locale-specific msi file in every loop            for (int i = 1; i < JnlpConstants.LOCALES.length; i++) {                // Copy en.msi to localized msi file                String localizedMsiFilePath =                    pkgInfo.getUniqueTmpDirPath()                        + JnlpConstants.LOCALES[i]                        + ".msi";                FileOperUtility.copyLocalFile(enMsiFilePath,                        localizedMsiFilePath);                //Import the localized tables into target MSI file                importLocalizedTables(localizedMsiFilePath, pkgInfo, i);                //Put localized JavaWS product name into MSI file                putProductNameIntoMsi(localizedMsiFilePath, pkgInfo, i);                // Adjust the relevant fields to reflect current show                // license setting                adjustMsiLicenseFields(localizedMsiFilePath, pkgInfo, i);            }        }        generateBootStrapper(pkgInfo);    }    /**     * Import the localized MSI tables into the target MSI file, includes     * ActionText, Error, Control & ControlEvent.     * @param localizedMsiFilePath The localized MSI file path.     * @param pkgInfo   The given JNLP package info.     * @param localeIndex   The index of the current locale     * @throws IOException If failed to import these tables.     */    public final void importLocalizedTables(String localizedMsiFilePath,                                      JnlpPackageInfo pkgInfo,                                      int localeIndex) throws IOException {        ArrayList sqlStrings = new ArrayList();        // If Localization support enabled, we will import the        // "ActionText", "Error", "Control", "ControlEvent"        sqlStrings.add("DROP TABLE ActionText");        sqlStrings.add("DROP TABLE Error");        sqlStrings.add("DROP TABLE Control");        sqlStrings.add("DROP TABLE ControlEvent");        WinMsiUtility.runSql(localizedMsiFilePath, sqlStrings);        //Extract the tables from jar files        String localizedControlTableFileName =                "Control." + JnlpConstants.LOCALES_SUFFIX[localeIndex];        String localizedControlTableFilePath =                pkgInfo.getUniqueTmpDirPath() + localizedControlTableFileName;        String localizedControlEventTableFileName =                "ControlEvent." + JnlpConstants.LOCALES_SUFFIX[localeIndex];        String localizedControlEventTableFilePath =                pkgInfo.getUniqueTmpDirPath()                + localizedControlEventTableFileName;        WinUtility.extractFileFromJarFile(            packagerJarFilePath,            MSI_SUPPORT_FILES_HIERARCHY_PATH + localizedControlTableFileName,            localizedControlTableFilePath);        WinUtility.extractFileFromJarFile(            packagerJarFilePath,            MSI_SUPPORT_FILES_HIERARCHY_PATH            + localizedControlEventTableFileName,            localizedControlEventTableFilePath);        // Import the ActionText table        WinMsiUtility.importTableFromFile(            localizedMsiFilePath,            pkgInfo.getUniqueTmpDirPath(),            "ActionTe." + JnlpConstants.LOCALES_SUFFIX[localeIndex]);        // Import the Error table        WinMsiUtility.importTableFromFile(                localizedMsiFilePath,                pkgInfo.getUniqueTmpDirPath(),                "Error" + JnlpConstants.LOCALES_SUFFIX[localeIndex]);        //Import the Control table        WinMsiUtility.importTableFromFile(                localizedMsiFilePath,                pkgInfo.getUniqueTmpDirPath(),                localizedControlTableFileName);        //Import the Control event table        WinMsiUtility.importTableFromFile(                localizedMsiFilePath,                pkgInfo.getUniqueTmpDirPath(),                localizedControlEventTableFileName);    }    /**     * Put localized product name into the MSI file.     *     * @param localizedMsiFilePath The localized MSI file path.     * @param pkgInfo   The given jnlp package info.     * @param localeIndex    The index of current locale.     * @throws IOException If failed to put the product name into MSI.     */    public final void putProductNameIntoMsi(String localizedMsiFilePath,                                            JnlpPackageInfo pkgInfo,                                            int localeIndex)                                            throws IOException {        TreeMap treeMap = new TreeMap();        try {            treeMap.clear();            treeMap.put(                "ProductName",                pkgInfo.getLocalizedJnlpInfo(                        JnlpConstants.LOCALES[localeIndex],                        JnlpConstants.JNLP_FIELD_TITLE));            treeMap.put("Locale", JnlpConstants.LOCALES[localeIndex]);            WinMsiUtility.winMsiSetProperty(                    localizedMsiFilePath,                    "Property",                    "Property",                    2,                    false,                    treeMap);        } catch (IOException e) {            throw new IOException(                "Property Table: Modify ProductName field failed!");        }    }    /**     * Generate the target boot strapper file.     *     * @param pkgInfo The given package information.     * @todo Get the target bootstrapper file name     *     * @throws IOException If failed to generate the bootstrapper.     */    public final void generateBootStrapper(JnlpPackageInfo pkgInfo)        throws IOException {        //Get the MSI file name for locale en, The localized msi file naming        // schema would be locale.msi        //e.g. zh_cn.msi        String enMsiFilePath =            pkgInfo.getUniqueTmpDirPath()                + JnlpConstants.LOCALES[JnlpConstants.LOCALE_EN]                + ".msi";        //If there is localization requirement, we'll then generate the 9        //mst files and incorporate them into the en.msi        if (pkgInfo.getLocalizationEnabled()) {            // Genreate a locale-specific mst file in every loop, the msi file            // naming schema would be locale.mst, e.g. zh_cn.mst            String localizedMsiFilePath;            String targetMstFilePath;            for (int i = 1; i < JnlpConstants.LOCALES.length; i++) {                localizedMsiFilePath =                    pkgInfo.getUniqueTmpDirPath()                        + JnlpConstants.LOCALES[i]                        + ".msi";                targetMstFilePath =                    pkgInfo.getUniqueTmpDirPath()                        + JnlpConstants.LOCALES[i]                        + ".mst";                WinMsiUtility.generateTransform(                    enMsiFilePath,                    localizedMsiFilePath,                    targetMstFilePath);            }            // Incorporate the 9 mst files into file en.msi, these mst files            // woule be insert into _Storage table with each name as            // cust_locale, e.g. cust_zh_cn, cust_fr.            String newFieldName;            for (int i = 1; i < JnlpConstants.LOCALES.length; i++) {                targetMstFilePath =                    pkgInfo.getUniqueTmpDirPath()                        + JnlpConstants.LOCALES[i]                        + ".mst";                newFieldName = "cust_" + JnlpConstants.LOCALES[i];                WinMsiUtility.incorporateMST(                    enMsiFilePath,                    targetMstFilePath,                    newFieldName);            }        }        //Extract the bootstrapper from the jar file        String tempBootStrapperFilePath =            pkgInfo.getUniqueTmpDirPath() + pkgInfo.getPackageName() + ".exe";        WinUtility.extractFileFromJarFile(            packagerJarFilePath,            SYS_BOOTSTRAPPER_FILE_PATH,            tempBootStrapperFilePath);        //Store an UUID into the bootstrapper resource, which can be used to        // identify whether there        //are more than one instance running        String exeUUID = WinMsiUtility.genUUID();        WinUtility.updateResourceString(            tempBootStrapperFilePath,            exeUUID,            WinUtility.STRING_RES_UUID_ID);        //Incorporate the en.msi into the bootstrpper resources        WinUtility.updateResourceData(            tempBootStrapperFilePath,            enMsiFilePath,            WinUtility.BIN_RES_ID);        //Store a flag string indicating whether localization is supported        String localizationFlag;        if (pkgInfo.getLocalizationEnabled()) {            localizationFlag = "localization supported";        } else {            localizationFlag = "no localization support";        }        WinUtility.updateResourceString(            tempBootStrapperFilePath,            localizationFlag,            WinUtility.STRING_RES_LOCALIZATION_FLAG_ID);        //Copy the generated bootstrapper from temp dir to target dir        String targetBootStrapperFilePath =            pkgInfo.getOutputDirPath() + pkgInfo.getPackageName() + ".exe";        FileOperUtility.copyLocalFile(tempBootStrapperFilePath,                                 targetBootStrapperFilePath);        //Indicate user where the file has been generated        File targetFile = new File(targetBootStrapperFilePath);        if (targetFile.exists()) {            System.out.println("\nSuccess: The bootstrapper MSI file has been" +                " generated at: \n" + targetBootStrapperFilePath + "\n");           }        //Remove the Unique Tmp Dir        File tempDir = new File(pkgInfo.getUniqueTmpDirPath());        FileOperUtility.deleteDirTree(tempDir);    }}

⌨️ 快捷键说明

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