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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/controlevent_overview.asp
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi);
41 typedef UINT (*EVENTHANDLER)(MSIPACKAGE*,LPCWSTR,msi_dialog *);
55 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
58 * Create a dialog box and run it if it's modal
60 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name )
65 /* kill the current modeless dialog */
67 msi_dialog_destroy( package->dialog );
68 package->dialog = NULL;
70 /* create a new dialog */
71 dialog = msi_dialog_create( package, name,
72 ControlEvent_HandleControlEvent );
75 /* modeless dialogs return an error message */
76 r = msi_dialog_run_message_loop( dialog );
77 if( r == ERROR_SUCCESS )
78 msi_dialog_destroy( dialog );
80 package->dialog = dialog;
83 r = ERROR_FUNCTION_FAILED;
90 * End a modal dialog box
92 static UINT ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
95 static const WCHAR szExit[] = {
97 static const WCHAR szRetry[] = {
98 'R','e','t','r','y',0};
99 static const WCHAR szIgnore[] = {
100 'I','g','n','o','r','e',0};
101 static const WCHAR szReturn[] = {
102 'R','e','t','u','r','n',0};
104 if (lstrcmpW(argument,szExit)==0)
105 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
106 else if (lstrcmpW(argument, szRetry) == 0)
107 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
108 else if (lstrcmpW(argument, szIgnore) == 0)
109 package->CurrentInstallState = -1;
110 else if (lstrcmpW(argument, szReturn) == 0)
111 package->CurrentInstallState = ERROR_SUCCESS;
114 ERR("Unknown argument string %s\n",debugstr_w(argument));
115 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
118 ControlEvent_CleanupSubscriptions(package);
119 msi_dialog_end_dialog( dialog );
120 return ERROR_SUCCESS;
124 * transition from one modal dialog to another modal dialog
126 static UINT ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
129 /* store the name of the next dialog, and signal this one to end */
130 package->next_dialog = strdupW(argument);
131 ControlEvent_CleanupSubscriptions(package);
132 msi_dialog_end_dialog( dialog );
133 return ERROR_SUCCESS;
137 * Create a new child dialog of an existing modal dialog
139 static UINT ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
142 event_do_dialog( package, argument );
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,TRUE);
163 return ERROR_SUCCESS;
166 static UINT ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
169 static const WCHAR szAll[] = {'A','L','L',0};
172 if (lstrcmpW(szAll,argument))
174 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
178 for (i = 0; i < package->loaded_features; i++)
180 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
181 package->features[i].Action = INSTALLSTATE_LOCAL;
183 ACTION_UpdateComponentStates(package,argument);
185 return ERROR_SUCCESS;
188 static UINT ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
191 static const WCHAR szAll[] = {'A','L','L',0};
194 if (lstrcmpW(szAll,argument))
196 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
200 for (i = 0; i < package->loaded_features; i++)
202 package->features[i].ActionRequest = INSTALLSTATE_ABSENT;
203 package->features[i].Action= INSTALLSTATE_ABSENT;
205 ACTION_UpdateComponentStates(package,argument);
207 return ERROR_SUCCESS;
210 static UINT ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
213 static const WCHAR szAll[] = {'A','L','L',0};
216 if (lstrcmpW(szAll,argument))
218 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
222 for (i = 0; i < package->loaded_features; i++)
224 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
225 package->features[i].Action = INSTALLSTATE_SOURCE;
227 ACTION_UpdateComponentStates(package,argument);
229 return ERROR_SUCCESS;
232 static UINT ControlEvent_SetTargetPath(MSIPACKAGE* package, LPCWSTR argument,
235 LPWSTR path = load_dynamic_property(package,argument, NULL);
236 /* failure to set the path halts the executing of control events */
237 return MSI_SetTargetPathW(package, argument, path);
243 static void free_subscriber( struct subscriber *sub )
245 HeapFree(GetProcessHeap(),0,sub->event);
246 HeapFree(GetProcessHeap(),0,sub->control);
247 HeapFree(GetProcessHeap(),0,sub->attribute);
248 HeapFree(GetProcessHeap(),0,sub);
251 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
252 LPCWSTR control, LPCWSTR attribute )
254 struct subscriber *sub;
256 sub = HeapAlloc(GetProcessHeap(),0,sizeof (*sub));
259 sub->event = strdupW(event);
260 sub->control = strdupW(control);
261 sub->attribute = strdupW(attribute);
262 list_add_tail( &package->subscriptions, &sub->entry );
265 VOID ControlEvent_UnSubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
266 LPCWSTR control, LPCWSTR attribute )
269 struct subscriber *sub;
271 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
273 sub = LIST_ENTRY( i, struct subscriber, entry );
275 if( lstrcmpiW(sub->control,control) )
277 if( lstrcmpiW(sub->attribute,attribute) )
279 if( lstrcmpiW(sub->event,event) )
281 list_remove( &sub->entry );
282 free_subscriber( sub );
286 VOID ControlEvent_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event,
289 struct subscriber *sub;
291 TRACE("Firing Event %s\n",debugstr_w(event));
293 if (!package->dialog)
296 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
298 if (lstrcmpiW(sub->event, event))
300 msi_dialog_handle_event( package->dialog, sub->control,
301 sub->attribute, rec );
305 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
308 struct subscriber *sub;
310 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
312 sub = LIST_ENTRY( i, struct subscriber, entry );
314 list_remove( &sub->entry );
315 free_subscriber( sub );
322 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
323 * if the given parameter is not a dialog box
325 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
327 UINT r = ERROR_SUCCESS;
329 if( package->next_dialog )
330 ERR("Already a next dialog... ignoring it\n");
331 package->next_dialog = NULL;
334 * Dialogs are chained by filling in the next_dialog member
335 * of the package structure, then terminating the current dialog.
336 * The code below sees the next_dialog member set, and runs the
338 * We fall out of the loop below if we come across a modeless
339 * dialog, as it returns ERROR_IO_PENDING when we try to run
342 r = event_do_dialog( package, szDialogName );
343 while( r == ERROR_SUCCESS && package->next_dialog )
345 LPWSTR name = package->next_dialog;
347 package->next_dialog = NULL;
348 r = event_do_dialog( package, name );
349 HeapFree( GetProcessHeap(), 0, name );
352 if( r == ERROR_IO_PENDING )
358 struct _events Events[] = {
359 { "EndDialog",ControlEvent_EndDialog },
360 { "NewDialog",ControlEvent_NewDialog },
361 { "SpawnDialog",ControlEvent_SpawnDialog },
362 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
363 { "DoAction",ControlEvent_DoAction },
364 { "AddLocal",ControlEvent_AddLocal },
365 { "Remove",ControlEvent_Remove },
366 { "AddSource",ControlEvent_AddSource },
367 { "SetTargetPath",ControlEvent_SetTargetPath },
371 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
372 LPCWSTR argument, msi_dialog* dialog)
375 UINT rc = ERROR_SUCCESS;
377 TRACE("Handling Control Event %s\n",debugstr_w(event));
381 while( Events[i].event != NULL)
383 LPWSTR wevent = strdupAtoW(Events[i].event);
384 if (lstrcmpW(wevent,event)==0)
386 HeapFree(GetProcessHeap(),0,wevent);
387 rc = Events[i].handler(package,argument,dialog);
390 HeapFree(GetProcessHeap(),0,wevent);
393 FIXME("unhandled control event %s arg(%s)\n",
394 debugstr_w(event), debugstr_w(argument));