KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > packager > impl > WinMsiWrapper


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.packager.impl;
22
23 import java.io.IOException JavaDoc;
24 /**
25  * Bottom layer java wrapper for Windows MSI APIs.
26  */

27 public class WinMsiWrapper {
28
29     static {
30         System.loadLibrary("WinMsiWrapper");
31     }
32
33     //MsiOpenDatabase constants
34
/**
35      * Create a new database, transact mode read/write.
36      */

37     public static final int MSIDBOPEN_CREATE = 3;
38     /**
39      * Open a database direct read/write without transaction.
40      */

41     public static final int MSIDBOPEN_DIRECT = 2;
42     /**
43      * Open a database read-only, no persistent changes.
44      */

45     public static final int MSIDBOPEN_READONLY = 0;
46     /**
47      * Open a database read/write in transaction mode.
48      */

49     public static final int MSIDBOPEN_TRANSACT = 1;
50
51     //MsiViewModify mode constants
52
/**
53      * Refreshes the information in the supplied record without changing the
54      * position in the result set and without affecting subsequent
55      * fetch operations.
56      */

57     public static final int MSIMODIFY_SEEK = -1;
58     /**
59      * Refreshes the information in the record. Must first call MsiViewFetch
60      * with the same record.
61      */

62     public static final int MSIMODIFY_REFRESH = 0;
63     /**
64      * Inserts a record.
65      */

66     public static final int MSIMODIFY_INSERT = 1;
67     /**
68      * Updates an existing record.
69      */

70     public static final int MSIMODIFY_UPDATE = 2;
71     /**
72      * Writes current data in the cursor to a table row.
73      */

74     public static final int MSIMODIFY_ASSIGN = 3;
75     /**
76      * Updates or deletes and inserts a record into a table.
77      */

78     public static final int MSIMODIFY_REPLACE = 4;
79     /**
80      * Inserts or validates a record in a table.
81      */

82     public static final int MSIMODIFY_MERGE = 5;
83     /**
84      * Remove a row from the table.
85      */

86     public static final int MSIMODIFY_DELETE = 6;
87     /**
88      * Inserts a temporary record.
89      */

90     public static final int MSIMODIFY_INSERT_TEMPORARY = 7;
91     /**
92      * Validates a record.
93      */

94     public static final int MSIMODIFY_VALIDATE = 8;
95     /**
96      * Validate a new record.
97      */

98     public static final int MSIMODIFY_VALIDATE_NEW = 9;
99     /**
100      * Validates fields of a fetched or new record.
101      */

102     public static final int MSIMODIFY_VALIDATE_FIELD = 10;
103     /**
104      * Validates a record that will be deleted later.
105      */

106     public static final int MSIMODIFY_VALIDATE_DELETE = 11;
107
108     //Error code
109
/**
110      * The function succeeded.
111      */

112     public static final int ERROR_SUCCESS = 0;
113     /**
114      * Access was not permitted.
115      */

116     public static final int ERROR_ACCESS_DENIED = 5;
117     /**
118      * An invalid or inactive handle was supplied.
119      */

120     public static final int ERROR_INVALID_HANDLE = 6;
121     /**
122      * A validation was requested and the data did not pass.
123      */

124     public static final int ERROR_INVALID_DATA = 13;
125     /**
126      * One of the parameters was invalid.
127      */

128     public static final int ERROR_INVALID_PARAMETER = 87;
129     /**
130      * The database could not be opened as requested.
131      */

132     public static final int ERROR_OPEN_FAILED = 110;
133     /**
134      * An invalid path was supplied.
135      */

136     public static final int ERROR_BAD_PATHNAME = 161;
137     /**
138      * No records remain, and a NULL handle is returned.
139      */

140     public static final int ERROR_NO_MORE_ITEMS = 259;
141     /**
142      * The handle is in an invalid state.
143      */

144     public static final int ERROR_INVALID_HANDLE_STATE = 1609;
145     /**
146      * An invalid SQL query string was passed to the function.
147      */

148     public static final int ERROR_BAD_QUERY_SYNTAX = 1615;
149     /**
150      * The database could not be created.
151      */

152     public static final int ERROR_CREATE_FAILED = 1631;
153     /**
154      * A view could not be executed.
155      */

156     public static final int ERROR_FUNCTION_FAILED = 1627;
157
158     /**
159      * Java wrapper for Windows MSI API MsiOpenDatabase.
160      * @param databasePath Specifies the full path or relative path to the
161      * database file
162      * @param persist Receives the full path to the file or the persistence
163      * mode. You can use the szPersist parameter to direct the
164      * persistent output to a new file or to specify one of the
165      * following predefined persistence modes.
166      * @return result[0]: Pointer to the location of the returned database
167      * handle if succeed.
168      * result[1]: error code.
169      */

170     private static native int[] msiOpenDatabase(byte[] databasePath,
171                                                        int persist);
172
173     /**
174      * Java wrapper for Windows MSI API MsiDatabaseOpenView.
175      * @param hDatabase Handle to the database to which you want to open
176      * a view object.
177      * @param szQuery Specifies a SQL query string for querying the database.
178      * @return result[0]: error code.
179      * result[1]: Pointer to a handle for the returned view.
180      */

181     private static native int[] msiDatabaseOpenView(int hDatabase,
182                                                     byte[] szQuery);
183
184     /**
185      * Java wrapper for Windows MSI API MsiViewExecute.
186      * @param hView Handle to the view upon which to execute the query.
187      * @param hRecord Handle to a record that supplies the parameters.
188      * @return error_code
189      */

190     private static native int msiViewExecute(int hView, int hRecord);
191
192     /**
193      * Java wrapper for Windows MSI API MsiViewFetch.
194      * @param hView Handle to the view to fetch from.
195      * @return result[0]: error_code.
196      * result[1]: handle for the fetched record.
197      */

198     private static native int[] msiViewFetch(int hView);
199
200     /**
201      * Java wrapper for Windows MSI API MsiRecordGetString.
202      * @param hRecord Handle to the record.
203      * @param iField Specifies the field requested.
204      * @return the returned string
205      */

206     private static native byte[] msiRecordGetString(int hRecord, int iField);
207
208     /**
209      * Java wrapper for Windows MSI API MsiRecordSetString.
210      * @param hRecord Handle to the record.
211      * @param iField Specifies the field of the record to set.
212      * @param szValue Specifies the string value of the field.
213      * @return error_code
214      */

215     private static native int msiRecordSetString(int hRecord,
216                                                  int iField,
217                                                  byte[] szValue);
218
219     /**
220      * Java wrapper for Windows MSI API MsiViewModify.
221      * @param hView Handle to a view.
222      * @param eModifyMode Specifies the modify mode.
223      * @param hRecord Handle to the record to modify.
224      * @return error_code
225      */

226     private static native int msiViewModify(int hView,
227                                             int eModifyMode,
228                                             int hRecord);
229
230     /**
231      * Java wrapper for Windows MSI API MsiRecordGetFieldCount.
232      * @param hRecord Handle to a record.
233      * @return If the function succeeds, the return value is the number of
234      * fields in the record. If the function is given an invalid or
235      * inactive handle, it returns -1 or 0xFFFFFFFF.
236      */

237     private static native int msiRecordGetFieldCount(int hRecord);
238
239     /**
240      * Java Wrapper for Windows API MsiCreateRecord.
241      * @param numRecords Number of fields to be created in this record
242      * @return If the function succeeds, the return type is the handle to
243      * the record.
244      */

245     private static native int msiCreateRecord(int numRecords);
246
247     /**
248      * Java wrapper for Windows MSI API MsiViewClose.
249      * @param hView Handle to a view that is set to release.
250      * @return error_code
251      */

252     private static native int msiViewClose(int hView);
253
254     /**
255      * Java wrapper for Windows MSI API MsiDatabaseCommit.
256      * @param hDatabase Handle to the database.
257      * @return error_code
258      */

259     private static native int msiDatabaseCommit(int hDatabase);
260
261     /**
262      * Java wrapper for Windows MSI API MsiCloseHandle.
263      * @param hAny Specifies any open installation handle.
264      * @return error_code
265      */

266     private static native int msiCloseHandle(int hAny);
267
268     /**
269      * Java wrapper for Windows MSI API MsiRecordSetStream.
270      * @param hRecord Handle to the record.
271      * @param iField Specifies the field of the record to set.
272      * @param szFilePath Specifies the path to the file containing the stream.
273      * @return error_code
274      */

275     private static native int msiRecordSetStream(int hRecord,
276                                                  int iField,
277                                                  byte[] szFilePath);
278
279     /**
280      * Java wrapper for Windows MSI API MsiRecordReadStream.
281      * @param hRecord Handle to the record.
282      * @param iField Specifies the field of the record.
283      * @return A buffer to receive the stream field.
284      */

285     private static native byte[] msiRecordReadStream(int hRecord, int iField);
286
287     /**
288      * Java wrapper for Windows MSI API MsiGetSummaryInformation.
289      * @param hDatabase Handle of the database.
290      * @return Handle to the summaryInformation, errorcode.
291      */

292     private static native int[] msiGetSummaryInformation(int hDatabase);
293
294     /**
295      * Java wrapper for Windows MSI API MsiSummaryInfoSetProperty.
296      * @param hSummaryInfo Handle to the summary information.
297      * @param uiProperty Specify the property set
298      * @param szValue Specify the text value
299      * @return errorcode
300      */

301     private static native int msiSummaryInfoSetProperty(int hSummaryInfo,
302                                                         int uiProperty,
303                                                         byte[] szValue);
304
305     /**
306      * Java wrapper for Windows MSI API MsiSummaryInfoPersist.
307      * @param hSummaryInfo Handle to the summary information.
308      * @return errorcode.
309      */

310     private static native int msiSummaryInfoPersist(int hSummaryInfo);
311
312     /**
313      * Java wrapper for Windows MSI API MsiCloseAllHandles.
314      * @return This function returns 0 if all handles are closed.
315      * Otherwise, the function returns the number of handles
316      * open prior to its call.
317      */

318     private static native int msiCloseAllHandles();
319
320     /**
321      * Java wrapper for Windows MSI API MsiDatabaseGenerateTransform.
322      * @param hDatabase Handle to the database includes the changes.
323      * @param hDatabaseReference Handle to the database that does not include
324      * the changes.
325      * @param szTransformFile Path of the tranform file.
326      * @return errorcode
327      */

328     private static native int msiDatabaseGenerateTransform(
329                 int hDatabase,
330                 int hDatabaseReference,
331                 byte[] szTransformFile);
332
333     /**
334      * Java wrapper for Windows MSI API MsiCreateTransformSummaryInfo.
335      * @param hDatabase Handle to the database includes the changes.
336      * @param hDatabaseReference Handle to the database that does not
337      * include the changes.
338      * @param szTransformFile Path of the tranform file.
339      * @return errorcode.
340      */

341     private static native int msiCreateTransformSummaryInfo(
342             int hDatabase,
343             int hDatabaseReference,
344             byte[] szTransformFile);
345
346     /**
347      * Java wrapper for MsiDatabaseImport.
348      * @param hDatabase Handle to the database.
349      * @param folderPath Directory where the txt table file locates.
350      * @param txtTableName Given text table file.
351      * @return errorcode.
352      */

353     private static native int msiDatabaseImport(int hDatabase,
354                                                 byte[] folderPath,
355                                                 byte[] txtTableName);
356
357     /**
358      * Java wrapper for MsiDatabaseApplyTransform.
359      * @param hDatabase Handle to the database.
360      * @param transformFile The given MST file path.
361      * @param iErrorConditions Error conditions that should be suppressed.
362      * @return Error code.
363      */

364     private static native int msiDatabaseApplyTransform(
365             int hDatabase,
366             byte[] transformFile,
367             int iErrorConditions);
368
369     /**
370      * Generate a UUID.
371      * @return A buffer containing the UUID generated
372      */

373     private static native byte[] genUUID();
374
375     /**
376      * Windows api wrapper to edit/add a string in an executable
377      * file's string table.
378      * @param appFilePath The given application's file path.
379      * @param contentStr The string to be added.
380      * @param resID The given resource ID.
381      * @return error code.
382      */

383     private static native int updateResourceString(
384         byte[] appFilePath,
385         byte[] contentStr,
386         int resID);
387
388     /**
389      * Windows api wrapper to edit/add a binary data into an executable
390      * file's resource.
391      * @param appFilePath The given application's file path.
392      * @param dataFilePath The given file containing the binary data.
393      * @param resID The given resource ID.
394      * @return error code.
395      */

396     private static native int updateResourceData(byte[] appFilePath,
397                                                  byte[] dataFilePath,
398                                                  int resID);
399
400     /**
401      * Returns this java string as a null-terminated byte array.
402      * @param str The given string to be converted.
403      * @return The bytes translated.
404      */

405     private static byte[] stringToByteArray(String JavaDoc str) {
406         if (str == null) {
407             return null;
408         }
409
410         byte[] srcByte = str.getBytes();
411         int srcLength = srcByte.length;
412         byte[] result = new byte[srcLength + 1];
413
414         System.arraycopy(srcByte, 0, result, 0, srcLength);
415         result[srcLength] = 0;
416
417         return result;
418     }
419
420     /**
421      * Converts a null-terminated byte array to java string.
422      * @param array The given array to be converted.
423      * @return The generated string.
424      */

425     private static String JavaDoc byteArrayToString(byte[] array) {
426         if (array != null) {
427             String JavaDoc temString = new String JavaDoc(array);
428
429             if (temString != null) {
430                 return temString;
431             }
432         }
433         return null;
434     }
435
436     /**
437      * Opens a database file for data access.
438      * @param databasePath Specifies the full path or relative path to the
439      * database file.
440      * @param persistMode Specifies the full path to the file or the persistence
441      * mode.
442      * @return result[0]: error code.
443      * result[1]: Pointer to the location of the returned database
444      * handle if succeed
445      * @throws IOException If fail to open the database.
446      */

447     public static int[] winMsiOpenDatabase(String JavaDoc databasePath,
448                                            int persistMode) throws IOException JavaDoc {
449         int[] result = msiOpenDatabase(stringToByteArray(databasePath),
450                                        persistMode);
451         if (result[0] == ERROR_SUCCESS) {
452             return result;
453         } else {
454             throw new IOException JavaDoc("MSI Open database failed!");
455         }
456     }
457
458     /**
459      * Prepares a database query and creates a view object.
460      * @param hDatabase Handle to the database to which you want to open
461      * a view object.
462      * @param szQuery Specifies a SQL query string for querying the database.
463      * @return result[0]: error code.
464      * result[1]: Pointer to a handle for the returned view.
465      * @throws IOException If fail to open the view.
466      */

467     public static int[] winMsiDatabaseOpenView(int hDatabase,
468                                                String JavaDoc szQuery)
469                                                throws IOException JavaDoc {
470         int[] result = msiDatabaseOpenView(hDatabase,
471                                            stringToByteArray(szQuery));
472         if (result[0] == ERROR_SUCCESS) {
473             return result;
474         } else {
475             throw new IOException JavaDoc("MSI Database Open View Failed!");
476         }
477     }
478
479     /**
480      * Executes a SQL view query and supplies any required parameters.
481      * @param hView Handle to the view upon which to execute the query.
482      * @param hRecord Handle to a record that supplies the parameters.
483      * @throws IOException If fail to execute the sql.
484      */

485     public static void winMsiViewExecute(int hView, int hRecord)
486                                         throws IOException JavaDoc {
487         if (msiViewExecute(hView, hRecord) != ERROR_SUCCESS) {
488             throw new IOException JavaDoc("MSI View Execuation Failed!");
489         }
490     }
491
492     /**
493      * Fetches the next sequential record from the view.
494      * @param hView Handle to the view to fetch from.
495      * @return result[0]: error_code.
496      * result[1]: handle for the fetched record.
497      * @throws IOException If fail to fetch the records.
498      */

499     public static int[] winMsiViewFetch(int hView) throws IOException JavaDoc {
500         int[] result = msiViewFetch(hView);
501         if (result[0] == ERROR_SUCCESS) {
502             return result;
503         } else {
504             throw new IOException JavaDoc("MSI View Fetch failed!");
505         }
506     }
507
508     /**
509      * Returns the string value of a record field.
510      * @param hRecord Handle to the record.
511      * @param iField Specifies the field requested.
512      * @return The record string
513      */

514     public static String JavaDoc winMsiRecordGetString(int hRecord, int iField) {
515         byte[] recordBytes = msiRecordGetString(hRecord, iField);
516         if (recordBytes != null) {
517             return byteArrayToString(recordBytes);
518         } else {
519             return null;
520         }
521     }
522
523     /**
524      * Copies a string into the designated field.
525      * @param hRecord Handle to the record.
526      * @param iField Specifies the field of the record to set.
527      * @param valueStr Specifies the string value of the field.
528      * @throws IOException If fail to set the record string.
529      */

530     public static void winMsiRecordSetString(int hRecord,
531                                              int iField,
532                                              String JavaDoc valueStr)
533                                              throws IOException JavaDoc {
534         if (msiRecordSetString(hRecord, iField, stringToByteArray(valueStr))
535                         != ERROR_SUCCESS) {
536             throw new IOException JavaDoc("MSI Record Set String Failed!");
537         }
538     }
539
540     /**
541      * Updates a fetched record.
542      * @param hView Handle to a view.
543      * @param eModifyMode Specifies the modify mode.
544      * @param hRecord Handle to the record to modify.
545      * @throws IOException If fail to modify the view.
546      */

547     public static void winMsiViewModify(int hView, int eModifyMode, int hRecord)
548                         throws IOException JavaDoc {
549         if (msiViewModify(hView, eModifyMode, hRecord) != ERROR_SUCCESS) {
550             throw new IOException JavaDoc("MSI View Modification Failed!");
551         }
552     }
553
554     /**
555      * Returns the number of fields in a record.
556      * @param hRecord Handle to a record.
557      * @return If the function succeeds, the return value is the number of
558      * fields in the record. If the function is given an invalid or
559      * inactive handle, it returns -1 or 0xFFFFFFFF.
560      * @throws IOException If fail to get fields count.
561      */

562     public static int winMsiRecordGetFieldCount(int hRecord)
563                 throws IOException JavaDoc {
564         int nFields = msiRecordGetFieldCount(hRecord);
565         if (nFields != -1) {
566             return nFields;
567         } else {
568             throw new IOException JavaDoc("MSI Record Get Field Count Failed!");
569         }
570     }
571
572     /**
573      * Releases the result set for an executed view.
574      * @param hView Handle to a view that is set to release.
575      * @throws IOException If fail to close the view.
576      */

577     public static void winMsiViewClose(int hView) throws IOException JavaDoc {
578         if (msiViewClose(hView) != ERROR_SUCCESS) {
579             throw new IOException JavaDoc("MSI View Close Failed!");
580         }
581     }
582
583     /**
584      * Commits changes to a database.
585      * @param hDatabase Handle to the database.
586      * @throws IOException If fail to commit the changes.
587      */

588     public static void winMsiDatabaseCommit(int hDatabase) throws IOException JavaDoc {
589         if (msiDatabaseCommit(hDatabase) != ERROR_SUCCESS) {
590             throw new IOException JavaDoc("MSI Database Commit Failed!");
591         }
592     }
593
594     /**
595      * Apply the transform to the MSI database.
596      * @param hDatabase Handle of the MSI database.
597      * @param transformFile The MST file containing the transform information.
598      * @throws IOException If fail to apply the transform.
599      */

600     public static void winMsiDatabaseApplyTransform(int hDatabase,
601                                                     String JavaDoc transformFile)
602                                                     throws IOException JavaDoc {
603         if (ERROR_SUCCESS
604             != msiDatabaseApplyTransform(hDatabase,
605                stringToByteArray(transformFile), 0)) {
606             throw new IOException JavaDoc("MSI Database apply tranform failed!");
607         }
608     }
609
610     /**
611      * Closes an open installation handle.
612      * @param hAny Specifies any open installation handle.
613      * @throws IOException If fail to close the handle.
614      */

615     public static void winMsiCloseHandle(int hAny) throws IOException JavaDoc {
616         if (msiCloseHandle(hAny) != ERROR_SUCCESS) {
617             throw new IOException JavaDoc("MSI Close Handle Failed!");
618         }
619     }
620
621     /**
622      * Sets a record stream field from a file.
623      * @param hRecord Handle to the record.
624      * @param iField Specifies the field of the record to set.
625      * @param filePathStr Specifies the path to the file containing the stream.
626      * @throws IOException If fail to set the stream into the record.
627      */

628     public static void winMsiRecordSetStream(int hRecord,
629                                              int iField,
630                                              String JavaDoc filePathStr)
631                                              throws IOException JavaDoc {
632         if (msiRecordSetStream(hRecord, iField, stringToByteArray(filePathStr))
633                         != ERROR_SUCCESS) {
634             throw new IOException JavaDoc("MSI Record Set Stream Failed!");
635         }
636     }
637
638     /**
639      * Reads bytes from a record stream field into a buffer.
640      * @param hRecord Handle to the record.
641      * @param iField Specifies the field of the record.
642      * @return The read stream bytes.
643      */

644     public static byte[] winMsiRecordReadStream(int hRecord, int iField) {
645         return msiRecordReadStream(hRecord, iField);
646     }
647
648     /**
649      * Opens Summary Information stream.
650      * @param hDatabase Handle of the msi database.
651      * @return Handle to the opened summary information, errorcode.
652      */

653     public static int[] winMsiGetSummaryInformation(int hDatabase) {
654         return msiGetSummaryInformation(hDatabase);
655     }
656
657     /**
658      * Sets the property field of the msi summary information stream.
659      * @param hSummaryInfo Handle of the msi summary information stream.
660      * @param uiProperty Specify the property field.
661      * @param strValue New value to be set.
662      * @throws IOException If fail to set the property.
663      */

664     public static void winMsiSummaryInfoSetProperty(int hSummaryInfo,
665                                                     int uiProperty,
666                                                     String JavaDoc strValue)
667                                                     throws IOException JavaDoc {
668         if (msiSummaryInfoSetProperty(hSummaryInfo,
669                                       uiProperty,
670                                       stringToByteArray(strValue))
671                                       != ERROR_SUCCESS) {
672             throw new IOException JavaDoc("MSI SummaryInfo Set Property Failed!");
673         }
674     }
675
676     /**
677      * Flush the msi summary information stream.
678      * @param hSummaryInfo Handle to the msi summary information stream.
679      * @throws IOException If fail to do the flush.
680      */

681     public static void winMsiSummaryInfoPersist(int hSummaryInfo)
682                 throws IOException JavaDoc {
683         if (msiSummaryInfoPersist(hSummaryInfo) != ERROR_SUCCESS) {
684             throw new IOException JavaDoc("MSI Summaryinfo Persist Failed!");
685         }
686     }
687
688     /**
689      * Closes all open installation handles allocated by the current thread.
690      * @return 0 if all handles are closed. Otherwise, the function returns
691      * the number of handles open prior to its call.
692      */

693     public static int winMsiCloseAllHandles() {
694         return msiCloseAllHandles();
695     }
696
697     /**
698      * Generates a UUID string.
699      * @return The generated UUID string if succeed or null if failed.
700      */

701     public static String JavaDoc generateUUID() {
702         byte[] newUUID = genUUID();
703         if (newUUID != null) {
704             return byteArrayToString(newUUID);
705         } else {
706             return null;
707         }
708     }
709
710     /**
711      * Generate the transform MST file.
712      * @param hDatabase Handle of the database.
713      * @param hDatabaseReference Handle of the referenced database.
714      * @param transformFile Path of the transform file.
715      * @throws IOException If failed to generate the transform.
716      */

717     public static void winMsiDatabaseGenerateTransform(int hDatabase,
718                                                        int hDatabaseReference,
719                                                        String JavaDoc transformFile)
720                                                        throws IOException JavaDoc {
721         int result = msiDatabaseGenerateTransform(
722                         hDatabase,
723                         hDatabaseReference,
724                         stringToByteArray(transformFile));
725         if (result != ERROR_SUCCESS) {
726             throw new IOException JavaDoc("MSI Database Generate Transform Failed!");
727         }
728     }
729
730     /**
731      * Creates summary information of an existing transform to include
732      * validation and error conditions.
733      * @param hDatabase Handle of the database.
734      * @param hDatabaseReference handle of the referenced database.
735      * @param transformFile Path of the transform file.
736      * @throws IOException If failed to generate the summary info transform.
737      */

738     public static void winMsiCreateTransformSummaryInfo(
739                             int hDatabase,
740                             int hDatabaseReference,
741                             String JavaDoc transformFile)
742                             throws IOException JavaDoc {
743         int result = msiCreateTransformSummaryInfo(
744                         hDatabase,
745                         hDatabaseReference,
746                         stringToByteArray(transformFile));
747         if (result != ERROR_SUCCESS) {
748             throw new IOException JavaDoc("MSI Database Generate Transform Failed!");
749         }
750     }
751
752     /**
753      * Windows API to import a database table from a txt file.
754      * @param hDatabase The given database handle.
755      * @param folderPath The directory path where the txt table file locates.
756      * @param txtFileName The txt representation for the corresponding table.
757      * @throws IOException If failed to import the database.
758      */

759     public static void winMsiDatabaseImport(
760                             int hDatabase,
761                             String JavaDoc folderPath,
762                             String JavaDoc txtFileName)
763                             throws IOException JavaDoc {
764         int result = msiDatabaseImport(hDatabase,
765                                        stringToByteArray(folderPath),
766                                        stringToByteArray(txtFileName));
767         if (ERROR_SUCCESS != result) {
768             throw new IOException JavaDoc("MSI Databse import failed!");
769         }
770     }
771
772     /**
773      * Windows API wrapper to add/update an executable file's resource
774      * string table.
775      * @param appFilePath The given application's file path.
776      * @param contentStr The string to be added.
777      * @param resID The given resource ID.
778      * @throws IOException If fail to update the resource string.
779      */

780     public static void winUpdateResourceString(
781                         String JavaDoc appFilePath,
782                         String JavaDoc contentStr,
783                         int resID)
784                         throws IOException JavaDoc {
785         int result = updateResourceString(stringToByteArray(appFilePath),
786                                           stringToByteArray(contentStr),
787                                           resID);
788         if (result != ERROR_SUCCESS) {
789             throw new IOException JavaDoc("Windows Update Resource String Failed!");
790         }
791     }
792
793     /**
794      * Windows API to add/update an executble file's binary resource.
795      * @param appFilePath The given application's file path.
796      * @param dataFilePath The given file containing the binary data
797      * @param resID The given resource ID
798      * @throws IOException If failed to update the binary resource field.
799      */

800     public static void winUpdateResourceData(
801                         String JavaDoc appFilePath,
802                         String JavaDoc dataFilePath,
803                         int resID)
804                         throws IOException JavaDoc {
805         int result = updateResourceData(stringToByteArray(appFilePath),
806                                         stringToByteArray(dataFilePath),
807                                         resID);
808         if (result != ERROR_SUCCESS) {
809             throw new IOException JavaDoc(
810                             "Windows Update Resource Binary Data Failed!");
811         }
812     }
813
814     /**
815      * Windows API to create a MSI database record.
816      * @param numFields Number of the fields to be included in this record.
817      * @return Handle to the created record.
818      * @throws IOException If failed to create the record.
819      */

820     public static int winMsiCreateRecord(int numFields) throws IOException JavaDoc {
821         int msiRecordHandle = msiCreateRecord(numFields);
822         if (msiRecordHandle != -1) {
823             return msiRecordHandle;
824         } else {
825             throw new IOException JavaDoc("MSI Create Record Failed!");
826         }
827     }
828 }
829
Popular Tags