msi: Properly register and unregister components.
[wine] / dlls / msi / msipriv.h
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002-2005 Mike McCormack for CodeWeavers
5  * Copyright 2005 Aric Stewart for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #ifndef __WINE_MSI_PRIVATE__
23 #define __WINE_MSI_PRIVATE__
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "msi.h"
30 #include "msiquery.h"
31 #include "objbase.h"
32 #include "objidl.h"
33 #include "winnls.h"
34 #include "wine/list.h"
35
36 #define MSI_DATASIZEMASK 0x00ff
37 #define MSITYPE_VALID    0x0100
38 #define MSITYPE_LOCALIZABLE 0x200
39 #define MSITYPE_STRING   0x0800
40 #define MSITYPE_NULLABLE 0x1000
41 #define MSITYPE_KEY      0x2000
42 #define MSITYPE_TEMPORARY 0x4000
43
44 /* Word Count masks */
45 #define MSIWORDCOUNT_SHORTFILENAMES     0x0001
46 #define MSIWORDCOUNT_COMPRESSED         0x0002
47 #define MSIWORDCOUNT_ADMINISTRATIVE     0x0004
48 #define MSIWORDCOUNT_PRIVILEGES         0x0008
49
50 /* Install UI level mask for AND operation to exclude flags */
51 #define INSTALLUILEVEL_MASK             0x0007
52
53 #define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
54
55 struct tagMSITABLE;
56 typedef struct tagMSITABLE MSITABLE;
57
58 struct string_table;
59 typedef struct string_table string_table;
60
61 struct tagMSIOBJECTHDR;
62 typedef struct tagMSIOBJECTHDR MSIOBJECTHDR;
63
64 typedef VOID (*msihandledestructor)( MSIOBJECTHDR * );
65
66 struct tagMSIOBJECTHDR
67 {
68     UINT magic;
69     UINT type;
70     LONG refcount;
71     msihandledestructor destructor;
72 };
73
74 typedef struct tagMSIDATABASE
75 {
76     MSIOBJECTHDR hdr;
77     IStorage *storage;
78     string_table *strings;
79     UINT bytes_per_strref;
80     LPWSTR path;
81     LPWSTR deletefile;
82     LPCWSTR mode;
83     struct list tables;
84     struct list transforms;
85 } MSIDATABASE;
86
87 typedef struct tagMSIVIEW MSIVIEW;
88
89 typedef struct tagMSIQUERY
90 {
91     MSIOBJECTHDR hdr;
92     MSIVIEW *view;
93     UINT row;
94     MSIDATABASE *db;
95     struct list mem;
96 } MSIQUERY;
97
98 /* maybe we can use a Variant instead of doing it ourselves? */
99 typedef struct tagMSIFIELD
100 {
101     UINT type;
102     union
103     {
104         INT iVal;
105         LPWSTR szwVal;
106         IStream *stream;
107     } u;
108 } MSIFIELD;
109
110 typedef struct tagMSIRECORD
111 {
112     MSIOBJECTHDR hdr;
113     UINT count;       /* as passed to MsiCreateRecord */
114     MSIFIELD fields[1]; /* nb. array size is count+1 */
115 } MSIRECORD;
116
117 typedef struct tagMSISOURCELISTINFO
118 {
119     struct list entry;
120     DWORD context;
121     DWORD options;
122     LPCWSTR property;
123     LPWSTR value;
124 } MSISOURCELISTINFO;
125
126 typedef struct tagMSIMEDIADISK
127 {
128     struct list entry;
129     DWORD context;
130     DWORD options;
131     DWORD disk_id;
132     LPWSTR volume_label;
133     LPWSTR disk_prompt;
134 } MSIMEDIADISK;
135
136 typedef const struct tagMSICOLUMNHASHENTRY *MSIITERHANDLE;
137
138 typedef struct tagMSIVIEWOPS
139 {
140     /*
141      * fetch_int - reads one integer from {row,col} in the table
142      *
143      *  This function should be called after the execute method.
144      *  Data returned by the function should not change until
145      *   close or delete is called.
146      *  To get a string value, query the database's string table with
147      *   the integer value returned from this function.
148      */
149     UINT (*fetch_int)( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val );
150
151     /*
152      * fetch_stream - gets a stream from {row,col} in the table
153      *
154      *  This function is similar to fetch_int, except fetches a
155      *    stream instead of an integer.
156      */
157     UINT (*fetch_stream)( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm );
158
159     /*
160      * get_row - gets values from a row
161      *
162      */
163     UINT (*get_row)( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec );
164
165     /*
166      * set_row - sets values in a row as specified by mask
167      *
168      *  Similar semantics to fetch_int
169      */
170     UINT (*set_row)( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask );
171
172     /*
173      * Inserts a new row into the database from the records contents
174      */
175     UINT (*insert_row)( struct tagMSIVIEW *view, MSIRECORD *record, BOOL temporary );
176
177     /*
178      * Deletes a row from the database
179      */
180     UINT (*delete_row)( struct tagMSIVIEW *view, UINT row );
181
182     /*
183      * execute - loads the underlying data into memory so it can be read
184      */
185     UINT (*execute)( struct tagMSIVIEW *view, MSIRECORD *record );
186
187     /*
188      * close - clears the data read by execute from memory
189      */
190     UINT (*close)( struct tagMSIVIEW *view );
191
192     /*
193      * get_dimensions - returns the number of rows or columns in a table.
194      *
195      *  The number of rows can only be queried after the execute method
196      *   is called. The number of columns can be queried at any time.
197      */
198     UINT (*get_dimensions)( struct tagMSIVIEW *view, UINT *rows, UINT *cols );
199
200     /*
201      * get_column_info - returns the name and type of a specific column
202      *
203      *  The name is HeapAlloc'ed by this function and should be freed by
204      *   the caller.
205      *  The column information can be queried at any time.
206      */
207     UINT (*get_column_info)( struct tagMSIVIEW *view, UINT n, LPWSTR *name, UINT *type );
208
209     /*
210      * modify - not yet implemented properly
211      */
212     UINT (*modify)( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *record, UINT row );
213
214     /*
215      * delete - destroys the structure completely
216      */
217     UINT (*delete)( struct tagMSIVIEW * );
218
219     /*
220      * find_matching_rows - iterates through rows that match a value
221      *
222      * If the column type is a string then a string ID should be passed in.
223      *  If the value to be looked up is an integer then no transformation of
224      *  the input value is required, except if the column is a string, in which
225      *  case a string ID should be passed in.
226      * The handle is an input/output parameter that keeps track of the current
227      *  position in the iteration. It must be initialised to zero before the
228      *  first call and continued to be passed in to subsequent calls.
229      */
230     UINT (*find_matching_rows)( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle );
231
232     /*
233      * add_ref - increases the reference count of the table
234      */
235     UINT (*add_ref)( struct tagMSIVIEW *view );
236
237     /*
238      * release - decreases the reference count of the table
239      */
240     UINT (*release)( struct tagMSIVIEW *view );
241
242     /*
243      * add_column - adds a column to the table
244      */
245     UINT (*add_column)( struct tagMSIVIEW *view, LPCWSTR table, UINT number, LPCWSTR column, UINT type, BOOL hold );
246
247     /*
248      * remove_column - removes the column represented by table name and column number from the table
249      */
250     UINT (*remove_column)( struct tagMSIVIEW *view, LPCWSTR table, UINT number );
251 } MSIVIEWOPS;
252
253 struct tagMSIVIEW
254 {
255     MSIOBJECTHDR hdr;
256     const MSIVIEWOPS *ops;
257 };
258
259 struct msi_dialog_tag;
260 typedef struct msi_dialog_tag msi_dialog;
261
262 typedef struct tagMSIPACKAGE
263 {
264     MSIOBJECTHDR hdr;
265     MSIDATABASE *db;
266     struct list components;
267     struct list features;
268     struct list files;
269     struct list tempfiles;
270     struct list folders;
271     LPWSTR ActionFormat;
272     LPWSTR LastAction;
273
274     struct list classes;
275     struct list extensions;
276     struct list progids;
277     struct list mimes;
278     struct list appids;
279
280     struct tagMSISCRIPT *script;
281
282     struct list RunningActions;
283
284     LPWSTR BaseURL;
285     LPWSTR PackagePath;
286     LPWSTR ProductCode;
287
288     UINT CurrentInstallState;
289     msi_dialog *dialog;
290     LPWSTR next_dialog;
291     float center_x;
292     float center_y;
293
294     UINT WordCount;
295
296     struct list subscriptions;
297
298     struct list sourcelist_info;
299     struct list sourcelist_media;
300
301     unsigned char scheduled_action_running : 1;
302     unsigned char commit_action_running : 1;
303     unsigned char rollback_action_running : 1;
304 } MSIPACKAGE;
305
306 typedef struct tagMSIPREVIEW
307 {
308     MSIOBJECTHDR hdr;
309     MSIPACKAGE *package;
310     msi_dialog *dialog;
311 } MSIPREVIEW;
312
313 #define MSI_MAX_PROPS 20
314
315 typedef struct tagMSISUMMARYINFO
316 {
317     MSIOBJECTHDR hdr;
318     IStorage *storage;
319     DWORD update_count;
320     PROPVARIANT property[MSI_MAX_PROPS];
321 } MSISUMMARYINFO;
322
323 typedef struct tagMSIFEATURE
324 {
325     struct list entry;
326     LPWSTR Feature;
327     LPWSTR Feature_Parent;
328     LPWSTR Title;
329     LPWSTR Description;
330     INT Display;
331     INT Level;
332     LPWSTR Directory;
333     INT Attributes;
334     INSTALLSTATE Installed;
335     INSTALLSTATE ActionRequest;
336     INSTALLSTATE Action;
337     struct list Children;
338     struct list Components;
339     INT Cost;
340 } MSIFEATURE;
341
342 typedef struct tagMSICOMPONENT
343 {
344     struct list entry;
345     DWORD magic;
346     LPWSTR Component;
347     LPWSTR ComponentId;
348     LPWSTR Directory;
349     INT Attributes;
350     LPWSTR Condition;
351     LPWSTR KeyPath;
352     INSTALLSTATE Installed;
353     INSTALLSTATE ActionRequest;
354     INSTALLSTATE Action;
355     BOOL ForceLocalState;
356     BOOL Enabled;
357     INT  Cost;
358     INT  RefCount;
359     LPWSTR FullKeypath;
360     LPWSTR AdvertiseString;
361
362     unsigned int anyAbsent:1;
363     unsigned int hasAdvertiseFeature:1;
364     unsigned int hasLocalFeature:1;
365     unsigned int hasSourceFeature:1;
366 } MSICOMPONENT;
367
368 typedef struct tagComponentList
369 {
370     struct list entry;
371     MSICOMPONENT *component;
372 } ComponentList;
373
374 typedef struct tagFeatureList
375 {
376     struct list entry;
377     MSIFEATURE *feature;
378 } FeatureList;
379
380 typedef struct tagMSIFOLDER
381 {
382     struct list entry;
383     LPWSTR Directory;
384     LPWSTR Parent;
385     LPWSTR TargetDefault;
386     LPWSTR SourceLongPath;
387     LPWSTR SourceShortPath;
388
389     LPWSTR ResolvedTarget;
390     LPWSTR ResolvedSource;
391     LPWSTR Property;   /* initially set property */
392     INT   State;
393         /* 0 = uninitialized */
394         /* 1 = existing */
395         /* 2 = created remove if empty */
396         /* 3 = created persist if empty */
397     INT   Cost;
398     INT   Space;
399 } MSIFOLDER;
400
401 typedef enum _msi_file_state {
402     msifs_invalid,
403     msifs_missing,
404     msifs_overwrite,
405     msifs_present,
406     msifs_installed,
407     msifs_skipped,
408 } msi_file_state;
409
410 typedef struct tagMSIFILE
411 {
412     struct list entry;
413     LPWSTR File;
414     MSICOMPONENT *Component;
415     LPWSTR FileName;
416     LPWSTR ShortName;
417     LPWSTR LongName;
418     INT FileSize;
419     LPWSTR Version;
420     LPWSTR Language;
421     INT Attributes;
422     INT Sequence;
423     msi_file_state state;
424     LPWSTR  SourcePath;
425     LPWSTR  TargetPath;
426     BOOL IsCompressed;
427 } MSIFILE;
428
429 typedef struct tagMSITEMPFILE
430 {
431     struct list entry;
432     LPWSTR Path;
433 } MSITEMPFILE;
434
435 typedef struct tagMSIAPPID
436 {
437     struct list entry;
438     LPWSTR AppID; /* Primary key */
439     LPWSTR RemoteServerName;
440     LPWSTR LocalServer;
441     LPWSTR ServiceParameters;
442     LPWSTR DllSurrogate;
443     BOOL ActivateAtStorage;
444     BOOL RunAsInteractiveUser;
445 } MSIAPPID;
446
447 typedef struct tagMSIPROGID MSIPROGID;
448
449 typedef struct tagMSICLASS
450 {
451     struct list entry;
452     LPWSTR clsid;     /* Primary Key */
453     LPWSTR Context;   /* Primary Key */
454     MSICOMPONENT *Component;
455     MSIPROGID *ProgID;
456     LPWSTR ProgIDText;
457     LPWSTR Description;
458     MSIAPPID *AppID;
459     LPWSTR FileTypeMask;
460     LPWSTR IconPath;
461     LPWSTR DefInprocHandler;
462     LPWSTR DefInprocHandler32;
463     LPWSTR Argument;
464     MSIFEATURE *Feature;
465     INT Attributes;
466     /* not in the table, set during installation */
467     BOOL Installed;
468 } MSICLASS;
469
470 typedef struct tagMSIMIME MSIMIME;
471
472 typedef struct tagMSIEXTENSION
473 {
474     struct list entry;
475     LPWSTR Extension;  /* Primary Key */
476     MSICOMPONENT *Component;
477     MSIPROGID *ProgID;
478     LPWSTR ProgIDText;
479     MSIMIME *Mime;
480     MSIFEATURE *Feature;
481     /* not in the table, set during installation */
482     BOOL Installed;
483     struct list verbs;
484 } MSIEXTENSION;
485
486 struct tagMSIPROGID
487 {
488     struct list entry;
489     LPWSTR ProgID;  /* Primary Key */
490     MSIPROGID *Parent;
491     MSICLASS *Class;
492     LPWSTR Description;
493     LPWSTR IconPath;
494     /* not in the table, set during installation */
495     BOOL InstallMe;
496     MSIPROGID *CurVer;
497     MSIPROGID *VersionInd;
498 };
499
500 typedef struct tagMSIVERB
501 {
502     struct list entry;
503     LPWSTR Verb;
504     INT Sequence;
505     LPWSTR Command;
506     LPWSTR Argument;
507 } MSIVERB;
508
509 struct tagMSIMIME
510 {
511     struct list entry;
512     LPWSTR ContentType;  /* Primary Key */
513     MSIEXTENSION *Extension;
514     LPWSTR clsid;
515     MSICLASS *Class;
516     /* not in the table, set during installation */
517     BOOL InstallMe;
518 };
519
520 enum SCRIPTS {
521     INSTALL_SCRIPT = 0,
522     COMMIT_SCRIPT = 1,
523     ROLLBACK_SCRIPT = 2,
524     TOTAL_SCRIPTS = 3
525 };
526
527 #define SEQUENCE_UI       0x1
528 #define SEQUENCE_EXEC     0x2
529 #define SEQUENCE_INSTALL  0x10
530
531 typedef struct tagMSISCRIPT
532 {
533     LPWSTR  *Actions[TOTAL_SCRIPTS];
534     UINT    ActionCount[TOTAL_SCRIPTS];
535     BOOL    ExecuteSequenceRun;
536     BOOL    CurrentlyScripting;
537     UINT    InWhatSequence;
538     LPWSTR  *UniqueActions;
539     UINT    UniqueActionsCount;
540 } MSISCRIPT;
541
542 #define MSIHANDLETYPE_ANY 0
543 #define MSIHANDLETYPE_DATABASE 1
544 #define MSIHANDLETYPE_SUMMARYINFO 2
545 #define MSIHANDLETYPE_VIEW 3
546 #define MSIHANDLETYPE_RECORD 4
547 #define MSIHANDLETYPE_PACKAGE 5
548 #define MSIHANDLETYPE_PREVIEW 6
549
550 #define MSI_MAJORVERSION 3
551 #define MSI_MINORVERSION 1
552 #define MSI_BUILDNUMBER 4000
553
554 #define GUID_SIZE 39
555
556 #define MSIHANDLE_MAGIC 0x4d434923
557
558 DEFINE_GUID(CLSID_IMsiServer,   0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
559 DEFINE_GUID(CLSID_IMsiServerX1, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
560 DEFINE_GUID(CLSID_IMsiServerX2, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
561 DEFINE_GUID(CLSID_IMsiServerX3, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
562
563 DEFINE_GUID(CLSID_IMsiServerMessage, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
564
565 DEFINE_GUID(CLSID_IWineMsiRemoteCustomAction,0xBA26E6FA,0x4F27,0x4f56,0x95,0x3A,0x3F,0x90,0x27,0x20,0x18,0xAA);
566 DEFINE_GUID(CLSID_IWineMsiRemotePackage,0x902b3592,0x9d08,0x4dfd,0xa5,0x93,0xd0,0x7c,0x52,0x54,0x64,0x21);
567
568 /* handle unicode/ascii output in the Msi* API functions */
569 typedef struct {
570     BOOL unicode;
571     union {
572        LPSTR a;
573        LPWSTR w;
574     } str;
575 } awstring;
576
577 typedef struct {
578     BOOL unicode;
579     union {
580        LPCSTR a;
581        LPCWSTR w;
582     } str;
583 } awcstring;
584
585 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz );
586
587 /* msi server interface */
588 extern ITypeLib *get_msi_typelib( LPWSTR *path );
589 extern HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj );
590 extern HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj );
591 extern IUnknown *msi_get_remote(MSIHANDLE handle);
592
593 /* handle functions */
594 extern void *msihandle2msiinfo(MSIHANDLE handle, UINT type);
595 extern MSIHANDLE alloc_msihandle( MSIOBJECTHDR * );
596 extern MSIHANDLE alloc_msi_remote_handle( IUnknown *unk );
597 extern void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy );
598 extern void msiobj_addref(MSIOBJECTHDR *);
599 extern int msiobj_release(MSIOBJECTHDR *);
600 extern void msiobj_lock(MSIOBJECTHDR *);
601 extern void msiobj_unlock(MSIOBJECTHDR *);
602 extern void msi_free_handle_table(void);
603
604 extern void free_cached_tables( MSIDATABASE *db );
605 extern void msi_free_transforms( MSIDATABASE *db );
606 extern UINT MSI_CommitTables( MSIDATABASE *db );
607
608
609 /* string table functions */
610 enum StringPersistence
611 {
612     StringPersistent = 0,
613     StringNonPersistent = 1
614 };
615
616 extern BOOL msi_addstringW( string_table *st, UINT string_no, const WCHAR *data, int len, UINT refcount, enum StringPersistence persistence );
617 extern UINT msi_id2stringW( const string_table *st, UINT string_no, LPWSTR buffer, UINT *sz );
618 extern UINT msi_id2stringA( const string_table *st, UINT string_no, LPSTR buffer, UINT *sz );
619
620 extern UINT msi_string2idW( const string_table *st, LPCWSTR buffer, UINT *id );
621 extern UINT msi_string2idA( const string_table *st, LPCSTR str, UINT *id );
622 extern VOID msi_destroy_stringtable( string_table *st );
623 extern UINT msi_strcmp( const string_table *st, UINT lval, UINT rval, UINT *res );
624 extern const WCHAR *msi_string_lookup_id( const string_table *st, UINT id );
625 extern HRESULT msi_init_string_table( IStorage *stg );
626 extern string_table *msi_load_string_table( IStorage *stg, UINT *bytes_per_strref );
627 extern UINT msi_save_string_table( const string_table *st, IStorage *storage );
628
629
630 extern void msi_table_set_strref(UINT bytes_per_strref);
631 extern BOOL TABLE_Exists( MSIDATABASE *db, LPCWSTR name );
632 extern MSICONDITION MSI_DatabaseIsTablePersistent( MSIDATABASE *db, LPCWSTR table );
633
634 extern UINT read_raw_stream_data( MSIDATABASE *db, LPCWSTR stname,
635                                   USHORT **pdata, UINT *psz );
636 extern UINT read_stream_data( IStorage *stg, LPCWSTR stname, BOOL table,
637                               BYTE **pdata, UINT *psz );
638 extern UINT write_stream_data( IStorage *stg, LPCWSTR stname,
639                                LPCVOID data, UINT sz, BOOL bTable );
640
641 /* transform functions */
642 extern UINT msi_table_apply_transform( MSIDATABASE *db, IStorage *stg );
643 extern UINT MSI_DatabaseApplyTransformW( MSIDATABASE *db,
644                  LPCWSTR szTransformFile, int iErrorCond );
645 extern void append_storage_to_db( MSIDATABASE *db, IStorage *stg );
646
647 /* action internals */
648 extern UINT MSI_InstallPackage( MSIPACKAGE *, LPCWSTR, LPCWSTR );
649 extern void ACTION_free_package_structures( MSIPACKAGE* );
650 extern UINT ACTION_DialogBox( MSIPACKAGE*, LPCWSTR);
651 extern UINT ACTION_ForceReboot(MSIPACKAGE *package);
652 extern UINT MSI_Sequence( MSIPACKAGE *package, LPCWSTR szTable, INT iSequenceMode );
653 extern UINT MSI_SetFeatureStates( MSIPACKAGE *package );
654 extern UINT msi_parse_command_line( MSIPACKAGE *package, LPCWSTR szCommandLine );
655
656 /* record internals */
657 extern UINT MSI_RecordSetIStream( MSIRECORD *, UINT, IStream *);
658 extern UINT MSI_RecordGetIStream( MSIRECORD *, UINT, IStream **);
659 extern const WCHAR *MSI_RecordGetString( const MSIRECORD *, UINT );
660 extern MSIRECORD *MSI_CreateRecord( UINT );
661 extern UINT MSI_RecordSetInteger( MSIRECORD *, UINT, int );
662 extern UINT MSI_RecordSetStringW( MSIRECORD *, UINT, LPCWSTR );
663 extern UINT MSI_RecordSetStringA( MSIRECORD *, UINT, LPCSTR );
664 extern BOOL MSI_RecordIsNull( MSIRECORD *, UINT );
665 extern UINT MSI_RecordGetStringW( MSIRECORD * , UINT, LPWSTR, LPDWORD);
666 extern UINT MSI_RecordGetStringA( MSIRECORD *, UINT, LPSTR, LPDWORD);
667 extern int MSI_RecordGetInteger( MSIRECORD *, UINT );
668 extern UINT MSI_RecordReadStream( MSIRECORD *, UINT, char *, LPDWORD);
669 extern UINT MSI_RecordGetFieldCount( const MSIRECORD *rec );
670 extern UINT MSI_RecordSetStream( MSIRECORD *, UINT, IStream * );
671 extern UINT MSI_RecordDataSize( MSIRECORD *, UINT );
672 extern UINT MSI_RecordStreamToFile( MSIRECORD *, UINT, LPCWSTR );
673 extern UINT MSI_RecordCopyField( MSIRECORD *, UINT, MSIRECORD *, UINT );
674
675 /* stream internals */
676 extern UINT get_raw_stream( MSIHANDLE hdb, LPCWSTR stname, IStream **stm );
677 extern UINT db_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm );
678 extern void enum_stream_names( IStorage *stg );
679 extern BOOL decode_streamname(LPCWSTR in, LPWSTR out);
680 extern LPWSTR encode_streamname(BOOL bTable, LPCWSTR in);
681
682 /* database internals */
683 extern UINT MSI_OpenDatabaseW( LPCWSTR, LPCWSTR, MSIDATABASE ** );
684 extern UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY ** );
685 extern UINT MSI_OpenQuery( MSIDATABASE *, MSIQUERY **, LPCWSTR, ... );
686 typedef UINT (*record_func)( MSIRECORD *, LPVOID );
687 extern UINT MSI_IterateRecords( MSIQUERY *, LPDWORD, record_func, LPVOID );
688 extern MSIRECORD *MSI_QueryGetRecord( MSIDATABASE *db, LPCWSTR query, ... );
689 extern UINT MSI_DatabaseImport( MSIDATABASE *, LPCWSTR, LPCWSTR );
690 extern UINT MSI_DatabaseExport( MSIDATABASE *, LPCWSTR, LPCWSTR, LPCWSTR );
691 extern UINT MSI_DatabaseGetPrimaryKeys( MSIDATABASE *, LPCWSTR, MSIRECORD ** );
692
693 /* view internals */
694 extern UINT MSI_ViewExecute( MSIQUERY*, MSIRECORD * );
695 extern UINT MSI_ViewFetch( MSIQUERY*, MSIRECORD ** );
696 extern UINT MSI_ViewClose( MSIQUERY* );
697 extern UINT MSI_ViewGetColumnInfo(MSIQUERY *, MSICOLINFO, MSIRECORD **);
698 extern UINT MSI_ViewModify( MSIQUERY *, MSIMODIFY, MSIRECORD * );
699 extern UINT VIEW_find_column( MSIVIEW *, LPCWSTR, UINT * );
700 extern UINT msi_view_get_row(MSIDATABASE *, MSIVIEW *, UINT, MSIRECORD **);
701
702 /* install internals */
703 extern UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel );
704
705 /* package internals */
706 extern MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *, LPCWSTR );
707 extern UINT MSI_OpenPackageW( LPCWSTR szPackage, MSIPACKAGE **pPackage );
708 extern UINT MSI_SetTargetPathW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
709 extern UINT MSI_SetPropertyW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
710 extern INT MSI_ProcessMessage( MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD * );
711 extern UINT MSI_GetPropertyW( MSIPACKAGE *, LPCWSTR, LPWSTR, LPDWORD );
712 extern UINT MSI_GetPropertyA(MSIPACKAGE *, LPCSTR, LPSTR, LPDWORD );
713 extern MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *, LPCWSTR );
714 extern UINT MSI_GetComponentStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
715 extern UINT MSI_GetFeatureStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
716 extern UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE*, LPCWSTR, INSTALLSTATE );
717 extern LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename );
718 extern UINT msi_package_add_info(MSIPACKAGE *, DWORD, DWORD, LPCWSTR, LPWSTR);
719 extern UINT msi_package_add_media_disk(MSIPACKAGE *, DWORD, DWORD, DWORD, LPWSTR, LPWSTR);
720 extern UINT msi_clone_properties(MSIPACKAGE *);
721
722 /* for deformating */
723 extern UINT MSI_FormatRecordW( MSIPACKAGE *, MSIRECORD *, LPWSTR, LPDWORD );
724
725 /* registry data encoding/decoding functions */
726 extern BOOL unsquash_guid(LPCWSTR in, LPWSTR out);
727 extern BOOL squash_guid(LPCWSTR in, LPWSTR out);
728 extern BOOL encode_base85_guid(GUID *,LPWSTR);
729 extern BOOL decode_base85_guid(LPCWSTR,GUID*);
730 extern UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create);
731 extern UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
732 extern UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create);
733 extern UINT MSIREG_OpenFeatures(HKEY* key);
734 extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
735 extern UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create);
736 extern UINT MSIREG_OpenComponents(HKEY* key);
737 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
738 extern UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
739 extern UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create);
740 extern UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
741 extern UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create);
742 extern UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY* key, BOOL create);
743 extern UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
744 extern UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
745 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
746 extern UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
747 extern UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
748 extern UINT MSIREG_DeleteProductKey(LPCWSTR szProduct);
749 extern UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct);
750 extern UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct);
751 extern UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create);
752 extern UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create);
753 extern UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create);
754 extern UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create);
755 extern UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct);
756 extern UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent);
757
758 extern LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name );
759 extern BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val);
760
761 extern DWORD msi_version_str_to_dword(LPCWSTR p);
762 extern LPWSTR msi_version_dword_to_str(DWORD version);
763
764 extern LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value );
765 extern LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value );
766 extern LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val );
767 extern LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val );
768
769 /* msi dialog interface */
770 typedef UINT (*msi_dialog_event_handler)( MSIPACKAGE*, LPCWSTR, LPCWSTR, msi_dialog* );
771 extern msi_dialog *msi_dialog_create( MSIPACKAGE*, LPCWSTR, msi_dialog*, msi_dialog_event_handler );
772 extern UINT msi_dialog_run_message_loop( msi_dialog* );
773 extern void msi_dialog_end_dialog( msi_dialog* );
774 extern void msi_dialog_check_messages( HANDLE );
775 extern void msi_dialog_do_preview( msi_dialog* );
776 extern void msi_dialog_destroy( msi_dialog* );
777 extern BOOL msi_dialog_register_class( void );
778 extern void msi_dialog_unregister_class( void );
779 extern void msi_dialog_handle_event( msi_dialog*, LPCWSTR, LPCWSTR, MSIRECORD * );
780 extern UINT msi_dialog_reset( msi_dialog *dialog );
781 extern UINT msi_dialog_directorylist_up( msi_dialog *dialog );
782 extern msi_dialog *msi_dialog_get_parent( msi_dialog *dialog );
783 extern LPWSTR msi_dialog_get_name( msi_dialog *dialog );
784 extern UINT msi_spawn_error_dialog( MSIPACKAGE*, LPWSTR, LPWSTR );
785
786 /* preview */
787 extern MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE * );
788 extern UINT MSI_PreviewDialogW( MSIPREVIEW *, LPCWSTR );
789
790 /* summary information */
791 extern MSISUMMARYINFO *MSI_GetSummaryInformationW( IStorage *stg, UINT uiUpdateCount );
792 extern LPWSTR msi_suminfo_dup_string( MSISUMMARYINFO *si, UINT uiProperty );
793 extern LPWSTR msi_get_suminfo_product( IStorage *stg );
794
795 /* undocumented functions */
796 UINT WINAPI MsiCreateAndVerifyInstallerDirectory( DWORD );
797 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR, LPWSTR, LPWSTR, LPWSTR, LPDWORD );
798 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR, LPSTR, LPSTR, LPSTR, LPDWORD );
799 LANGID WINAPI MsiLoadStringW( MSIHANDLE, UINT, LPWSTR, int, LANGID );
800 LANGID WINAPI MsiLoadStringA( MSIHANDLE, UINT, LPSTR, int, LANGID );
801
802 /* UI globals */
803 extern INSTALLUILEVEL gUILevel;
804 extern HWND gUIhwnd;
805 extern INSTALLUI_HANDLERA gUIHandlerA;
806 extern INSTALLUI_HANDLERW gUIHandlerW;
807 extern DWORD gUIFilter;
808 extern LPVOID gUIContext;
809 extern WCHAR gszLogFile[MAX_PATH];
810 extern HINSTANCE msi_hInstance;
811
812 /* action related functions */
813 extern UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, UINT script, BOOL force);
814 extern UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action, UINT script);
815 extern void ACTION_FinishCustomActions( const MSIPACKAGE* package);
816 extern UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action, UINT script, BOOL execute);
817
818 static inline void msi_feature_set_state( MSIFEATURE *feature, INSTALLSTATE state )
819 {
820     feature->ActionRequest = state;
821     feature->Action = state;
822 }
823
824 static inline void msi_component_set_state( MSICOMPONENT *comp, INSTALLSTATE state )
825 {
826     comp->ActionRequest = state;
827     comp->Action = state;
828 }
829
830 /* actions in other modules */
831 extern UINT ACTION_AppSearch(MSIPACKAGE *package);
832 extern UINT ACTION_FindRelatedProducts(MSIPACKAGE *package);
833 extern UINT ACTION_InstallFiles(MSIPACKAGE *package);
834 extern UINT ACTION_RemoveFiles(MSIPACKAGE *package);
835 extern UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
836 extern UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
837 extern UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
838 extern UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package);
839 extern UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package);
840 extern UINT ACTION_RegisterFonts(MSIPACKAGE *package);
841
842 /* Helpers */
843 extern DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data );
844 extern LPWSTR msi_dup_record_field(MSIRECORD *row, INT index);
845 extern LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop);
846 extern int msi_get_property_int( MSIPACKAGE *package, LPCWSTR prop, int def );
847 extern LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
848                       BOOL set_prop, BOOL load_prop, MSIFOLDER **folder);
849 extern MSICOMPONENT *get_loaded_component( MSIPACKAGE* package, LPCWSTR Component );
850 extern MSIFEATURE *get_loaded_feature( MSIPACKAGE* package, LPCWSTR Feature );
851 extern MSIFILE *get_loaded_file( MSIPACKAGE* package, LPCWSTR file );
852 extern MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir );
853 extern int track_tempfile(MSIPACKAGE *package, LPCWSTR path);
854 extern UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action);
855 extern void msi_free_action_script(MSIPACKAGE *package, UINT script);
856 extern LPWSTR build_icon_path(MSIPACKAGE *, LPCWSTR);
857 extern LPWSTR build_directory_name(DWORD , ...);
858 extern BOOL create_full_pathW(const WCHAR *path);
859 extern BOOL ACTION_VerifyComponentForAction(const MSICOMPONENT*, INSTALLSTATE);
860 extern BOOL ACTION_VerifyFeatureForAction(const MSIFEATURE*, INSTALLSTATE);
861 extern void reduce_to_longfilename(WCHAR*);
862 extern void reduce_to_shortfilename(WCHAR*);
863 extern LPWSTR create_component_advertise_string(MSIPACKAGE*, MSICOMPONENT*, LPCWSTR);
864 extern void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature);
865 extern UINT register_unique_action(MSIPACKAGE *, LPCWSTR);
866 extern BOOL check_unique_action(const MSIPACKAGE *, LPCWSTR);
867 extern WCHAR* generate_error_string(MSIPACKAGE *, UINT, DWORD, ... );
868 extern UINT msi_create_component_directories( MSIPACKAGE *package );
869 extern void msi_ui_error( DWORD msg_id, DWORD type );
870
871 /* control event stuff */
872 extern VOID ControlEvent_FireSubscribedEvent(MSIPACKAGE *package, LPCWSTR event,
873                                       MSIRECORD *data);
874 extern VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog);
875 extern VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package);
876 extern VOID ControlEvent_SubscribeToEvent(MSIPACKAGE *package, msi_dialog *dialog,
877                                       LPCWSTR event, LPCWSTR control, LPCWSTR attribute);
878 extern VOID ControlEvent_UnSubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
879                                       LPCWSTR control, LPCWSTR attribute );
880
881 /* OLE automation */
882 extern HRESULT create_msiserver(IUnknown *pOuter, LPVOID *ppObj);
883 extern HRESULT create_session(MSIHANDLE msiHandle, IDispatch *pInstaller, IDispatch **pDispatch);
884 extern HRESULT load_type_info(IDispatch *iface, ITypeInfo **pptinfo, REFIID clsid, LCID lcid);
885
886 /* Scripting */
887 extern DWORD call_script(MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action);
888
889 /* User Interface messages from the actions */
890 extern void ui_progress(MSIPACKAGE *, int, int, int, int);
891 extern void ui_actiondata(MSIPACKAGE *, LPCWSTR, MSIRECORD *);
892
893 /* string consts use a number of places  and defined in helpers.c*/
894 extern const WCHAR cszSourceDir[];
895 extern const WCHAR cszSOURCEDIR[];
896 extern const WCHAR szProductCode[];
897 extern const WCHAR cszRootDrive[];
898 extern const WCHAR cszbs[];
899
900 /* memory allocation macro functions */
901 static inline void *msi_alloc( size_t len )
902 {
903     return HeapAlloc( GetProcessHeap(), 0, len );
904 }
905
906 static inline void *msi_alloc_zero( size_t len )
907 {
908     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
909 }
910
911 static inline void *msi_realloc( void *mem, size_t len )
912 {
913     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
914 }
915
916 static inline void *msi_realloc_zero( void *mem, size_t len )
917 {
918     return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len );
919 }
920
921 static inline BOOL msi_free( void *mem )
922 {
923     return HeapFree( GetProcessHeap(), 0, mem );
924 }
925
926 static inline char *strdupWtoA( LPCWSTR str )
927 {
928     LPSTR ret = NULL;
929     DWORD len;
930
931     if (!str) return ret;
932     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
933     ret = msi_alloc( len );
934     if (ret)
935         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
936     return ret;
937 }
938
939 static inline LPWSTR strdupAtoW( LPCSTR str )
940 {
941     LPWSTR ret = NULL;
942     DWORD len;
943
944     if (!str) return ret;
945     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
946     ret = msi_alloc( len * sizeof(WCHAR) );
947     if (ret)
948         MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
949     return ret;
950 }
951
952 static inline LPWSTR strdupW( LPCWSTR src )
953 {
954     LPWSTR dest;
955     if (!src) return NULL;
956     dest = msi_alloc( (lstrlenW(src)+1)*sizeof(WCHAR) );
957     if (dest)
958         lstrcpyW(dest, src);
959     return dest;
960 }
961
962 #endif /* __WINE_MSI_PRIVATE__ */