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

📄 winmsiutility.java

📁 jdic,显著提高swing性能的插件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            for (int i = 0; i < fieldNames.length; i++) {                if ((fieldProperties[i].compareToIgnoreCase("String")) == 0) {                    WinMsiWrapper.winMsiRecordSetString(hRecord, i + 1,                                                        fieldValues[i]);                    WinMsiWrapper.winMsiViewExecute(hView, hRecord);                }                if ((fieldProperties[i].compareToIgnoreCase("Stream")) == 0) {                    WinMsiWrapper.winMsiRecordSetStream(hRecord, i + 1,                                                        fieldValues[i]);                    WinMsiWrapper.winMsiViewModify(                                  hView,                                  WinMsiWrapper.MSIMODIFY_ASSIGN,                                  hRecord);                }            }           WinMsiWrapper.winMsiDatabaseCommit(hMsiDatabase);       } finally {           WinMsiWrapper.winMsiCloseHandle(hRecord);           closeView(hView);           WinMsiWrapper.winMsiCloseHandle(hMsiDatabase);       }    }    /**     * Incorporate the mst file into the msi database "_Storages" table with     *  the name as fieldsName.     * @param msiFilePath Given msi file path.     * @param mstFilePath Given mst file path.     * @param fieldName Given field name.     * @throws IOException If failed to incorporate the MST file.     */    public static void incorporateMST(String msiFilePath,                                      String mstFilePath,                                      String fieldName)                                      throws IOException {        String[] fieldNames = new String[] {"Name", "Data"};        String tableName = "_Storages";        String[] fieldProperties = new String[] {"String", "Stream"};        String[] fieldValues = new String[] {fieldName, mstFilePath};        addBinaryRecord(msiFilePath, tableName, fieldNames,                        fieldProperties, fieldValues);    }    /**     * Import a table from a table txt file representation.     * @param msiFilePath   The msi file path.     * @param folderPath    The directory where the txt file locates.     * @param txtTableName  The txt file name.     * @throws IOException If failed to import the table from the file.     */    public static void importTableFromFile(String msiFilePath,                                           String folderPath,                                           String txtTableName)                                           throws IOException {       int hDatabase = 0;       try {           hDatabase = openDatabase(msiFilePath);           WinMsiWrapper.winMsiDatabaseImport(hDatabase,                                              folderPath,                                              txtTableName);           WinMsiWrapper.winMsiDatabaseCommit(hDatabase);       } finally {           WinMsiWrapper.winMsiCloseHandle(hDatabase);       }    }    /**     * Appy the MST transform onto the MSI file.     * @param msiFilePath The specified MSI path.     * @param mstFilePath The specified MST path.     * @throws IOException If failed to apply the transform.     */    public static void applyMstToMsi(String msiFilePath,                                     String mstFilePath)                                     throws IOException {        int[] result = new int[] {0, 0};        try {            result = WinMsiWrapper.winMsiOpenDatabase(                                        msiFilePath,                                        WinMsiWrapper.MSIDBOPEN_TRANSACT);            //Get the database handle if succeed            int hDatabase = result[1];            WinMsiWrapper.winMsiDatabaseApplyTransform(hDatabase, mstFilePath);            WinMsiWrapper.winMsiDatabaseCommit(hDatabase);            WinMsiWrapper.winMsiCloseHandle(hDatabase);        } catch (IOException e) {            System.out.println(e);        }    }    /**     * Sets the record value field with the new value.     * @param hView The given view.     * @param hRecord The given record.     * @param valueIndex The value column index.     * @param isBinary Specify whether the field is binary field.     * @param newValue New value to be replaced with.     * @throws IOException If fail to set the record property.     */    private static void setRecordProperty(int hView,                                          int hRecord,                                          int valueIndex,                                          boolean isBinary,                                          String newValue)                                          throws IOException {        try {            if (isBinary) {                WinMsiWrapper.winMsiRecordSetStream(hRecord,                                                    valueIndex,                                                    newValue);            } else {                WinMsiWrapper.winMsiRecordSetString(hRecord,                                                    valueIndex,                                                    newValue);            }            WinMsiWrapper.winMsiViewModify(hView,                                           WinMsiWrapper.MSIMODIFY_REPLACE,                                           hRecord);        } finally {            WinMsiWrapper.winMsiCloseHandle(hRecord);        }    }    /**     * Opens the given databse.     * @param msiFilePath Database file path.     * @return The handle to the opened MSI database.     * @throws IOException If fail to open the MSI database.     */    private static int openDatabase(String msiFilePath) throws IOException {        int[] result = new int[] {ERROR_FAIL, 0};        result = WinMsiWrapper.winMsiOpenDatabase(                               msiFilePath,                               WinMsiWrapper.MSIDBOPEN_TRANSACT);        //return the database handle if succeed        return result[1];    }    /**     * Opens the msi summary information stream.     * @param hDatabase Handle of the msi database opened.     * @return The summary information stream handle.     * @throws IOException If failed to open the Summary Info stream.     */    private static int openSummaryInfo(int hDatabase) throws IOException {        int[] result = new int[] {ERROR_FAIL, 0};        result = WinMsiWrapper.winMsiGetSummaryInformation(hDatabase);        //return the summary information stream handle        return result[1];    }    /**     * Opens a table in the given database.     * @param hDatabase The database handle.     * @param tableName The name of the table to be opened.     * @param fieldNames The fields to be selected.     * @param criterial The records selecting criterial.     * @return Handle to the opened view.     * @throws IOException If fail to open the view.     */    private static int openView(int hDatabase,                                String tableName,                                String fieldNames,                                String criterial)                                throws IOException {        int[] result = new int[] {ERROR_FAIL, 0};        //Constructs a sql string        String sqlSelectStr = "select " + fieldNames + " from " + tableName                              + " " + criterial;        result = WinMsiWrapper.winMsiDatabaseOpenView(hDatabase, sqlSelectStr);        int hView = result[1];        WinMsiWrapper.winMsiViewExecute(hView, 0);        return hView;    }    /**     * Close the view and view handle.     * @param hView Handle to view.     * @throws IOException If fail to close the view.     */    private static void closeView(int hView) throws IOException {        WinMsiWrapper.winMsiViewClose(hView);        WinMsiWrapper.winMsiCloseHandle(hView);    }    /**     * Returns the handle to the record.     * @param hView The given view.     * @return Handle to the record if succeed.     * @throws IOException If fail to get the record.     */    private static int getRecord(int hView) throws IOException {       int[] result;       result = WinMsiWrapper.winMsiViewFetch(hView);       if (result[0] == WinMsiWrapper.ERROR_NO_MORE_ITEMS) {           //No records found, just return zero (indicating null record)           return 0;       } else {           //return a valid record handle if succeed           return result[1];       }    }    /**     * Gets the localized welcome msg according to license display status.     * @param msiFilePath The given msi file path.     * @param locale The name of the current locale.     * @param isShowLicense Whether the license information gets displayed.     * @return The localized welcome message (according to isShowLicense).     * @throws IOException If failed to get the welcome message.     */    public static String getWelcomeMsg(String msiFilePath,                                        String locale,                                        boolean isShowLicense)                                        throws IOException {        int hDatabase = 0;        int hView = 0;        int hRecord = 0;        try {            hDatabase = openDatabase(msiFilePath);            String tableName =                    MsiPackageGenerator.LOCALIZED_WELCOME_MSG_TABLE_NAME;            String fieldNames = "*";            String criterial = " where "                               + "Locale = '"                               + locale                               + "'";            hView = openView(hDatabase, tableName, fieldNames, criterial);            hRecord = getRecord(hView);            String welcomeMsg = null;            if (isShowLicense) {                welcomeMsg = WinMsiWrapper.winMsiRecordGetString(                                hRecord,                                LICENSED_WELCOME_MSG_FIELD_INDEX);            } else {                welcomeMsg = WinMsiWrapper.winMsiRecordGetString(                                hRecord,                                NON_LICENSED_WELCOME_MSG_FIELD_INDEX);            }            return welcomeMsg;        } finally {            WinMsiWrapper.winMsiCloseHandle(hRecord);            closeView(hView);            WinMsiWrapper.winMsiCloseHandle(hDatabase);        }    }    /**     * Generate a UUID String.     * @return String representing the UUID.     * @throws IOException If fail to generate the UUID.     */    public static String genUUID() throws IOException {        String oneUUID = WinMsiWrapper.generateUUID();        if (oneUUID != null) {            return oneUUID.toUpperCase();        } else {            throw new IOException("Could not generate the UUID.");        }    }}

⌨️ 快捷键说明

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