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 typedef struct tagMSIPACKAGE
208 struct list components
;
209 struct list features
;
211 struct list tempfiles
;
217 struct list extensions
;
222 struct tagMSISCRIPT
*script
;
224 struct list RunningActions
;
229 UINT CurrentInstallState
;
235 struct list subscriptions
;
238 typedef struct tagMSIPREVIEW
245 #define MSI_MAX_PROPS 20
247 typedef struct tagMSISUMMARYINFO
252 PROPVARIANT property
[MSI_MAX_PROPS
];
255 #define MSIHANDLETYPE_ANY 0
256 #define MSIHANDLETYPE_DATABASE 1
257 #define MSIHANDLETYPE_SUMMARYINFO 2
258 #define MSIHANDLETYPE_VIEW 3
259 #define MSIHANDLETYPE_RECORD 4
260 #define MSIHANDLETYPE_PACKAGE 5
261 #define MSIHANDLETYPE_PREVIEW 6
263 #define MSI_MAJORVERSION 3
264 #define MSI_MINORVERSION 1
265 #define MSI_BUILDNUMBER 4000
269 #define MSIHANDLE_MAGIC 0x4d434923
270 #define MSIMAXHANDLES 0xf0
272 DEFINE_GUID(CLSID_IMsiServer
, 0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
273 DEFINE_GUID(CLSID_IMsiServerX1
, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
274 DEFINE_GUID(CLSID_IMsiServerX2
, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
275 DEFINE_GUID(CLSID_IMsiServerX3
, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
277 DEFINE_GUID(CLSID_IMsiServerMessage
, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
279 /* handle unicode/ascii output in the Msi* API functions */
296 UINT
msi_strcpy_to_awstring( LPCWSTR str
, awstring
*awbuf
, DWORD
*sz
);
298 /* handle functions */
299 extern void *msihandle2msiinfo(MSIHANDLE handle
, UINT type
);
300 extern MSIHANDLE
alloc_msihandle( MSIOBJECTHDR
* );
301 extern void *alloc_msiobject(UINT type
, UINT size
, msihandledestructor destroy
);
302 extern void msiobj_addref(MSIOBJECTHDR
*);
303 extern int msiobj_release(MSIOBJECTHDR
*);
304 extern void msiobj_lock(MSIOBJECTHDR
*);
305 extern void msiobj_unlock(MSIOBJECTHDR
*);
307 extern void free_cached_tables( MSIDATABASE
*db
);
308 extern void msi_free_transforms( MSIDATABASE
*db
);
309 extern string_table
*load_string_table( IStorage
*stg
);
310 extern UINT
MSI_CommitTables( MSIDATABASE
*db
);
311 extern HRESULT
init_string_table( IStorage
*stg
);
314 /* string table functions */
315 extern BOOL
msi_addstring( string_table
*st
, UINT string_no
, const CHAR
*data
, int len
, UINT refcount
);
316 extern BOOL
msi_addstringW( string_table
*st
, UINT string_no
, const WCHAR
*data
, int len
, UINT refcount
);
317 extern UINT
msi_id2stringW( string_table
*st
, UINT string_no
, LPWSTR buffer
, UINT
*sz
);
318 extern UINT
msi_id2stringA( string_table
*st
, UINT string_no
, LPSTR buffer
, UINT
*sz
);
320 extern LPWSTR
MSI_makestring( MSIDATABASE
*db
, UINT stringid
);
321 extern UINT
msi_string2idW( string_table
*st
, LPCWSTR buffer
, UINT
*id
);
322 extern UINT
msi_string2idA( string_table
*st
, LPCSTR str
, UINT
*id
);
323 extern string_table
*msi_init_stringtable( int entries
, UINT codepage
);
324 extern VOID
msi_destroy_stringtable( string_table
*st
);
325 extern UINT
msi_string_count( string_table
*st
);
326 extern UINT
msi_id_refcount( string_table
*st
, UINT i
);
327 extern UINT
msi_string_totalsize( string_table
*st
, UINT
*last
);
328 extern UINT
msi_strcmp( string_table
*st
, UINT lval
, UINT rval
, UINT
*res
);
329 extern const WCHAR
*msi_string_lookup_id( string_table
*st
, UINT id
);
330 extern UINT
msi_string_get_codepage( string_table
*st
);
333 extern UINT
VIEW_find_column( MSIVIEW
*view
, LPCWSTR name
, UINT
*n
);
335 extern BOOL
TABLE_Exists( MSIDATABASE
*db
, LPWSTR name
);
337 extern UINT
read_raw_stream_data( MSIDATABASE
*, LPCWSTR stname
,
338 USHORT
**pdata
, UINT
*psz
);
340 /* transform functions */
341 extern UINT
msi_table_apply_transform( MSIDATABASE
*db
, IStorage
*stg
);
342 extern UINT
MSI_DatabaseApplyTransformW( MSIDATABASE
*db
,
343 LPCWSTR szTransformFile
, int iErrorCond
);
345 /* action internals */
346 extern UINT
MSI_InstallPackage( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
347 extern void ACTION_free_package_structures( MSIPACKAGE
* );
348 extern UINT
ACTION_DialogBox( MSIPACKAGE
*, LPCWSTR
);
349 extern UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
);
350 extern UINT
MSI_SetFeatureStates( MSIPACKAGE
*package
);
352 /* record internals */
353 extern UINT
MSI_RecordSetIStream( MSIRECORD
*, unsigned int, IStream
*);
354 extern UINT
MSI_RecordGetIStream( MSIRECORD
*, unsigned int, IStream
**);
355 extern const WCHAR
*MSI_RecordGetString( MSIRECORD
*, unsigned int );
356 extern MSIRECORD
*MSI_CreateRecord( unsigned int );
357 extern UINT
MSI_RecordSetInteger( MSIRECORD
*, unsigned int, int );
358 extern UINT
MSI_RecordSetStringW( MSIRECORD
*, unsigned int, LPCWSTR
);
359 extern UINT
MSI_RecordSetStringA( MSIRECORD
*, unsigned int, LPCSTR
);
360 extern BOOL
MSI_RecordIsNull( MSIRECORD
*, unsigned int );
361 extern UINT
MSI_RecordGetStringW( MSIRECORD
* , unsigned int, LPWSTR
, DWORD
*);
362 extern UINT
MSI_RecordGetStringA( MSIRECORD
*, unsigned int, LPSTR
, DWORD
*);
363 extern int MSI_RecordGetInteger( MSIRECORD
*, unsigned int );
364 extern UINT
MSI_RecordReadStream( MSIRECORD
*, unsigned int, char *, DWORD
*);
365 extern unsigned int MSI_RecordGetFieldCount( MSIRECORD
*rec
);
366 extern UINT
MSI_RecordSetStreamW( MSIRECORD
*, unsigned int, LPCWSTR
);
367 extern UINT
MSI_RecordSetStreamA( MSIRECORD
*, unsigned int, LPCSTR
);
368 extern UINT
MSI_RecordDataSize( MSIRECORD
*, unsigned int );
369 extern UINT
MSI_RecordStreamToFile( MSIRECORD
*, unsigned int, LPCWSTR
);
371 /* stream internals */
372 extern UINT
get_raw_stream( MSIHANDLE hdb
, LPCWSTR stname
, IStream
**stm
);
373 extern UINT
db_get_raw_stream( MSIDATABASE
*db
, LPCWSTR stname
, IStream
**stm
);
374 extern void enum_stream_names( IStorage
*stg
);
376 /* database internals */
377 extern UINT
MSI_OpenDatabaseW( LPCWSTR
, LPCWSTR
, MSIDATABASE
** );
378 extern UINT
MSI_DatabaseOpenViewW(MSIDATABASE
*, LPCWSTR
, MSIQUERY
** );
379 extern UINT
MSI_OpenQuery( MSIDATABASE
*, MSIQUERY
**, LPCWSTR
, ... );
380 typedef UINT (*record_func
)( MSIRECORD
*, LPVOID
);
381 extern UINT
MSI_IterateRecords( MSIQUERY
*, DWORD
*, record_func
, LPVOID
);
382 extern MSIRECORD
*MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR query
, ... );
383 extern UINT
MSI_DatabaseImport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
);
384 extern UINT
MSI_DatabaseExport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
, LPCWSTR
);
385 extern UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*, LPCWSTR
, MSIRECORD
** );
388 extern UINT
MSI_ViewExecute( MSIQUERY
*, MSIRECORD
* );
389 extern UINT
MSI_ViewFetch( MSIQUERY
*, MSIRECORD
** );
390 extern UINT
MSI_ViewClose( MSIQUERY
* );
392 /* install internals */
393 extern UINT
MSI_SetInstallLevel( MSIPACKAGE
*package
, int iInstallLevel
);
395 /* package internals */
396 extern MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
* );
397 extern UINT
MSI_OpenPackageW( LPCWSTR szPackage
, MSIPACKAGE
** );
398 extern UINT
MSI_SetTargetPathW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
399 extern UINT
MSI_SetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
400 extern INT
MSI_ProcessMessage( MSIPACKAGE
*, INSTALLMESSAGE
, MSIRECORD
* );
401 extern UINT
MSI_GetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPWSTR
, DWORD
* );
402 extern UINT
MSI_GetPropertyA(MSIPACKAGE
*, LPCSTR
, LPSTR
, DWORD
* );
403 extern MSICONDITION
MSI_EvaluateConditionW( MSIPACKAGE
*, LPCWSTR
);
404 extern UINT
MSI_GetComponentStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
405 extern UINT
MSI_GetFeatureStateW( MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
406 extern UINT WINAPI
MSI_SetFeatureStateW(MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
);
408 /* for deformating */
409 extern UINT
MSI_FormatRecordW( MSIPACKAGE
*, MSIRECORD
*, LPWSTR
, DWORD
* );
410 extern UINT
MSI_FormatRecordA( MSIPACKAGE
*, MSIRECORD
*, LPSTR
, DWORD
* );
412 /* registry data encoding/decoding functions */
413 extern BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
);
414 extern BOOL
squash_guid(LPCWSTR in
, LPWSTR out
);
415 extern BOOL
encode_base85_guid(GUID
*,LPWSTR
);
416 extern BOOL
decode_base85_guid(LPCWSTR
,GUID
*);
417 extern UINT
MSIREG_OpenUninstallKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
418 extern UINT
MSIREG_OpenUserProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
419 extern UINT
MSIREG_OpenFeatures(HKEY
* key
);
420 extern UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
421 extern UINT
MSIREG_OpenComponents(HKEY
* key
);
422 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
423 extern UINT
MSIREG_OpenComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
424 extern UINT
MSIREG_OpenProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
425 extern UINT
MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
426 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
427 extern UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
428 extern UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
430 extern LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
);
431 extern BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
);
433 extern DWORD
msi_version_str_to_dword(LPCWSTR p
);
434 extern LPWSTR
msi_version_dword_to_str(DWORD version
);
436 extern LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
437 extern LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
438 extern LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
);
439 extern LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
);
441 /* msi dialog interface */
442 typedef UINT (*msi_dialog_event_handler
)( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
, msi_dialog
* );
443 extern msi_dialog
*msi_dialog_create( MSIPACKAGE
*, LPCWSTR
, msi_dialog_event_handler
);
444 extern UINT
msi_dialog_run_message_loop( msi_dialog
* );
445 extern void msi_dialog_end_dialog( msi_dialog
* );
446 extern void msi_dialog_check_messages( HANDLE
);
447 extern void msi_dialog_do_preview( msi_dialog
* );
448 extern void msi_dialog_destroy( msi_dialog
* );
449 extern BOOL
msi_dialog_register_class( void );
450 extern void msi_dialog_unregister_class( void );
451 extern void msi_dialog_handle_event( msi_dialog
*, LPCWSTR
, LPCWSTR
, MSIRECORD
* );
452 extern UINT
msi_dialog_reset( msi_dialog
*dialog
);
455 extern MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
* );
456 extern UINT
MSI_PreviewDialogW( MSIPREVIEW
*, LPCWSTR
);
458 /* summary information */
459 extern MSISUMMARYINFO
*MSI_GetSummaryInformationW( MSIDATABASE
*db
, UINT uiUpdateCount
);
460 extern LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
);
462 /* undocumented functions */
463 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory( DWORD
);
464 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
* );
465 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR
, LPSTR
, LPSTR
, LPSTR
, DWORD
* );
466 LANGID WINAPI
MsiLoadStringW( MSIHANDLE
, UINT
, LPWSTR
, int, LANGID
);
467 LANGID WINAPI
MsiLoadStringA( MSIHANDLE
, UINT
, LPSTR
, int, LANGID
);
470 extern INSTALLUILEVEL gUILevel
;
472 extern INSTALLUI_HANDLERA gUIHandlerA
;
473 extern INSTALLUI_HANDLERW gUIHandlerW
;
474 extern DWORD gUIFilter
;
475 extern LPVOID gUIContext
;
476 extern WCHAR gszLogFile
[MAX_PATH
];
477 extern HINSTANCE msi_hInstance
;
479 /* memory allocation macro functions */
480 static inline void *msi_alloc( size_t len
)
482 return HeapAlloc( GetProcessHeap(), 0, len
);
485 static inline void *msi_alloc_zero( size_t len
)
487 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
490 static inline void *msi_realloc( void *mem
, size_t len
)
492 return HeapReAlloc( GetProcessHeap(), 0, mem
, len
);
495 static inline void *msi_realloc_zero( void *mem
, size_t len
)
497 return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
500 static inline BOOL
msi_free( void *mem
)
502 return HeapFree( GetProcessHeap(), 0, mem
);
505 inline static char *strdupWtoA( LPCWSTR str
)
510 if (!str
) return ret
;
511 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
512 ret
= msi_alloc( len
);
514 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
518 inline static LPWSTR
strdupAtoW( LPCSTR str
)
523 if (!str
) return ret
;
524 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
525 ret
= msi_alloc( len
* sizeof(WCHAR
) );
527 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
531 inline static LPWSTR
strdupW( LPCWSTR src
)
534 if (!src
) return NULL
;
535 dest
= msi_alloc( (lstrlenW(src
)+1)*sizeof(WCHAR
) );
541 #endif /* __WINE_MSI_PRIVATE__ */