2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_MSI_PRIVATE__
22 #define __WINE_MSI_PRIVATE__
33 #include "wine/list.h"
35 #define MSI_DATASIZEMASK 0x00ff
36 #define MSITYPE_VALID 0x0100
37 #define MSITYPE_LOCALIZABLE 0x200
38 #define MSITYPE_STRING 0x0800
39 #define MSITYPE_NULLABLE 0x1000
40 #define MSITYPE_KEY 0x2000
42 /* Word Count masks */
43 #define MSIWORDCOUNT_SHORTFILENAMES 0x0001
44 #define MSIWORDCOUNT_COMPRESSED 0x0002
45 #define MSIWORDCOUNT_ADMINISTRATIVE 0x0004
46 #define MSIWORDCOUNT_PRIVILEGES 0x0008
48 #define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
51 typedef struct tagMSITABLE MSITABLE
;
54 typedef struct string_table string_table
;
56 struct tagMSIOBJECTHDR
;
57 typedef struct tagMSIOBJECTHDR MSIOBJECTHDR
;
59 typedef VOID (*msihandledestructor
)( MSIOBJECTHDR
* );
61 struct tagMSIOBJECTHDR
66 msihandledestructor destructor
;
69 typedef struct tagMSIDATABASE
73 string_table
*strings
;
76 struct list transforms
;
79 typedef struct tagMSIVIEW MSIVIEW
;
81 typedef struct tagMSIQUERY
90 /* maybe we can use a Variant instead of doing it ourselves? */
91 typedef struct tagMSIFIELD
102 typedef struct tagMSIRECORD
105 UINT count
; /* as passed to MsiCreateRecord */
106 MSIFIELD fields
[1]; /* nb. array size is count+1 */
109 typedef void *MSIITERHANDLE
;
111 typedef struct tagMSIVIEWOPS
114 * fetch_int - reads one integer from {row,col} in the table
116 * This function should be called after the execute method.
117 * Data returned by the function should not change until
118 * close or delete is called.
119 * To get a string value, query the database's string table with
120 * the integer value returned from this function.
122 UINT (*fetch_int
)( struct tagMSIVIEW
*, UINT row
, UINT col
, UINT
*val
);
125 * fetch_stream - gets a stream from {row,col} in the table
127 * This function is similar to fetch_int, except fetches a
128 * stream instead of an integer.
130 UINT (*fetch_stream
)( struct tagMSIVIEW
*, UINT row
, UINT col
, IStream
**stm
);
133 * get_int - sets one integer at {row,col} in the table
135 * Similar semantics to fetch_int
137 UINT (*set_int
)( struct tagMSIVIEW
*, UINT row
, UINT col
, UINT val
);
140 * Inserts a new row into the database from the records contents
142 UINT (*insert_row
)( struct tagMSIVIEW
*, MSIRECORD
* );
145 * execute - loads the underlying data into memory so it can be read
147 UINT (*execute
)( struct tagMSIVIEW
*, MSIRECORD
* );
150 * close - clears the data read by execute from memory
152 UINT (*close
)( struct tagMSIVIEW
* );
155 * get_dimensions - returns the number of rows or columns in a table.
157 * The number of rows can only be queried after the execute method
158 * is called. The number of columns can be queried at any time.
160 UINT (*get_dimensions
)( struct tagMSIVIEW
*, UINT
*rows
, UINT
*cols
);
163 * get_column_info - returns the name and type of a specific column
165 * The name is HeapAlloc'ed by this function and should be freed by
167 * The column information can be queried at any time.
169 UINT (*get_column_info
)( struct tagMSIVIEW
*, UINT n
, LPWSTR
*name
, UINT
*type
);
172 * modify - not yet implemented properly
174 UINT (*modify
)( struct tagMSIVIEW
*, MSIMODIFY
, MSIRECORD
* );
177 * delete - destroys the structure completely
179 UINT (*delete)( struct tagMSIVIEW
* );
182 * find_matching_rows - iterates through rows that match a value
184 * If the column type is a string then a string ID should be passed in.
185 * If the value to be looked up is an integer then no transformation of
186 * the input value is required, except if the column is a string, in which
187 * case a string ID should be passed in.
188 * The handle is an input/output parameter that keeps track of the current
189 * position in the iteration. It must be initialised to zero before the
190 * first call and continued to be passed in to subsequent calls.
192 UINT (*find_matching_rows
)( struct tagMSIVIEW
*, UINT col
, UINT val
, UINT
*row
, MSIITERHANDLE
*handle
);
198 const MSIVIEWOPS
*ops
;
201 struct msi_dialog_tag
;
202 typedef struct msi_dialog_tag msi_dialog
;
204 #define PROPERTY_HASH_SIZE 67
206 typedef struct tagMSIPACKAGE
210 struct list components
;
211 struct list features
;
213 struct list tempfiles
;
219 struct list extensions
;
224 struct tagMSISCRIPT
*script
;
226 struct list RunningActions
;
231 UINT CurrentInstallState
;
239 struct list props
[PROPERTY_HASH_SIZE
];
241 struct list subscriptions
;
244 typedef struct tagMSIPREVIEW
251 #define MSI_MAX_PROPS 20
253 typedef struct tagMSISUMMARYINFO
258 PROPVARIANT property
[MSI_MAX_PROPS
];
261 #define MSIHANDLETYPE_ANY 0
262 #define MSIHANDLETYPE_DATABASE 1
263 #define MSIHANDLETYPE_SUMMARYINFO 2
264 #define MSIHANDLETYPE_VIEW 3
265 #define MSIHANDLETYPE_RECORD 4
266 #define MSIHANDLETYPE_PACKAGE 5
267 #define MSIHANDLETYPE_PREVIEW 6
269 #define MSI_MAJORVERSION 3
270 #define MSI_MINORVERSION 1
271 #define MSI_BUILDNUMBER 4000
275 #define MSIHANDLE_MAGIC 0x4d434923
277 DEFINE_GUID(CLSID_IMsiServer
, 0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
278 DEFINE_GUID(CLSID_IMsiServerX1
, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
279 DEFINE_GUID(CLSID_IMsiServerX2
, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
280 DEFINE_GUID(CLSID_IMsiServerX3
, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
282 DEFINE_GUID(CLSID_IMsiServerMessage
, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
284 /* handle unicode/ascii output in the Msi* API functions */
301 UINT
msi_strcpy_to_awstring( LPCWSTR str
, awstring
*awbuf
, DWORD
*sz
);
303 /* handle functions */
304 extern void *msihandle2msiinfo(MSIHANDLE handle
, UINT type
);
305 extern MSIHANDLE
alloc_msihandle( MSIOBJECTHDR
* );
306 extern void *alloc_msiobject(UINT type
, UINT size
, msihandledestructor destroy
);
307 extern void msiobj_addref(MSIOBJECTHDR
*);
308 extern int msiobj_release(MSIOBJECTHDR
*);
309 extern void msiobj_lock(MSIOBJECTHDR
*);
310 extern void msiobj_unlock(MSIOBJECTHDR
*);
311 extern void msi_free_handle_table(void);
313 extern void free_cached_tables( MSIDATABASE
*db
);
314 extern void msi_free_transforms( MSIDATABASE
*db
);
315 extern string_table
*load_string_table( IStorage
*stg
);
316 extern UINT
MSI_CommitTables( MSIDATABASE
*db
);
317 extern HRESULT
init_string_table( IStorage
*stg
);
320 /* string table functions */
321 extern BOOL
msi_addstring( string_table
*st
, UINT string_no
, const CHAR
*data
, int len
, UINT refcount
);
322 extern BOOL
msi_addstringW( string_table
*st
, UINT string_no
, const WCHAR
*data
, int len
, UINT refcount
);
323 extern UINT
msi_id2stringW( string_table
*st
, UINT string_no
, LPWSTR buffer
, UINT
*sz
);
324 extern UINT
msi_id2stringA( string_table
*st
, UINT string_no
, LPSTR buffer
, UINT
*sz
);
326 extern LPWSTR
MSI_makestring( MSIDATABASE
*db
, UINT stringid
);
327 extern UINT
msi_string2idW( string_table
*st
, LPCWSTR buffer
, UINT
*id
);
328 extern UINT
msi_string2idA( string_table
*st
, LPCSTR str
, UINT
*id
);
329 extern string_table
*msi_init_stringtable( int entries
, UINT codepage
);
330 extern VOID
msi_destroy_stringtable( string_table
*st
);
331 extern UINT
msi_string_count( string_table
*st
);
332 extern UINT
msi_id_refcount( string_table
*st
, UINT i
);
333 extern UINT
msi_string_totalsize( string_table
*st
, UINT
*datasize
, UINT
*poolsize
);
334 extern UINT
msi_strcmp( string_table
*st
, UINT lval
, UINT rval
, UINT
*res
);
335 extern const WCHAR
*msi_string_lookup_id( string_table
*st
, UINT id
);
336 extern UINT
msi_string_get_codepage( string_table
*st
);
339 extern BOOL
TABLE_Exists( MSIDATABASE
*db
, LPWSTR name
);
341 extern UINT
read_raw_stream_data( MSIDATABASE
*, LPCWSTR stname
,
342 USHORT
**pdata
, UINT
*psz
);
344 /* transform functions */
345 extern UINT
msi_table_apply_transform( MSIDATABASE
*db
, IStorage
*stg
);
346 extern UINT
MSI_DatabaseApplyTransformW( MSIDATABASE
*db
,
347 LPCWSTR szTransformFile
, int iErrorCond
);
349 /* action internals */
350 extern UINT
MSI_InstallPackage( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
351 extern void ACTION_free_package_structures( MSIPACKAGE
* );
352 extern UINT
ACTION_DialogBox( MSIPACKAGE
*, LPCWSTR
);
353 extern UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
);
354 extern UINT
MSI_SetFeatureStates( MSIPACKAGE
*package
);
356 /* record internals */
357 extern UINT
MSI_RecordSetIStream( MSIRECORD
*, unsigned int, IStream
*);
358 extern UINT
MSI_RecordGetIStream( MSIRECORD
*, unsigned int, IStream
**);
359 extern const WCHAR
*MSI_RecordGetString( MSIRECORD
*, unsigned int );
360 extern MSIRECORD
*MSI_CreateRecord( unsigned int );
361 extern UINT
MSI_RecordSetInteger( MSIRECORD
*, unsigned int, int );
362 extern UINT
MSI_RecordSetStringW( MSIRECORD
*, unsigned int, LPCWSTR
);
363 extern UINT
MSI_RecordSetStringA( MSIRECORD
*, unsigned int, LPCSTR
);
364 extern BOOL
MSI_RecordIsNull( MSIRECORD
*, unsigned int );
365 extern UINT
MSI_RecordGetStringW( MSIRECORD
* , unsigned int, LPWSTR
, DWORD
*);
366 extern UINT
MSI_RecordGetStringA( MSIRECORD
*, unsigned int, LPSTR
, DWORD
*);
367 extern int MSI_RecordGetInteger( MSIRECORD
*, unsigned int );
368 extern UINT
MSI_RecordReadStream( MSIRECORD
*, unsigned int, char *, DWORD
*);
369 extern unsigned int MSI_RecordGetFieldCount( MSIRECORD
*rec
);
370 extern UINT
MSI_RecordSetStreamW( MSIRECORD
*, unsigned int, LPCWSTR
);
371 extern UINT
MSI_RecordSetStreamA( MSIRECORD
*, unsigned int, LPCSTR
);
372 extern UINT
MSI_RecordDataSize( MSIRECORD
*, unsigned int );
373 extern UINT
MSI_RecordStreamToFile( MSIRECORD
*, unsigned int, LPCWSTR
);
374 extern UINT
MSI_RecordCopyField( MSIRECORD
*, unsigned int, MSIRECORD
*, unsigned int );
376 /* stream internals */
377 extern UINT
get_raw_stream( MSIHANDLE hdb
, LPCWSTR stname
, IStream
**stm
);
378 extern UINT
db_get_raw_stream( MSIDATABASE
*db
, LPCWSTR stname
, IStream
**stm
);
379 extern void enum_stream_names( IStorage
*stg
);
381 /* database internals */
382 extern UINT
MSI_OpenDatabaseW( LPCWSTR
, LPCWSTR
, MSIDATABASE
** );
383 extern UINT
MSI_DatabaseOpenViewW(MSIDATABASE
*, LPCWSTR
, MSIQUERY
** );
384 extern UINT
MSI_OpenQuery( MSIDATABASE
*, MSIQUERY
**, LPCWSTR
, ... );
385 typedef UINT (*record_func
)( MSIRECORD
*, LPVOID
);
386 extern UINT
MSI_IterateRecords( MSIQUERY
*, DWORD
*, record_func
, LPVOID
);
387 extern MSIRECORD
*MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR query
, ... );
388 extern UINT
MSI_DatabaseImport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
);
389 extern UINT
MSI_DatabaseExport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
, LPCWSTR
);
390 extern UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*, LPCWSTR
, MSIRECORD
** );
393 extern UINT
MSI_ViewExecute( MSIQUERY
*, MSIRECORD
* );
394 extern UINT
MSI_ViewFetch( MSIQUERY
*, MSIRECORD
** );
395 extern UINT
MSI_ViewClose( MSIQUERY
* );
396 extern UINT
MSI_ViewGetColumnInfo(MSIQUERY
*, MSICOLINFO
, MSIRECORD
**);
397 extern UINT
VIEW_find_column( MSIVIEW
*, LPCWSTR
, UINT
* );
400 /* install internals */
401 extern UINT
MSI_SetInstallLevel( MSIPACKAGE
*package
, int iInstallLevel
);
403 /* package internals */
404 extern MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
* );
405 extern UINT
MSI_OpenPackageW( LPCWSTR szPackage
, MSIPACKAGE
** );
406 extern UINT
MSI_SetTargetPathW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
407 extern UINT
MSI_SetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
408 extern INT
MSI_ProcessMessage( MSIPACKAGE
*, INSTALLMESSAGE
, MSIRECORD
* );
409 extern UINT
MSI_GetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPWSTR
, DWORD
* );
410 extern UINT
MSI_GetPropertyA(MSIPACKAGE
*, LPCSTR
, LPSTR
, DWORD
* );
411 extern MSICONDITION
MSI_EvaluateConditionW( MSIPACKAGE
*, LPCWSTR
);
412 extern UINT
MSI_GetComponentStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
413 extern UINT
MSI_GetFeatureStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
414 extern UINT WINAPI
MSI_SetFeatureStateW(MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
);
416 /* for deformating */
417 extern UINT
MSI_FormatRecordW( MSIPACKAGE
*, MSIRECORD
*, LPWSTR
, DWORD
* );
418 extern UINT
MSI_FormatRecordA( MSIPACKAGE
*, MSIRECORD
*, LPSTR
, DWORD
* );
420 /* registry data encoding/decoding functions */
421 extern BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
);
422 extern BOOL
squash_guid(LPCWSTR in
, LPWSTR out
);
423 extern BOOL
encode_base85_guid(GUID
*,LPWSTR
);
424 extern BOOL
decode_base85_guid(LPCWSTR
,GUID
*);
425 extern UINT
MSIREG_OpenUninstallKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
426 extern UINT
MSIREG_OpenUserProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
427 extern UINT
MSIREG_OpenFeatures(HKEY
* key
);
428 extern UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
429 extern UINT
MSIREG_OpenComponents(HKEY
* key
);
430 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
431 extern UINT
MSIREG_OpenComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
432 extern UINT
MSIREG_OpenProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
433 extern UINT
MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
434 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
435 extern UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
436 extern UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
438 extern LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
);
439 extern BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
);
441 extern DWORD
msi_version_str_to_dword(LPCWSTR p
);
442 extern LPWSTR
msi_version_dword_to_str(DWORD version
);
444 extern LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
445 extern LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
446 extern LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
);
447 extern LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
);
449 /* msi dialog interface */
450 typedef UINT (*msi_dialog_event_handler
)( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
, msi_dialog
* );
451 extern msi_dialog
*msi_dialog_create( MSIPACKAGE
*, LPCWSTR
, msi_dialog_event_handler
);
452 extern UINT
msi_dialog_run_message_loop( msi_dialog
* );
453 extern void msi_dialog_end_dialog( msi_dialog
* );
454 extern void msi_dialog_check_messages( HANDLE
);
455 extern void msi_dialog_do_preview( msi_dialog
* );
456 extern void msi_dialog_destroy( msi_dialog
* );
457 extern BOOL
msi_dialog_register_class( void );
458 extern void msi_dialog_unregister_class( void );
459 extern void msi_dialog_handle_event( msi_dialog
*, LPCWSTR
, LPCWSTR
, MSIRECORD
* );
460 extern UINT
msi_dialog_reset( msi_dialog
*dialog
);
461 extern UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
);
464 extern MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
* );
465 extern UINT
MSI_PreviewDialogW( MSIPREVIEW
*, LPCWSTR
);
467 /* summary information */
468 extern MSISUMMARYINFO
*MSI_GetSummaryInformationW( MSIDATABASE
*db
, UINT uiUpdateCount
);
469 extern LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
);
471 /* undocumented functions */
472 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory( DWORD
);
473 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
* );
474 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR
, LPSTR
, LPSTR
, LPSTR
, DWORD
* );
475 LANGID WINAPI
MsiLoadStringW( MSIHANDLE
, UINT
, LPWSTR
, int, LANGID
);
476 LANGID WINAPI
MsiLoadStringA( MSIHANDLE
, UINT
, LPSTR
, int, LANGID
);
479 extern INSTALLUILEVEL gUILevel
;
481 extern INSTALLUI_HANDLERA gUIHandlerA
;
482 extern INSTALLUI_HANDLERW gUIHandlerW
;
483 extern DWORD gUIFilter
;
484 extern LPVOID gUIContext
;
485 extern WCHAR gszLogFile
[MAX_PATH
];
486 extern HINSTANCE msi_hInstance
;
488 /* memory allocation macro functions */
489 static inline void *msi_alloc( size_t len
)
491 return HeapAlloc( GetProcessHeap(), 0, len
);
494 static inline void *msi_alloc_zero( size_t len
)
496 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
499 static inline void *msi_realloc( void *mem
, size_t len
)
501 return HeapReAlloc( GetProcessHeap(), 0, mem
, len
);
504 static inline void *msi_realloc_zero( void *mem
, size_t len
)
506 return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
509 static inline BOOL
msi_free( void *mem
)
511 return HeapFree( GetProcessHeap(), 0, mem
);
514 inline static char *strdupWtoA( LPCWSTR str
)
519 if (!str
) return ret
;
520 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
521 ret
= msi_alloc( len
);
523 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
527 inline static LPWSTR
strdupAtoW( LPCSTR str
)
532 if (!str
) return ret
;
533 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
534 ret
= msi_alloc( len
* sizeof(WCHAR
) );
536 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
540 inline static LPWSTR
strdupW( LPCWSTR src
)
543 if (!src
) return NULL
;
544 dest
= msi_alloc( (lstrlenW(src
)+1)*sizeof(WCHAR
) );
550 #endif /* __WINE_MSI_PRIVATE__ */