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
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
, BOOL destroy_modeless
)
65 /* create a new dialog */
66 dialog
= msi_dialog_create( package
, name
,
67 ControlEvent_HandleControlEvent
);
70 /* kill the current modeless dialog */
71 if( destroy_modeless
&& package
->dialog
)
73 msi_dialog_destroy( package
->dialog
);
74 package
->dialog
= NULL
;
77 /* modeless dialogs return an error message */
78 r
= msi_dialog_run_message_loop( dialog
);
79 if( r
== ERROR_SUCCESS
)
80 msi_dialog_destroy( dialog
);
82 package
->dialog
= dialog
;
85 r
= ERROR_FUNCTION_FAILED
;
92 * End a modal dialog box
94 static UINT
ControlEvent_EndDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
97 static const WCHAR szExit
[] = {
99 static const WCHAR szRetry
[] = {
100 'R','e','t','r','y',0};
101 static const WCHAR szIgnore
[] = {
102 'I','g','n','o','r','e',0};
103 static const WCHAR szReturn
[] = {
104 'R','e','t','u','r','n',0};
106 if (lstrcmpW(argument
,szExit
)==0)
107 package
->CurrentInstallState
= ERROR_INSTALL_USEREXIT
;
108 else if (lstrcmpW(argument
, szRetry
) == 0)
109 package
->CurrentInstallState
= ERROR_INSTALL_SUSPEND
;
110 else if (lstrcmpW(argument
, szIgnore
) == 0)
111 package
->CurrentInstallState
= -1;
112 else if (lstrcmpW(argument
, szReturn
) == 0)
113 package
->CurrentInstallState
= ERROR_SUCCESS
;
116 ERR("Unknown argument string %s\n",debugstr_w(argument
));
117 package
->CurrentInstallState
= ERROR_FUNCTION_FAILED
;
120 ControlEvent_CleanupSubscriptions(package
);
121 msi_dialog_end_dialog( dialog
);
122 return ERROR_SUCCESS
;
126 * transition from one modal dialog to another modal dialog
128 static UINT
ControlEvent_NewDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
131 /* store the name of the next dialog, and signal this one to end */
132 package
->next_dialog
= strdupW(argument
);
133 ControlEvent_CleanupSubscriptions(package
);
134 msi_dialog_end_dialog( dialog
);
135 return ERROR_SUCCESS
;
139 * Create a new child dialog of an existing modal dialog
141 static UINT
ControlEvent_SpawnDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
144 /* don't destroy a modeless dialogs that might be our parent */
145 event_do_dialog( package
, argument
, FALSE
);
146 if( package
->CurrentInstallState
!= ERROR_SUCCESS
)
147 msi_dialog_end_dialog( dialog
);
148 return ERROR_SUCCESS
;
152 * Creates a dialog that remains up for a period of time
153 * based on a condition
155 static UINT
ControlEvent_SpawnWaitDialog(MSIPACKAGE
* package
, LPCWSTR argument
,
158 FIXME("Doing Nothing\n");
159 return ERROR_SUCCESS
;
162 static UINT
ControlEvent_DoAction(MSIPACKAGE
* package
, LPCWSTR argument
,
165 ACTION_PerformAction(package
,argument
,TRUE
);
166 return ERROR_SUCCESS
;
169 static UINT
ControlEvent_AddLocal(MSIPACKAGE
* package
, LPCWSTR argument
,
172 static const WCHAR szAll
[] = {'A','L','L',0};
173 MSIFEATURE
*feature
= NULL
;
175 if (lstrcmpW(szAll
,argument
))
177 MSI_SetFeatureStateW(package
,argument
,INSTALLSTATE_LOCAL
);
181 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
183 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
184 feature
->Action
= INSTALLSTATE_LOCAL
;
186 ACTION_UpdateComponentStates(package
,argument
);
188 return ERROR_SUCCESS
;
191 static UINT
ControlEvent_Remove(MSIPACKAGE
* package
, LPCWSTR argument
,
194 static const WCHAR szAll
[] = {'A','L','L',0};
195 MSIFEATURE
*feature
= NULL
;
197 if (lstrcmpW(szAll
,argument
))
199 MSI_SetFeatureStateW(package
,argument
,INSTALLSTATE_ABSENT
);
203 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
205 feature
->ActionRequest
= INSTALLSTATE_ABSENT
;
206 feature
->Action
= INSTALLSTATE_ABSENT
;
208 ACTION_UpdateComponentStates(package
,argument
);
210 return ERROR_SUCCESS
;
213 static UINT
ControlEvent_AddSource(MSIPACKAGE
* package
, LPCWSTR argument
,
216 static const WCHAR szAll
[] = {'A','L','L',0};
217 MSIFEATURE
*feature
= NULL
;
219 if (lstrcmpW(szAll
,argument
))
221 MSI_SetFeatureStateW(package
,argument
,INSTALLSTATE_SOURCE
);
225 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
227 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
228 feature
->Action
= INSTALLSTATE_SOURCE
;
230 ACTION_UpdateComponentStates(package
,argument
);
232 return ERROR_SUCCESS
;
235 static UINT
ControlEvent_SetTargetPath(MSIPACKAGE
* package
, LPCWSTR argument
,
238 LPWSTR path
= msi_dup_property( package
, argument
);
240 /* failure to set the path halts the executing of control events */
241 r
= MSI_SetTargetPathW(package
, argument
, path
);
246 static UINT
ControlEvent_Reset(MSIPACKAGE
* package
, LPCWSTR argument
,
249 msi_dialog_reset(dialog
);
250 return ERROR_SUCCESS
;
256 static void free_subscriber( struct subscriber
*sub
)
258 msi_free(sub
->event
);
259 msi_free(sub
->control
);
260 msi_free(sub
->attribute
);
264 VOID
ControlEvent_SubscribeToEvent( MSIPACKAGE
*package
, LPCWSTR event
,
265 LPCWSTR control
, LPCWSTR attribute
)
267 struct subscriber
*sub
;
269 sub
= msi_alloc(sizeof (*sub
));
272 sub
->event
= strdupW(event
);
273 sub
->control
= strdupW(control
);
274 sub
->attribute
= strdupW(attribute
);
275 list_add_tail( &package
->subscriptions
, &sub
->entry
);
278 VOID
ControlEvent_UnSubscribeToEvent( MSIPACKAGE
*package
, LPCWSTR event
,
279 LPCWSTR control
, LPCWSTR attribute
)
282 struct subscriber
*sub
;
284 LIST_FOR_EACH_SAFE( i
, t
, &package
->subscriptions
)
286 sub
= LIST_ENTRY( i
, struct subscriber
, entry
);
288 if( lstrcmpiW(sub
->control
,control
) )
290 if( lstrcmpiW(sub
->attribute
,attribute
) )
292 if( lstrcmpiW(sub
->event
,event
) )
294 list_remove( &sub
->entry
);
295 free_subscriber( sub
);
299 VOID
ControlEvent_FireSubscribedEvent( MSIPACKAGE
*package
, LPCWSTR event
,
302 struct subscriber
*sub
;
304 TRACE("Firing Event %s\n",debugstr_w(event
));
306 if (!package
->dialog
)
309 LIST_FOR_EACH_ENTRY( sub
, &package
->subscriptions
, struct subscriber
, entry
)
311 if (lstrcmpiW(sub
->event
, event
))
313 msi_dialog_handle_event( package
->dialog
, sub
->control
,
314 sub
->attribute
, rec
);
318 VOID
ControlEvent_CleanupSubscriptions(MSIPACKAGE
*package
)
321 struct subscriber
*sub
;
323 LIST_FOR_EACH_SAFE( i
, t
, &package
->subscriptions
)
325 sub
= LIST_ENTRY( i
, struct subscriber
, entry
);
327 list_remove( &sub
->entry
);
328 free_subscriber( sub
);
335 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
336 * if the given parameter is not a dialog box
338 UINT
ACTION_DialogBox( MSIPACKAGE
* package
, LPCWSTR szDialogName
)
340 UINT r
= ERROR_SUCCESS
;
342 if( package
->next_dialog
)
343 ERR("Already a next dialog... ignoring it\n");
344 package
->next_dialog
= NULL
;
347 * Dialogs are chained by filling in the next_dialog member
348 * of the package structure, then terminating the current dialog.
349 * The code below sees the next_dialog member set, and runs the
351 * We fall out of the loop below if we come across a modeless
352 * dialog, as it returns ERROR_IO_PENDING when we try to run
355 r
= event_do_dialog( package
, szDialogName
, TRUE
);
356 while( r
== ERROR_SUCCESS
&& package
->next_dialog
)
358 LPWSTR name
= package
->next_dialog
;
360 package
->next_dialog
= NULL
;
361 r
= event_do_dialog( package
, name
, TRUE
);
365 if( r
== ERROR_IO_PENDING
)
371 struct _events Events
[] = {
372 { "EndDialog",ControlEvent_EndDialog
},
373 { "NewDialog",ControlEvent_NewDialog
},
374 { "SpawnDialog",ControlEvent_SpawnDialog
},
375 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog
},
376 { "DoAction",ControlEvent_DoAction
},
377 { "AddLocal",ControlEvent_AddLocal
},
378 { "Remove",ControlEvent_Remove
},
379 { "AddSource",ControlEvent_AddSource
},
380 { "SetTargetPath",ControlEvent_SetTargetPath
},
381 { "Reset",ControlEvent_Reset
},
385 UINT
ControlEvent_HandleControlEvent(MSIPACKAGE
*package
, LPCWSTR event
,
386 LPCWSTR argument
, msi_dialog
* dialog
)
389 UINT rc
= ERROR_SUCCESS
;
391 TRACE("Handling Control Event %s\n",debugstr_w(event
));
395 while( Events
[i
].event
!= NULL
)
397 LPWSTR wevent
= strdupAtoW(Events
[i
].event
);
398 if (lstrcmpW(wevent
,event
)==0)
401 rc
= Events
[i
].handler(package
,argument
,dialog
);
407 FIXME("unhandled control event %s arg(%s)\n",
408 debugstr_w(event
), debugstr_w(argument
));