2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart 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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
36 typedef UINT (*EVENTHANDLER
)(MSIPACKAGE
*,LPCWSTR
,msi_dialog
*);
51 static UINT
ControlEvent_HandleControlEvent(MSIPACKAGE
*, LPCWSTR
, LPCWSTR
, msi_dialog
*);
54 * Create a dialog box and run it if it's modal
56 static UINT
event_do_dialog( MSIPACKAGE
*package
, LPCWSTR name
, msi_dialog
*parent
, BOOL destroy_modeless
)
61 /* create a new dialog */
62 dialog
= msi_dialog_create( package
, name
, parent
,
63 ControlEvent_HandleControlEvent
);
66 /* kill the current modeless dialog */
67 if( destroy_modeless
&& package
->dialog
)
69 msi_dialog_destroy( package
->dialog
);
70 package
->dialog
= NULL
;
73 /* modeless dialogs return an error message */
74 r
= msi_dialog_run_message_loop( dialog
);
75 if( r
== ERROR_SUCCESS
)
76 msi_dialog_destroy( dialog
);
78 package
->dialog
= dialog
;
81 r
= ERROR_FUNCTION_FAILED
;
88 * End a modal dialog box
90 static UINT
ControlEvent_EndDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
93 static const WCHAR szExit
[] = {'E','x','i','t',0};
94 static const WCHAR szRetry
[] = {'R','e','t','r','y',0};
95 static const WCHAR szIgnore
[] = {'I','g','n','o','r','e',0};
96 static const WCHAR szReturn
[] = {'R','e','t','u','r','n',0};
98 if (!strcmpW( argument
, szExit
))
99 package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
100 else if (!strcmpW( argument
, szRetry
))
101 package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
102 else if (!strcmpW( argument
, szIgnore
))
103 package
->CurrentInstallState
= ERROR_SUCCESS
;
104 else if (!strcmpW( argument
, szReturn
))
106 msi_dialog
*parent
= msi_dialog_get_parent(dialog
);
107 msi_free(package
->next_dialog
);
108 package
->next_dialog
= (parent
) ? strdupW(msi_dialog_get_name(parent
)) : NULL
;
109 package
->CurrentInstallState
= ERROR_SUCCESS
;
113 ERR("Unknown argument string %s\n",debugstr_w(argument
));
114 package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
117 ControlEvent_CleanupDialogSubscriptions(package
, msi_dialog_get_name( dialog
));
118 msi_dialog_end_dialog( dialog
);
119 return ERROR_SUCCESS
;
123 * transition from one modal dialog to another modal dialog
125 static UINT
ControlEvent_NewDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
128 /* store the name of the next dialog, and signal this one to end */
129 package
->next_dialog
= strdupW(argument
);
130 ControlEvent_CleanupSubscriptions(package
);
131 msi_dialog_end_dialog( dialog
);
132 return ERROR_SUCCESS
;
136 * Create a new child dialog of an existing modal dialog
138 static UINT
ControlEvent_SpawnDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
141 /* don't destroy a modeless dialogs that might be our parent */
142 event_do_dialog( package
, argument
, dialog
, FALSE
);
143 if( package
->CurrentInstallState
!= ERROR_SUCCESS
)
144 msi_dialog_end_dialog( dialog
);
145 return ERROR_SUCCESS
;
149 * Creates a dialog that remains up for a period of time
150 * based on a condition
152 static UINT
ControlEvent_SpawnWaitDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
155 FIXME("Doing Nothing\n");
156 return ERROR_SUCCESS
;
159 static UINT
ControlEvent_DoAction(MSIPACKAGE
* package
, LPCWSTR argument
,
162 ACTION_PerformAction(package
, argument
, -1);
163 return ERROR_SUCCESS
;
166 static UINT
ControlEvent_AddLocal( MSIPACKAGE
*package
, LPCWSTR argument
, msi_dialog
*dialog
)
170 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
172 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
174 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
175 msi_set_property( package
->db
, szPreselected
, szOne
);
176 MSI_SetFeatureStateW( package
, feature
->Feature
, INSTALLSTATE_LOCAL
);
179 return ERROR_SUCCESS
;
182 static UINT
ControlEvent_Remove( MSIPACKAGE
*package
, LPCWSTR argument
, msi_dialog
*dialog
)
186 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
188 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
190 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
191 msi_set_property( package
->db
, szPreselected
, szOne
);
192 MSI_SetFeatureStateW( package
, feature
->Feature
, INSTALLSTATE_ABSENT
);
195 return ERROR_SUCCESS
;
198 static UINT
ControlEvent_AddSource( MSIPACKAGE
*package
, LPCWSTR argument
, msi_dialog
*dialog
)
202 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
204 if (!strcmpW( argument
, feature
->Feature
) || !strcmpW( argument
, szAll
))
206 if (feature
->ActionRequest
!= INSTALLSTATE_SOURCE
)
207 msi_set_property( package
->db
, szPreselected
, szOne
);
208 MSI_SetFeatureStateW( package
, feature
->Feature
, INSTALLSTATE_SOURCE
);
211 return ERROR_SUCCESS
;
214 static UINT
ControlEvent_SetTargetPath(MSIPACKAGE
* package
, LPCWSTR argument
,
217 LPWSTR path
= msi_dup_property( package
->db
, argument
);
218 MSIRECORD
*rec
= MSI_CreateRecord( 1 );
221 static const WCHAR szSelectionPath
[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
223 MSI_RecordSetStringW( rec
, 1, path
);
224 ControlEvent_FireSubscribedEvent( package
, szSelectionPath
, rec
);
226 /* failure to set the path halts the executing of control events */
227 r
= MSI_SetTargetPathW(package
, argument
, path
);
233 static UINT
ControlEvent_Reset(MSIPACKAGE
* package
, LPCWSTR argument
,
236 msi_dialog_reset(dialog
);
237 return ERROR_SUCCESS
;
243 static void free_subscriber( struct subscriber
*sub
)
245 msi_free(sub
->event
);
246 msi_free(sub
->control
);
247 msi_free(sub
->attribute
);
251 VOID
ControlEvent_SubscribeToEvent( MSIPACKAGE
*package
, msi_dialog
*dialog
,
252 LPCWSTR event
, LPCWSTR control
, LPCWSTR attribute
)
254 struct subscriber
*sub
;
256 sub
= msi_alloc(sizeof (*sub
));
259 sub
->dialog
= dialog
;
260 sub
->event
= strdupW(event
);
261 sub
->control
= strdupW(control
);
262 sub
->attribute
= strdupW(attribute
);
263 list_add_tail( &package
->subscriptions
, &sub
->entry
);
266 VOID
ControlEvent_FireSubscribedEvent( MSIPACKAGE
*package
, LPCWSTR event
,
269 struct subscriber
*sub
;
271 TRACE("Firing Event %s\n",debugstr_w(event
));
273 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
275 if (strcmpiW( sub
->event
, event
))
277 msi_dialog_handle_event( sub
->dialog
, sub
->control
, sub
->attribute
, rec
);
281 VOID
ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE
*package
, LPWSTR dialog
)
284 struct subscriber
*sub
;
286 LIST_FOR_EACH_SAFE( i
, t
, &package
->subscriptions
)
288 sub
= LIST_ENTRY( i
, struct subscriber
, entry
);
290 if (strcmpW( msi_dialog_get_name( sub
->dialog
), dialog
))
293 list_remove( &sub
->entry
);
294 free_subscriber( sub
);
298 VOID
ControlEvent_CleanupSubscriptions(MSIPACKAGE
*package
)
301 struct subscriber
*sub
;
303 LIST_FOR_EACH_SAFE( i
, t
, &package
->subscriptions
)
305 sub
= LIST_ENTRY( i
, struct subscriber
, entry
);
307 list_remove( &sub
->entry
);
308 free_subscriber( sub
);
315 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
316 * if the given parameter is not a dialog box
318 UINT
ACTION_DialogBox( MSIPACKAGE
* package
, LPCWSTR szDialogName
)
320 UINT r
= ERROR_SUCCESS
;
322 if( package
->next_dialog
)
323 ERR("Already a next dialog... ignoring it\n");
324 package
->next_dialog
= NULL
;
327 * Dialogs are chained by filling in the next_dialog member
328 * of the package structure, then terminating the current dialog.
329 * The code below sees the next_dialog member set, and runs the
331 * We fall out of the loop below if we come across a modeless
332 * dialog, as it returns ERROR_IO_PENDING when we try to run
335 r
= event_do_dialog( package
, szDialogName
, NULL
, TRUE
);
336 while( r
== ERROR_SUCCESS
&& package
->next_dialog
)
338 LPWSTR name
= package
->next_dialog
;
340 package
->next_dialog
= NULL
;
341 r
= event_do_dialog( package
, name
, NULL
, TRUE
);
345 if( r
== ERROR_IO_PENDING
)
351 static UINT
ControlEvent_SetInstallLevel(MSIPACKAGE
* package
, LPCWSTR argument
,
354 int iInstallLevel
= atolW(argument
);
356 TRACE("Setting install level: %i\n", iInstallLevel
);
358 return MSI_SetInstallLevel( package
, iInstallLevel
);
361 static UINT
ControlEvent_DirectoryListUp(MSIPACKAGE
*package
, LPCWSTR argument
,
364 return msi_dialog_directorylist_up( dialog
);
367 static UINT
ControlEvent_ReinstallMode(MSIPACKAGE
*package
, LPCWSTR argument
,
370 return msi_set_property( package
->db
, szReinstallMode
, argument
);
373 static UINT
ControlEvent_Reinstall( MSIPACKAGE
*package
, LPCWSTR argument
,
376 return msi_set_property( package
->db
, szReinstall
, argument
);
379 static UINT
ControlEvent_ValidateProductID(MSIPACKAGE
*package
, LPCWSTR argument
,
382 LPWSTR key
, template;
383 UINT ret
= ERROR_SUCCESS
;
385 template = msi_dup_property( package
->db
, szPIDTemplate
);
386 key
= msi_dup_property( package
->db
, szPIDKEY
);
390 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
391 ret
= msi_set_property( package
->db
, szProductID
, key
);
393 msi_free( template );
398 static const struct _events Events
[] = {
399 { "EndDialog",ControlEvent_EndDialog
},
400 { "NewDialog",ControlEvent_NewDialog
},
401 { "SpawnDialog",ControlEvent_SpawnDialog
},
402 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog
},
403 { "DoAction",ControlEvent_DoAction
},
404 { "AddLocal",ControlEvent_AddLocal
},
405 { "Remove",ControlEvent_Remove
},
406 { "AddSource",ControlEvent_AddSource
},
407 { "SetTargetPath",ControlEvent_SetTargetPath
},
408 { "Reset",ControlEvent_Reset
},
409 { "SetInstallLevel",ControlEvent_SetInstallLevel
},
410 { "DirectoryListUp",ControlEvent_DirectoryListUp
},
411 { "SelectionBrowse",ControlEvent_SpawnDialog
},
412 { "ReinstallMode",ControlEvent_ReinstallMode
},
413 { "Reinstall",ControlEvent_Reinstall
},
414 { "ValidateProductID",ControlEvent_ValidateProductID
},
418 UINT
ControlEvent_HandleControlEvent(MSIPACKAGE
*package
, LPCWSTR event
,
419 LPCWSTR argument
, msi_dialog
* dialog
)
422 UINT rc
= ERROR_SUCCESS
;
424 TRACE("Handling Control Event %s\n",debugstr_w(event
));
428 while( Events
[i
].event
!= NULL
)
430 LPWSTR wevent
= strdupAtoW(Events
[i
].event
);
431 if (!strcmpW( wevent
, event
))
434 rc
= Events
[i
].handler(package
,argument
,dialog
);
440 FIXME("unhandled control event %s arg(%s)\n",
441 debugstr_w(event
), debugstr_w(argument
));