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
;
237 struct list props
[PROPERTY_HASH_SIZE
];
239 struct list subscriptions
;
242 typedef struct tagMSIPREVIEW
249 #define MSI_MAX_PROPS 20
251 typedef struct tagMSISUMMARYINFO
256 PROPVARIANT property
[MSI_MAX_PROPS
];
259 #define MSIHANDLETYPE_ANY 0
260 #define MSIHANDLETYPE_DATABASE 1
261 #define MSIHANDLETYPE_SUMMARYINFO 2
262 #define MSIHANDLETYPE_VIEW 3
263 #define MSIHANDLETYPE_RECORD 4
264 #define MSIHANDLETYPE_PACKAGE 5
265 #define MSIHANDLETYPE_PREVIEW 6
267 #define MSI_MAJORVERSION 3
268 #define MSI_MINORVERSION 1
269 #define MSI_BUILDNUMBER 4000
273 #define MSIHANDLE_MAGIC 0x4d434923
275 DEFINE_GUID(CLSID_IMsiServer
, 0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
276 DEFINE_GUID(CLSID_IMsiServerX1
, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
277 DEFINE_GUID(CLSID_IMsiServerX2
, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
278 DEFINE_GUID(CLSID_IMsiServerX3
, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
280 DEFINE_GUID(CLSID_IMsiServerMessage
, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
282 /* handle unicode/ascii output in the Msi* API functions */
299 UINT
msi_strcpy_to_awstring( LPCWSTR str
, awstring
*awbuf
, DWORD
*sz
);
301 /* handle functions */
302 extern void *msihandle2msiinfo(MSIHANDLE handle
, UINT type
);
303 extern MSIHANDLE
alloc_msihandle( MSIOBJECTHDR
* );
304 extern void *alloc_msiobject(UINT type
, UINT size
, msihandledestructor destroy
);
305 extern void msiobj_addref(MSIOBJECTHDR
*);
306 extern int msiobj_release(MSIOBJECTHDR
*);
307 extern void msiobj_lock(MSIOBJECTHDR
*);
308 extern void msiobj_unlock(MSIOBJECTHDR
*);
309 extern void msi_free_handle_table(void);
311 extern void free_cached_tables( MSIDATABASE
*db
);
312 extern void msi_free_transforms( MSIDATABASE
*db
);
313 extern string_table
*load_string_table( IStorage
*stg
);
314 extern UINT
MSI_CommitTables( MSIDATABASE
*db
);
315 extern HRESULT
init_string_table( IStorage
*stg
);
318 /* string table functions */
319 extern BOOL
msi_addstring( string_table
*st
, UINT string_no
, const CHAR
*data
, int len
, UINT refcount
);
320 extern BOOL
msi_addstringW( string_table
*st
, UINT string_no
, const WCHAR
*data
, int len
, UINT refcount
);
321 extern UINT
msi_id2stringW( string_table
*st
, UINT string_no
, LPWSTR buffer
, UINT
*sz
);
322 extern UINT
msi_id2stringA( string_table
*st
, UINT string_no
, LPSTR buffer
, UINT
*sz
);
324 extern LPWSTR
MSI_makestring( MSIDATABASE
*db
, UINT stringid
);
325 extern UINT
msi_string2idW( string_table
*st
, LPCWSTR buffer
, UINT
*id
);
326 extern UINT
msi_string2idA( string_table
*st
, LPCSTR str
, UINT
*id
);
327 extern string_table
*msi_init_stringtable( int entries
, UINT codepage
);
328 extern VOID
msi_destroy_stringtable( string_table
*st
);
329 extern UINT
msi_string_count( string_table
*st
);
330 extern UINT
msi_id_refcount( string_table
*st
, UINT i
);
331 extern UINT
msi_string_totalsize( string_table
*st
, UINT
*datasize
, UINT
*poolsize
);
332 extern UINT
msi_strcmp( string_table
*st
, UINT lval
, UINT rval
, UINT
*res
);
333 extern const WCHAR
*msi_string_lookup_id( string_table
*st
, UINT id
);
334 extern UINT
msi_string_get_codepage( string_table
*st
);
337 extern UINT
VIEW_find_column( MSIVIEW
*view
, LPCWSTR name
, UINT
*n
);
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
);
375 /* stream internals */
376 extern UINT
get_raw_stream( MSIHANDLE hdb
, LPCWSTR stname
, IStream
**stm
);
377 extern UINT
db_get_raw_stream( MSIDATABASE
*db
, LPCWSTR stname
, IStream
**stm
);
378 extern void enum_stream_names( IStorage
*stg
);
380 /* database internals */
381 extern UINT
MSI_OpenDatabaseW( LPCWSTR
, LPCWSTR
, MSIDATABASE
** );
382 extern UINT
MSI_DatabaseOpenViewW(MSIDATABASE
*, LPCWSTR
, MSIQUERY
** );
383 extern UINT
MSI_OpenQuery( MSIDATABASE
*, MSIQUERY
**, LPCWSTR
, ... );
384 typedef UINT (*record_func
)( MSIRECORD
*, LPVOID
);
385 extern UINT
MSI_IterateRecords( MSIQUERY
*, DWORD
*, record_func
, LPVOID
);
386 extern MSIRECORD
*MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR query
, ... );
387 extern UINT
MSI_DatabaseImport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
);
388 extern UINT
MSI_DatabaseExport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
, LPCWSTR
);
389 extern UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*, LPCWSTR
, MSIRECORD
** );
392 extern UINT
MSI_ViewExecute( MSIQUERY
*, MSIRECORD
* );
393 extern UINT
MSI_ViewFetch( MSIQUERY
*, MSIRECORD
** );
394 extern UINT
MSI_ViewClose( MSIQUERY
* );
396 /* install internals */
397 extern UINT
MSI_SetInstallLevel( MSIPACKAGE
*package
, int iInstallLevel
);
399 /* package internals */
400 extern MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
* );
401 extern UINT
MSI_OpenPackageW( LPCWSTR szPackage
, MSIPACKAGE
** );
402 extern UINT
MSI_SetTargetPathW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
403 extern UINT
MSI_SetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
404 extern INT
MSI_ProcessMessage( MSIPACKAGE
*, INSTALLMESSAGE
, MSIRECORD
* );
405 extern UINT
MSI_GetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPWSTR
, DWORD
* );
406 extern UINT
MSI_GetPropertyA(MSIPACKAGE
*, LPCSTR
, LPSTR
, DWORD
* );
407 extern MSICONDITION
MSI_EvaluateConditionW( MSIPACKAGE
*, LPCWSTR
);
408 extern UINT
MSI_GetComponentStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
409 extern UINT
MSI_GetFeatureStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
410 extern UINT WINAPI
MSI_SetFeatureStateW(MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
);
412 /* for deformating */
413 extern UINT
MSI_FormatRecordW( MSIPACKAGE
*, MSIRECORD
*, LPWSTR
, DWORD
* );
414 extern UINT
MSI_FormatRecordA( MSIPACKAGE
*, MSIRECORD
*, LPSTR
, DWORD
* );
416 /* registry data encoding/decoding functions */
417 extern BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
);
418 extern BOOL
squash_guid(LPCWSTR in
, LPWSTR out
);
419 extern BOOL
encode_base85_guid(GUID
*,LPWSTR
);
420 extern BOOL
decode_base85_guid(LPCWSTR
,GUID
*);
421 extern UINT
MSIREG_OpenUninstallKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
422 extern UINT
MSIREG_OpenUserProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
423 extern UINT
MSIREG_OpenFeatures(HKEY
* key
);
424 extern UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
425 extern UINT
MSIREG_OpenComponents(HKEY
* key
);
426 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
427 extern UINT
MSIREG_OpenComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
428 extern UINT
MSIREG_OpenProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
429 extern UINT
MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
430 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
431 extern UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
432 extern UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
434 extern LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
);
435 extern BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
);
437 extern DWORD
msi_version_str_to_dword(LPCWSTR p
);
438 extern LPWSTR
msi_version_dword_to_str(DWORD version
);
440 extern LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
441 extern LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
442 extern LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
);
443 extern LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
);
445 /* msi dialog interface */
446 typedef UINT (*msi_dialog_event_handler
)( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
, msi_dialog
* );
447 extern msi_dialog
*msi_dialog_create( MSIPACKAGE
*, LPCWSTR
, msi_dialog_event_handler
);
448 extern UINT
msi_dialog_run_message_loop( msi_dialog
* );
449 extern void msi_dialog_end_dialog( msi_dialog
* );
450 extern void msi_dialog_check_messages( HANDLE
);
451 extern void msi_dialog_do_preview( msi_dialog
* );
452 extern void msi_dialog_destroy( msi_dialog
* );
453 extern BOOL
msi_dialog_register_class( void );
454 extern void msi_dialog_unregister_class( void );
455 extern void msi_dialog_handle_event( msi_dialog
*, LPCWSTR
, LPCWSTR
, MSIRECORD
* );
456 extern UINT
msi_dialog_reset( msi_dialog
*dialog
);
457 extern UINT
msi_dialog_directorylist_up( msi_dialog
*dialog
);
460 extern MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
* );
461 extern UINT
MSI_PreviewDialogW( MSIPREVIEW
*, LPCWSTR
);
463 /* summary information */
464 extern MSISUMMARYINFO
*MSI_GetSummaryInformationW( MSIDATABASE
*db
, UINT uiUpdateCount
);
465 extern LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
);
467 /* undocumented functions */
468 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory( DWORD
);
469 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
* );
470 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR
, LPSTR
, LPSTR
, LPSTR
, DWORD
* );
471 LANGID WINAPI
MsiLoadStringW( MSIHANDLE
, UINT
, LPWSTR
, int, LANGID
);
472 LANGID WINAPI
MsiLoadStringA( MSIHANDLE
, UINT
, LPSTR
, int, LANGID
);
475 extern INSTALLUILEVEL gUILevel
;
477 extern INSTALLUI_HANDLERA gUIHandlerA
;
478 extern INSTALLUI_HANDLERW gUIHandlerW
;
479 extern DWORD gUIFilter
;
480 extern LPVOID gUIContext
;
481 extern WCHAR gszLogFile
[MAX_PATH
];
482 extern HINSTANCE msi_hInstance
;
484 /* memory allocation macro functions */
485 static inline void *msi_alloc( size_t len
)
487 return HeapAlloc( GetProcessHeap(), 0, len
);
490 static inline void *msi_alloc_zero( size_t len
)
492 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
495 static inline void *msi_realloc( void *mem
, size_t len
)
497 return HeapReAlloc( GetProcessHeap(), 0, mem
, len
);
500 static inline void *msi_realloc_zero( void *mem
, size_t len
)
502 return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
505 static inline BOOL
msi_free( void *mem
)
507 return HeapFree( GetProcessHeap(), 0, mem
);
510 inline static char *strdupWtoA( LPCWSTR str
)
515 if (!str
) return ret
;
516 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
517 ret
= msi_alloc( len
);
519 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
523 inline static LPWSTR
strdupAtoW( LPCSTR str
)
528 if (!str
) return ret
;
529 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
530 ret
= msi_alloc( len
* sizeof(WCHAR
) );
532 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
536 inline static LPWSTR
strdupW( LPCWSTR src
)
539 if (!src
) return NULL
;
540 dest
= msi_alloc( (lstrlenW(src
)+1)*sizeof(WCHAR
) );
546 #endif /* __WINE_MSI_PRIVATE__ */