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 #define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
45 typedef struct tagMSITABLE MSITABLE
;
48 typedef struct string_table string_table
;
50 struct tagMSIOBJECTHDR
;
51 typedef struct tagMSIOBJECTHDR MSIOBJECTHDR
;
53 typedef VOID (*msihandledestructor
)( MSIOBJECTHDR
* );
55 struct tagMSIOBJECTHDR
60 msihandledestructor destructor
;
63 typedef struct tagMSIDATABASE
67 string_table
*strings
;
70 struct list transforms
;
73 typedef struct tagMSIVIEW MSIVIEW
;
75 typedef struct tagMSIQUERY
84 /* maybe we can use a Variant instead of doing it ourselves? */
85 typedef struct tagMSIFIELD
96 typedef struct tagMSIRECORD
99 UINT count
; /* as passed to MsiCreateRecord */
100 MSIFIELD fields
[1]; /* nb. array size is count+1 */
103 typedef void *MSIITERHANDLE
;
105 typedef struct tagMSIVIEWOPS
108 * fetch_int - reads one integer from {row,col} in the table
110 * This function should be called after the execute method.
111 * Data returned by the function should not change until
112 * close or delete is called.
113 * To get a string value, query the database's string table with
114 * the integer value returned from this function.
116 UINT (*fetch_int
)( struct tagMSIVIEW
*, UINT row
, UINT col
, UINT
*val
);
119 * fetch_stream - gets a stream from {row,col} in the table
121 * This function is similar to fetch_int, except fetches a
122 * stream instead of an integer.
124 UINT (*fetch_stream
)( struct tagMSIVIEW
*, UINT row
, UINT col
, IStream
**stm
);
127 * get_int - sets one integer at {row,col} in the table
129 * Similar semantics to fetch_int
131 UINT (*set_int
)( struct tagMSIVIEW
*, UINT row
, UINT col
, UINT val
);
134 * Inserts a new row into the database from the records contents
136 UINT (*insert_row
)( struct tagMSIVIEW
*, MSIRECORD
* );
139 * execute - loads the underlying data into memory so it can be read
141 UINT (*execute
)( struct tagMSIVIEW
*, MSIRECORD
* );
144 * close - clears the data read by execute from memory
146 UINT (*close
)( struct tagMSIVIEW
* );
149 * get_dimensions - returns the number of rows or columns in a table.
151 * The number of rows can only be queried after the execute method
152 * is called. The number of columns can be queried at any time.
154 UINT (*get_dimensions
)( struct tagMSIVIEW
*, UINT
*rows
, UINT
*cols
);
157 * get_column_info - returns the name and type of a specific column
159 * The name is HeapAlloc'ed by this function and should be freed by
161 * The column information can be queried at any time.
163 UINT (*get_column_info
)( struct tagMSIVIEW
*, UINT n
, LPWSTR
*name
, UINT
*type
);
166 * modify - not yet implemented properly
168 UINT (*modify
)( struct tagMSIVIEW
*, MSIMODIFY
, MSIRECORD
* );
171 * delete - destroys the structure completely
173 UINT (*delete)( struct tagMSIVIEW
* );
176 * find_matching_rows - iterates through rows that match a value
178 * If the column type is a string then a string ID should be passed in.
179 * If the value to be looked up is an integer then no transformation of
180 * the input value is required, except if the column is a string, in which
181 * case a string ID should be passed in.
182 * The handle is an input/output parameter that keeps track of the current
183 * position in the iteration. It must be initialised to zero before the
184 * first call and continued to be passed in to subsequent calls.
186 UINT (*find_matching_rows
)( struct tagMSIVIEW
*, UINT col
, UINT val
, UINT
*row
, MSIITERHANDLE
*handle
);
192 const MSIVIEWOPS
*ops
;
195 struct msi_dialog_tag
;
196 typedef struct msi_dialog_tag msi_dialog
;
198 typedef struct tagMSIPACKAGE
202 struct list components
;
203 struct list features
;
205 struct list tempfiles
;
211 struct list extensions
;
216 struct tagMSISCRIPT
*script
;
218 struct list RunningActions
;
223 UINT CurrentInstallState
;
227 struct list subscriptions
;
230 typedef struct tagMSIPREVIEW
237 #define MSI_MAX_PROPS 20
239 typedef struct tagMSISUMMARYINFO
244 PROPVARIANT property
[MSI_MAX_PROPS
];
247 #define MSIHANDLETYPE_ANY 0
248 #define MSIHANDLETYPE_DATABASE 1
249 #define MSIHANDLETYPE_SUMMARYINFO 2
250 #define MSIHANDLETYPE_VIEW 3
251 #define MSIHANDLETYPE_RECORD 4
252 #define MSIHANDLETYPE_PACKAGE 5
253 #define MSIHANDLETYPE_PREVIEW 6
255 #define MSI_MAJORVERSION 2
256 #define MSI_MINORVERSION 0
257 #define MSI_BUILDNUMBER 2600
261 #define MSIHANDLE_MAGIC 0x4d434923
262 #define MSIMAXHANDLES 0xf0
264 DEFINE_GUID(CLSID_IMsiServer
, 0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
265 DEFINE_GUID(CLSID_IMsiServerX1
, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
266 DEFINE_GUID(CLSID_IMsiServerX2
, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
267 DEFINE_GUID(CLSID_IMsiServerX3
, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
269 DEFINE_GUID(CLSID_IMsiServerMessage
, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
271 /* handle unicode/ascii output in the Msi* API functions */
288 UINT
msi_strcpy_to_awstring( LPCWSTR str
, awstring
*awbuf
, DWORD
*sz
);
290 /* handle functions */
291 extern void *msihandle2msiinfo(MSIHANDLE handle
, UINT type
);
292 extern MSIHANDLE
alloc_msihandle( MSIOBJECTHDR
* );
293 extern void *alloc_msiobject(UINT type
, UINT size
, msihandledestructor destroy
);
294 extern void msiobj_addref(MSIOBJECTHDR
*);
295 extern int msiobj_release(MSIOBJECTHDR
*);
296 extern void msiobj_lock(MSIOBJECTHDR
*);
297 extern void msiobj_unlock(MSIOBJECTHDR
*);
299 extern void free_cached_tables( MSIDATABASE
*db
);
300 extern void msi_free_transforms( MSIDATABASE
*db
);
301 extern string_table
*load_string_table( IStorage
*stg
);
302 extern UINT
MSI_CommitTables( MSIDATABASE
*db
);
303 extern HRESULT
init_string_table( IStorage
*stg
);
306 /* string table functions */
307 extern BOOL
msi_addstring( string_table
*st
, UINT string_no
, const CHAR
*data
, int len
, UINT refcount
);
308 extern BOOL
msi_addstringW( string_table
*st
, UINT string_no
, const WCHAR
*data
, int len
, UINT refcount
);
309 extern UINT
msi_id2stringW( string_table
*st
, UINT string_no
, LPWSTR buffer
, UINT
*sz
);
310 extern UINT
msi_id2stringA( string_table
*st
, UINT string_no
, LPSTR buffer
, UINT
*sz
);
312 extern LPWSTR
MSI_makestring( MSIDATABASE
*db
, UINT stringid
);
313 extern UINT
msi_string2idW( string_table
*st
, LPCWSTR buffer
, UINT
*id
);
314 extern UINT
msi_string2idA( string_table
*st
, LPCSTR str
, UINT
*id
);
315 extern string_table
*msi_init_stringtable( int entries
, UINT codepage
);
316 extern VOID
msi_destroy_stringtable( string_table
*st
);
317 extern UINT
msi_string_count( string_table
*st
);
318 extern UINT
msi_id_refcount( string_table
*st
, UINT i
);
319 extern UINT
msi_string_totalsize( string_table
*st
, UINT
*last
);
320 extern UINT
msi_strcmp( string_table
*st
, UINT lval
, UINT rval
, UINT
*res
);
321 extern const WCHAR
*msi_string_lookup_id( string_table
*st
, UINT id
);
322 extern UINT
msi_string_get_codepage( string_table
*st
);
325 extern UINT
VIEW_find_column( MSIVIEW
*view
, LPCWSTR name
, UINT
*n
);
327 extern BOOL
TABLE_Exists( MSIDATABASE
*db
, LPWSTR name
);
329 extern UINT
read_raw_stream_data( MSIDATABASE
*, LPCWSTR stname
,
330 USHORT
**pdata
, UINT
*psz
);
332 /* transform functions */
333 extern UINT
msi_table_apply_transform( MSIDATABASE
*db
, IStorage
*stg
);
334 extern UINT
MSI_DatabaseApplyTransformW( MSIDATABASE
*db
,
335 LPCWSTR szTransformFile
, int iErrorCond
);
337 /* action internals */
338 extern UINT
MSI_InstallPackage( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
339 extern void ACTION_free_package_structures( MSIPACKAGE
* );
340 extern UINT
ACTION_DialogBox( MSIPACKAGE
*, LPCWSTR
);
341 extern UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
);
342 extern UINT
MSI_SetFeatureStates( MSIPACKAGE
*package
);
344 /* record internals */
345 extern UINT
MSI_RecordSetIStream( MSIRECORD
*, unsigned int, IStream
*);
346 extern UINT
MSI_RecordGetIStream( MSIRECORD
*, unsigned int, IStream
**);
347 extern const WCHAR
*MSI_RecordGetString( MSIRECORD
*, unsigned int );
348 extern MSIRECORD
*MSI_CreateRecord( unsigned int );
349 extern UINT
MSI_RecordSetInteger( MSIRECORD
*, unsigned int, int );
350 extern UINT
MSI_RecordSetStringW( MSIRECORD
*, unsigned int, LPCWSTR
);
351 extern UINT
MSI_RecordSetStringA( MSIRECORD
*, unsigned int, LPCSTR
);
352 extern BOOL
MSI_RecordIsNull( MSIRECORD
*, unsigned int );
353 extern UINT
MSI_RecordGetStringW( MSIRECORD
* , unsigned int, LPWSTR
, DWORD
*);
354 extern UINT
MSI_RecordGetStringA( MSIRECORD
*, unsigned int, LPSTR
, DWORD
*);
355 extern int MSI_RecordGetInteger( MSIRECORD
*, unsigned int );
356 extern UINT
MSI_RecordReadStream( MSIRECORD
*, unsigned int, char *, DWORD
*);
357 extern unsigned int MSI_RecordGetFieldCount( MSIRECORD
*rec
);
358 extern UINT
MSI_RecordSetStreamW( MSIRECORD
*, unsigned int, LPCWSTR
);
359 extern UINT
MSI_RecordSetStreamA( MSIRECORD
*, unsigned int, LPCSTR
);
360 extern UINT
MSI_RecordDataSize( MSIRECORD
*, unsigned int );
361 extern UINT
MSI_RecordStreamToFile( MSIRECORD
*, unsigned int, LPCWSTR
);
363 /* stream internals */
364 extern UINT
get_raw_stream( MSIHANDLE hdb
, LPCWSTR stname
, IStream
**stm
);
365 extern UINT
db_get_raw_stream( MSIDATABASE
*db
, LPCWSTR stname
, IStream
**stm
);
366 extern void enum_stream_names( IStorage
*stg
);
368 /* database internals */
369 extern UINT
MSI_OpenDatabaseW( LPCWSTR
, LPCWSTR
, MSIDATABASE
** );
370 extern UINT
MSI_DatabaseOpenViewW(MSIDATABASE
*, LPCWSTR
, MSIQUERY
** );
371 extern UINT
MSI_OpenQuery( MSIDATABASE
*, MSIQUERY
**, LPCWSTR
, ... );
372 typedef UINT (*record_func
)( MSIRECORD
*, LPVOID
);
373 extern UINT
MSI_IterateRecords( MSIQUERY
*, DWORD
*, record_func
, LPVOID
);
374 extern MSIRECORD
*MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR query
, ... );
375 extern UINT
MSI_DatabaseImport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
);
376 extern UINT
MSI_DatabaseExport( MSIDATABASE
*, LPCWSTR
, LPCWSTR
, LPCWSTR
);
377 extern UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*, LPCWSTR
, MSIRECORD
** );
380 extern UINT
MSI_ViewExecute( MSIQUERY
*, MSIRECORD
* );
381 extern UINT
MSI_ViewFetch( MSIQUERY
*, MSIRECORD
** );
382 extern UINT
MSI_ViewClose( MSIQUERY
* );
384 /* install internals */
385 extern UINT
MSI_SetInstallLevel( MSIPACKAGE
*package
, int iInstallLevel
);
387 /* package internals */
388 extern MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
* );
389 extern UINT
MSI_OpenPackageW( LPCWSTR szPackage
, MSIPACKAGE
** );
390 extern UINT
MSI_SetTargetPathW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
391 extern UINT
MSI_SetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
);
392 extern INT
MSI_ProcessMessage( MSIPACKAGE
*, INSTALLMESSAGE
, MSIRECORD
* );
393 extern UINT
MSI_GetPropertyW( MSIPACKAGE
*, LPCWSTR
, LPWSTR
, DWORD
* );
394 extern UINT
MSI_GetPropertyA(MSIPACKAGE
*, LPCSTR
, LPSTR
, DWORD
* );
395 extern MSICONDITION
MSI_EvaluateConditionW( MSIPACKAGE
*, LPCWSTR
);
396 extern UINT
MSI_GetComponentStateW( MSIPACKAGE
*, LPWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
397 extern UINT
MSI_GetFeatureStateW( MSIPACKAGE
*, LPWSTR
, INSTALLSTATE
*, INSTALLSTATE
* );
398 extern UINT WINAPI
MSI_SetFeatureStateW(MSIPACKAGE
*, LPCWSTR
, INSTALLSTATE
);
400 /* for deformating */
401 extern UINT
MSI_FormatRecordW( MSIPACKAGE
*, MSIRECORD
*, LPWSTR
, DWORD
* );
402 extern UINT
MSI_FormatRecordA( MSIPACKAGE
*, MSIRECORD
*, LPSTR
, DWORD
* );
404 /* registry data encoding/decoding functions */
405 extern BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
);
406 extern BOOL
squash_guid(LPCWSTR in
, LPWSTR out
);
407 extern BOOL
encode_base85_guid(GUID
*,LPWSTR
);
408 extern BOOL
decode_base85_guid(LPCWSTR
,GUID
*);
409 extern UINT
MSIREG_OpenUninstallKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
410 extern UINT
MSIREG_OpenUserProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
411 extern UINT
MSIREG_OpenFeatures(HKEY
* key
);
412 extern UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
413 extern UINT
MSIREG_OpenComponents(HKEY
* key
);
414 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
415 extern UINT
MSIREG_OpenComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
416 extern UINT
MSIREG_OpenProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
417 extern UINT
MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
418 extern UINT
MSIREG_OpenUserComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
);
419 extern UINT
MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
420 extern UINT
MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
);
422 extern LPWSTR
msi_reg_get_val_str( HKEY hkey
, LPCWSTR name
);
423 extern BOOL
msi_reg_get_val_dword( HKEY hkey
, LPCWSTR name
, DWORD
*val
);
425 extern DWORD
msi_version_str_to_dword(LPCWSTR p
);
426 extern LPWSTR
msi_version_dword_to_str(DWORD version
);
428 extern LONG
msi_reg_set_val_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
429 extern LONG
msi_reg_set_val_multi_str( HKEY hkey
, LPCWSTR name
, LPCWSTR value
);
430 extern LONG
msi_reg_set_val_dword( HKEY hkey
, LPCWSTR name
, DWORD val
);
431 extern LONG
msi_reg_set_subkey_val( HKEY hkey
, LPCWSTR path
, LPCWSTR name
, LPCWSTR val
);
433 /* msi dialog interface */
434 typedef UINT (*msi_dialog_event_handler
)( MSIPACKAGE
*, LPCWSTR
, LPCWSTR
, msi_dialog
* );
435 extern msi_dialog
*msi_dialog_create( MSIPACKAGE
*, LPCWSTR
, msi_dialog_event_handler
);
436 extern UINT
msi_dialog_run_message_loop( msi_dialog
* );
437 extern void msi_dialog_end_dialog( msi_dialog
* );
438 extern void msi_dialog_check_messages( HANDLE
);
439 extern void msi_dialog_do_preview( msi_dialog
* );
440 extern void msi_dialog_destroy( msi_dialog
* );
441 extern BOOL
msi_dialog_register_class( void );
442 extern void msi_dialog_unregister_class( void );
443 extern void msi_dialog_handle_event( msi_dialog
*, LPCWSTR
, LPCWSTR
, MSIRECORD
* );
444 extern UINT
msi_dialog_reset( msi_dialog
*dialog
);
447 extern MSIPREVIEW
*MSI_EnableUIPreview( MSIDATABASE
* );
448 extern UINT
MSI_PreviewDialogW( MSIPREVIEW
*, LPCWSTR
);
450 /* summary information */
451 extern MSISUMMARYINFO
*MSI_GetSummaryInformationW( MSIDATABASE
*db
, UINT uiUpdateCount
);
452 extern LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
);
454 /* undocumented functions */
455 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory( DWORD
);
456 UINT WINAPI
MsiDecomposeDescriptorW( LPCWSTR
, LPWSTR
, LPWSTR
, LPWSTR
, DWORD
* );
457 UINT WINAPI
MsiDecomposeDescriptorA( LPCSTR
, LPSTR
, LPSTR
, LPSTR
, DWORD
* );
458 LANGID WINAPI
MsiLoadStringW( MSIHANDLE
, UINT
, LPWSTR
, int, LANGID
);
459 LANGID WINAPI
MsiLoadStringA( MSIHANDLE
, UINT
, LPSTR
, int, LANGID
);
462 extern INSTALLUILEVEL gUILevel
;
464 extern INSTALLUI_HANDLERA gUIHandlerA
;
465 extern INSTALLUI_HANDLERW gUIHandlerW
;
466 extern DWORD gUIFilter
;
467 extern LPVOID gUIContext
;
468 extern WCHAR gszLogFile
[MAX_PATH
];
469 extern HINSTANCE msi_hInstance
;
471 /* memory allocation macro functions */
472 static inline void *msi_alloc( size_t len
)
474 return HeapAlloc( GetProcessHeap(), 0, len
);
477 static inline void *msi_alloc_zero( size_t len
)
479 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
482 static inline void *msi_realloc( void *mem
, size_t len
)
484 return HeapReAlloc( GetProcessHeap(), 0, mem
, len
);
487 static inline void *msi_realloc_zero( void *mem
, size_t len
)
489 return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
492 static inline BOOL
msi_free( void *mem
)
494 return HeapFree( GetProcessHeap(), 0, mem
);
497 inline static char *strdupWtoA( LPCWSTR str
)
502 if (!str
) return ret
;
503 len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
504 ret
= msi_alloc( len
);
506 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
510 inline static LPWSTR
strdupAtoW( LPCSTR str
)
515 if (!str
) return ret
;
516 len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
517 ret
= msi_alloc( len
* sizeof(WCHAR
) );
519 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
523 inline static LPWSTR
strdupW( LPCWSTR src
)
526 if (!src
) return NULL
;
527 dest
= msi_alloc( (lstrlenW(src
)+1)*sizeof(WCHAR
) );
533 #endif /* __WINE_MSI_PRIVATE__ */