gdiplus: Convert formats that can't be drawn by gdi32 when drawing bitmaps.
[wine.git] / dlls / msi / events.c
blobe8f22975594954f8aa18c35e528704f55e304f22
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "winreg.h"
28 #include "msi.h"
29 #include "msipriv.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msi);
36 typedef UINT (*EVENTHANDLER)(MSIPACKAGE*,LPCWSTR,msi_dialog *);
38 struct _events {
39 LPCSTR event;
40 EVENTHANDLER handler;
43 struct subscriber {
44 struct list entry;
45 msi_dialog *dialog;
46 LPWSTR event;
47 LPWSTR control;
48 LPWSTR attribute;
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 )
58 msi_dialog *dialog;
59 UINT r;
61 /* create a new dialog */
62 dialog = msi_dialog_create( package, name, parent,
63 ControlEvent_HandleControlEvent );
64 if( dialog )
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 );
77 else
78 package->dialog = dialog;
80 else
81 r = ERROR_FUNCTION_FAILED;
83 return r;
88 * End a modal dialog box
90 static UINT ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
91 msi_dialog* dialog)
93 static const WCHAR szExit[] = {
94 'E','x','i','t',0};
95 static const WCHAR szRetry[] = {
96 'R','e','t','r','y',0};
97 static const WCHAR szIgnore[] = {
98 'I','g','n','o','r','e',0};
99 static const WCHAR szReturn[] = {
100 'R','e','t','u','r','n',0};
102 if (lstrcmpW(argument,szExit)==0)
103 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
104 else if (lstrcmpW(argument, szRetry) == 0)
105 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
106 else if (lstrcmpW(argument, szIgnore) == 0)
107 package->CurrentInstallState = ERROR_SUCCESS;
108 else if (lstrcmpW(argument, szReturn) == 0)
110 msi_dialog *parent = msi_dialog_get_parent(dialog);
111 msi_free(package->next_dialog);
112 package->next_dialog = (parent) ? strdupW(msi_dialog_get_name(parent)) : NULL;
113 package->CurrentInstallState = ERROR_SUCCESS;
115 else
117 ERR("Unknown argument string %s\n",debugstr_w(argument));
118 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
121 ControlEvent_CleanupDialogSubscriptions(package, msi_dialog_get_name( dialog ));
122 msi_dialog_end_dialog( dialog );
123 return ERROR_SUCCESS;
127 * transition from one modal dialog to another modal dialog
129 static UINT ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
130 msi_dialog *dialog)
132 /* store the name of the next dialog, and signal this one to end */
133 package->next_dialog = strdupW(argument);
134 ControlEvent_CleanupSubscriptions(package);
135 msi_dialog_end_dialog( dialog );
136 return ERROR_SUCCESS;
140 * Create a new child dialog of an existing modal dialog
142 static UINT ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
143 msi_dialog *dialog)
145 /* don't destroy a modeless dialogs that might be our parent */
146 event_do_dialog( package, argument, dialog, FALSE );
147 if( package->CurrentInstallState != ERROR_SUCCESS )
148 msi_dialog_end_dialog( dialog );
149 return ERROR_SUCCESS;
153 * Creates a dialog that remains up for a period of time
154 * based on a condition
156 static UINT ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
157 msi_dialog* dialog)
159 FIXME("Doing Nothing\n");
160 return ERROR_SUCCESS;
163 static UINT ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
164 msi_dialog* dialog)
166 ACTION_PerformAction(package,argument,-1,TRUE);
167 return ERROR_SUCCESS;
170 static UINT ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
171 msi_dialog* dialog)
173 MSIFEATURE *feature = NULL;
175 if (lstrcmpW(szAll,argument))
177 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
179 else
181 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
182 msi_feature_set_state(package, feature, INSTALLSTATE_LOCAL);
184 ACTION_UpdateComponentStates(package,argument);
186 return ERROR_SUCCESS;
189 static UINT ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
190 msi_dialog* dialog)
192 MSIFEATURE *feature = NULL;
194 if (lstrcmpW(szAll,argument))
196 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
198 else
200 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
201 msi_feature_set_state(package, feature, INSTALLSTATE_ABSENT);
203 ACTION_UpdateComponentStates(package,argument);
205 return ERROR_SUCCESS;
208 static UINT ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
209 msi_dialog* dialog)
211 MSIFEATURE *feature = NULL;
213 if (lstrcmpW(szAll,argument))
215 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
217 else
219 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
220 msi_feature_set_state(package, feature, INSTALLSTATE_SOURCE);
221 ACTION_UpdateComponentStates(package,argument);
223 return ERROR_SUCCESS;
226 static UINT ControlEvent_SetTargetPath(MSIPACKAGE* package, LPCWSTR argument,
227 msi_dialog* dialog)
229 LPWSTR path = msi_dup_property( package, argument );
230 MSIRECORD *rec = MSI_CreateRecord( 1 );
231 UINT r;
233 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
235 MSI_RecordSetStringW( rec, 1, path );
236 ControlEvent_FireSubscribedEvent( package, szSelectionPath, rec );
238 /* failure to set the path halts the executing of control events */
239 r = MSI_SetTargetPathW(package, argument, path);
240 msi_free(path);
241 msi_free(&rec->hdr);
242 return r;
245 static UINT ControlEvent_Reset(MSIPACKAGE* package, LPCWSTR argument,
246 msi_dialog* dialog)
248 msi_dialog_reset(dialog);
249 return ERROR_SUCCESS;
253 * Subscribed events
255 static void free_subscriber( struct subscriber *sub )
257 msi_free(sub->event);
258 msi_free(sub->control);
259 msi_free(sub->attribute);
260 msi_free(sub);
263 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, msi_dialog *dialog,
264 LPCWSTR event, LPCWSTR control, LPCWSTR attribute )
266 struct subscriber *sub;
268 sub = msi_alloc(sizeof (*sub));
269 if( !sub )
270 return;
271 sub->dialog = dialog;
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_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event,
279 MSIRECORD *rec )
281 struct subscriber *sub;
283 TRACE("Firing Event %s\n",debugstr_w(event));
285 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
287 if (lstrcmpiW(sub->event, event))
288 continue;
289 msi_dialog_handle_event( sub->dialog, sub->control,
290 sub->attribute, rec );
294 VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog)
296 struct list *i, *t;
297 struct subscriber *sub;
299 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
301 sub = LIST_ENTRY( i, struct subscriber, entry );
303 if ( lstrcmpW( msi_dialog_get_name( sub->dialog ), dialog ))
304 continue;
306 list_remove( &sub->entry );
307 free_subscriber( sub );
311 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
313 struct list *i, *t;
314 struct subscriber *sub;
316 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
318 sub = LIST_ENTRY( i, struct subscriber, entry );
320 list_remove( &sub->entry );
321 free_subscriber( sub );
326 * ACTION_DialogBox()
328 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
329 * if the given parameter is not a dialog box
331 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
333 UINT r = ERROR_SUCCESS;
335 if( package->next_dialog )
336 ERR("Already a next dialog... ignoring it\n");
337 package->next_dialog = NULL;
340 * Dialogs are chained by filling in the next_dialog member
341 * of the package structure, then terminating the current dialog.
342 * The code below sees the next_dialog member set, and runs the
343 * next dialog.
344 * We fall out of the loop below if we come across a modeless
345 * dialog, as it returns ERROR_IO_PENDING when we try to run
346 * its message loop.
348 r = event_do_dialog( package, szDialogName, NULL, TRUE );
349 while( r == ERROR_SUCCESS && package->next_dialog )
351 LPWSTR name = package->next_dialog;
353 package->next_dialog = NULL;
354 r = event_do_dialog( package, name, NULL, TRUE );
355 msi_free( name );
358 if( r == ERROR_IO_PENDING )
359 r = ERROR_SUCCESS;
361 return r;
364 static UINT ControlEvent_SetInstallLevel(MSIPACKAGE* package, LPCWSTR argument,
365 msi_dialog* dialog)
367 int iInstallLevel = atolW(argument);
369 TRACE("Setting install level: %i\n", iInstallLevel);
371 return MSI_SetInstallLevel( package, iInstallLevel );
374 static UINT ControlEvent_DirectoryListUp(MSIPACKAGE *package, LPCWSTR argument,
375 msi_dialog *dialog)
377 return msi_dialog_directorylist_up( dialog );
380 static UINT ControlEvent_ReinstallMode(MSIPACKAGE *package, LPCWSTR argument,
381 msi_dialog *dialog)
383 return MSI_SetPropertyW( package, szReinstallMode, argument );
386 static UINT ControlEvent_ValidateProductID(MSIPACKAGE *package, LPCWSTR argument,
387 msi_dialog *dialog)
389 LPWSTR key, template;
390 UINT ret = ERROR_SUCCESS;
392 template = msi_dup_property( package, szPIDTemplate );
393 key = msi_dup_property( package, szPIDKEY );
395 if (key && template)
397 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key) );
398 ret = MSI_SetPropertyW( package, szProductID, key );
400 msi_free( template );
401 msi_free( key );
402 return ret;
405 static const struct _events Events[] = {
406 { "EndDialog",ControlEvent_EndDialog },
407 { "NewDialog",ControlEvent_NewDialog },
408 { "SpawnDialog",ControlEvent_SpawnDialog },
409 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
410 { "DoAction",ControlEvent_DoAction },
411 { "AddLocal",ControlEvent_AddLocal },
412 { "Remove",ControlEvent_Remove },
413 { "AddSource",ControlEvent_AddSource },
414 { "SetTargetPath",ControlEvent_SetTargetPath },
415 { "Reset",ControlEvent_Reset },
416 { "SetInstallLevel",ControlEvent_SetInstallLevel },
417 { "DirectoryListUp",ControlEvent_DirectoryListUp },
418 { "SelectionBrowse",ControlEvent_SpawnDialog },
419 { "ReinstallMode",ControlEvent_ReinstallMode },
420 { "ValidateProductID",ControlEvent_ValidateProductID },
421 { NULL,NULL },
424 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
425 LPCWSTR argument, msi_dialog* dialog)
427 int i = 0;
428 UINT rc = ERROR_SUCCESS;
430 TRACE("Handling Control Event %s\n",debugstr_w(event));
431 if (!event)
432 return rc;
434 while( Events[i].event != NULL)
436 LPWSTR wevent = strdupAtoW(Events[i].event);
437 if (lstrcmpW(wevent,event)==0)
439 msi_free(wevent);
440 rc = Events[i].handler(package,argument,dialog);
441 return rc;
443 msi_free(wevent);
444 i++;
446 FIXME("unhandled control event %s arg(%s)\n",
447 debugstr_w(event), debugstr_w(argument));
448 return rc;