📄 winmsiwrapper.java
字号:
/** * Java wrapper for Windows MSI API MsiRecordReadStream. * @param hRecord Handle to the record. * @param iField Specifies the field of the record. * @return A buffer to receive the stream field. */ private static native byte[] msiRecordReadStream(int hRecord, int iField); /** * Java wrapper for Windows MSI API MsiGetSummaryInformation. * @param hDatabase Handle of the database. * @return Handle to the summaryInformation, errorcode. */ private static native int[] msiGetSummaryInformation(int hDatabase); /** * Java wrapper for Windows MSI API MsiSummaryInfoSetProperty. * @param hSummaryInfo Handle to the summary information. * @param uiProperty Specify the property set * @param szValue Specify the text value * @return errorcode */ private static native int msiSummaryInfoSetProperty(int hSummaryInfo, int uiProperty, byte[] szValue); /** * Java wrapper for Windows MSI API MsiSummaryInfoPersist. * @param hSummaryInfo Handle to the summary information. * @return errorcode. */ private static native int msiSummaryInfoPersist(int hSummaryInfo); /** * Java wrapper for Windows MSI API MsiCloseAllHandles. * @return This function returns 0 if all handles are closed. * Otherwise, the function returns the number of handles * open prior to its call. */ private static native int msiCloseAllHandles(); /** * Java wrapper for Windows MSI API MsiDatabaseGenerateTransform. * @param hDatabase Handle to the database includes the changes. * @param hDatabaseReference Handle to the database that does not include * the changes. * @param szTransformFile Path of the tranform file. * @return errorcode */ private static native int msiDatabaseGenerateTransform( int hDatabase, int hDatabaseReference, byte[] szTransformFile); /** * Java wrapper for Windows MSI API MsiCreateTransformSummaryInfo. * @param hDatabase Handle to the database includes the changes. * @param hDatabaseReference Handle to the database that does not * include the changes. * @param szTransformFile Path of the tranform file. * @return errorcode. */ private static native int msiCreateTransformSummaryInfo( int hDatabase, int hDatabaseReference, byte[] szTransformFile); /** * Java wrapper for MsiDatabaseImport. * @param hDatabase Handle to the database. * @param folderPath Directory where the txt table file locates. * @param txtTableName Given text table file. * @return errorcode. */ private static native int msiDatabaseImport(int hDatabase, byte[] folderPath, byte[] txtTableName); /** * Java wrapper for MsiDatabaseApplyTransform. * @param hDatabase Handle to the database. * @param transformFile The given MST file path. * @param iErrorConditions Error conditions that should be suppressed. * @return Error code. */ private static native int msiDatabaseApplyTransform( int hDatabase, byte[] transformFile, int iErrorConditions); /** * Generate a UUID. * @return A buffer containing the UUID generated */ private static native byte[] genUUID(); /** * Windows api wrapper to edit/add a string in an executable * file's string table. * @param appFilePath The given application's file path. * @param contentStr The string to be added. * @param resID The given resource ID. * @return error code. */ private static native int updateResourceString( byte[] appFilePath, byte[] contentStr, int resID); /** * Windows api wrapper to edit/add a binary data into an executable * file's resource. * @param appFilePath The given application's file path. * @param dataFilePath The given file containing the binary data. * @param resID The given resource ID. * @return error code. */ private static native int updateResourceData(byte[] appFilePath, byte[] dataFilePath, int resID); /** * Returns this java string as a null-terminated byte array. * @param str The given string to be converted. * @return The bytes translated. */ private static byte[] stringToByteArray(String str) { if (str == null) { return null; } byte[] srcByte = str.getBytes(); int srcLength = srcByte.length; byte[] result = new byte[srcLength + 1]; System.arraycopy(srcByte, 0, result, 0, srcLength); result[srcLength] = 0; return result; } /** * Converts a null-terminated byte array to java string. * @param array The given array to be converted. * @return The generated string. */ private static String byteArrayToString(byte[] array) { if (array != null) { String temString = new String(array); if (temString != null) { return temString; } } return null; } /** * Opens a database file for data access. * @param databasePath Specifies the full path or relative path to the * database file. * @param persistMode Specifies the full path to the file or the persistence * mode. * @return result[0]: error code. * result[1]: Pointer to the location of the returned database * handle if succeed * @throws IOException If fail to open the database. */ public static int[] winMsiOpenDatabase(String databasePath, int persistMode) throws IOException { int[] result = msiOpenDatabase(stringToByteArray(databasePath), persistMode); if (result[0] == ERROR_SUCCESS) { return result; } else { throw new IOException("MSI Open database failed!"); } } /** * Prepares a database query and creates a view object. * @param hDatabase Handle to the database to which you want to open * a view object. * @param szQuery Specifies a SQL query string for querying the database. * @return result[0]: error code. * result[1]: Pointer to a handle for the returned view. * @throws IOException If fail to open the view. */ public static int[] winMsiDatabaseOpenView(int hDatabase, String szQuery) throws IOException { int[] result = msiDatabaseOpenView(hDatabase, stringToByteArray(szQuery)); if (result[0] == ERROR_SUCCESS) { return result; } else { throw new IOException("MSI Database Open View Failed!"); } } /** * Executes a SQL view query and supplies any required parameters. * @param hView Handle to the view upon which to execute the query. * @param hRecord Handle to a record that supplies the parameters. * @throws IOException If fail to execute the sql. */ public static void winMsiViewExecute(int hView, int hRecord) throws IOException { if (msiViewExecute(hView, hRecord) != ERROR_SUCCESS) { throw new IOException("MSI View Execuation Failed!"); } } /** * Fetches the next sequential record from the view. * @param hView Handle to the view to fetch from. * @return result[0]: error_code. * result[1]: handle for the fetched record. * @throws IOException If fail to fetch the records. */ public static int[] winMsiViewFetch(int hView) throws IOException { int[] result = msiViewFetch(hView); if (result[0] == ERROR_SUCCESS) { return result; } else { throw new IOException("MSI View Fetch failed!"); } } /** * Returns the string value of a record field. * @param hRecord Handle to the record. * @param iField Specifies the field requested. * @return The record string */ public static String winMsiRecordGetString(int hRecord, int iField) { byte[] recordBytes = msiRecordGetString(hRecord, iField); if (recordBytes != null) { return byteArrayToString(recordBytes); } else { return null; } } /** * Copies a string into the designated field. * @param hRecord Handle to the record. * @param iField Specifies the field of the record to set. * @param valueStr Specifies the string value of the field. * @throws IOException If fail to set the record string. */ public static void winMsiRecordSetString(int hRecord, int iField, String valueStr) throws IOException { if (msiRecordSetString(hRecord, iField, stringToByteArray(valueStr)) != ERROR_SUCCESS) { throw new IOException("MSI Record Set String Failed!"); } } /** * Updates a fetched record. * @param hView Handle to a view. * @param eModifyMode Specifies the modify mode. * @param hRecord Handle to the record to modify. * @throws IOException If fail to modify the view. */ public static void winMsiViewModify(int hView, int eModifyMode, int hRecord) throws IOException { if (msiViewModify(hView, eModifyMode, hRecord) != ERROR_SUCCESS) { throw new IOException("MSI View Modification Failed!"); } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -