wined3d: Handle projected+bump mapped textures in atifs.
[wine.git] / dlls / setupapi / install.c
blob321d4d4196ccefc5d950d53ed13c0fbca6139faa
1 /*
2 * Setupapi install routines
4 * Copyright 2002 Alexandre Julliard 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>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "winternl.h"
27 #include "winerror.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "winsvc.h"
32 #include "setupapi.h"
33 #include "setupapi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
39 /* info passed to callback functions dealing with files */
40 struct files_callback_info
42 HSPFILEQ queue;
43 PCWSTR src_root;
44 UINT copy_flags;
45 HINF layout;
48 /* info passed to callback functions dealing with the registry */
49 struct registry_callback_info
51 HKEY default_root;
52 BOOL delete;
55 /* info passed to callback functions dealing with registering dlls */
56 struct register_dll_info
58 PSP_FILE_CALLBACK_W callback;
59 PVOID callback_context;
60 BOOL unregister;
63 typedef BOOL (*iterate_fields_func)( HINF hinf, PCWSTR field, void *arg );
65 /* Unicode constants */
66 static const WCHAR CopyFiles[] = {'C','o','p','y','F','i','l','e','s',0};
67 static const WCHAR DelFiles[] = {'D','e','l','F','i','l','e','s',0};
68 static const WCHAR RenFiles[] = {'R','e','n','F','i','l','e','s',0};
69 static const WCHAR Ini2Reg[] = {'I','n','i','2','R','e','g',0};
70 static const WCHAR LogConf[] = {'L','o','g','C','o','n','f',0};
71 static const WCHAR AddReg[] = {'A','d','d','R','e','g',0};
72 static const WCHAR DelReg[] = {'D','e','l','R','e','g',0};
73 static const WCHAR BitReg[] = {'B','i','t','R','e','g',0};
74 static const WCHAR UpdateInis[] = {'U','p','d','a','t','e','I','n','i','s',0};
75 static const WCHAR CopyINF[] = {'C','o','p','y','I','N','F',0};
76 static const WCHAR AddService[] = {'A','d','d','S','e','r','v','i','c','e',0};
77 static const WCHAR DelService[] = {'D','e','l','S','e','r','v','i','c','e',0};
78 static const WCHAR UpdateIniFields[] = {'U','p','d','a','t','e','I','n','i','F','i','e','l','d','s',0};
79 static const WCHAR RegisterDlls[] = {'R','e','g','i','s','t','e','r','D','l','l','s',0};
80 static const WCHAR UnregisterDlls[] = {'U','n','r','e','g','i','s','t','e','r','D','l','l','s',0};
81 static const WCHAR ProfileItems[] = {'P','r','o','f','i','l','e','I','t','e','m','s',0};
82 static const WCHAR WineFakeDlls[] = {'W','i','n','e','F','a','k','e','D','l','l','s',0};
83 static const WCHAR DisplayName[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
84 static const WCHAR Description[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
85 static const WCHAR ServiceBinary[] = {'S','e','r','v','i','c','e','B','i','n','a','r','y',0};
86 static const WCHAR StartName[] = {'S','t','a','r','t','N','a','m','e',0};
87 static const WCHAR LoadOrderGroup[] = {'L','o','a','d','O','r','d','e','r','G','r','o','u','p',0};
88 static const WCHAR ServiceType[] = {'S','e','r','v','i','c','e','T','y','p','e',0};
89 static const WCHAR StartType[] = {'S','t','a','r','t','T','y','p','e',0};
90 static const WCHAR ErrorControl[] = {'E','r','r','o','r','C','o','n','t','r','o','l',0};
92 static const WCHAR ServicesKey[] = {'S','y','s','t','e','m','\\',
93 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
94 'S','e','r','v','i','c','e','s',0};
96 /***********************************************************************
97 * get_field_string
99 * Retrieve the contents of a field, dynamically growing the buffer if necessary.
101 static WCHAR *get_field_string( INFCONTEXT *context, DWORD index, WCHAR *buffer,
102 WCHAR *static_buffer, DWORD *size )
104 DWORD required;
106 if (SetupGetStringFieldW( context, index, buffer, *size, &required )) return buffer;
107 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
109 /* now grow the buffer */
110 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
111 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required*sizeof(WCHAR) ))) return NULL;
112 *size = required;
113 if (SetupGetStringFieldW( context, index, buffer, *size, &required )) return buffer;
115 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
116 return NULL;
120 /***********************************************************************
121 * dup_section_line_field
123 * Retrieve the contents of a field in a newly-allocated buffer.
125 static WCHAR *dup_section_line_field( HINF hinf, const WCHAR *section, const WCHAR *line, DWORD index )
127 INFCONTEXT context;
128 DWORD size;
129 WCHAR *buffer;
131 if (!SetupFindFirstLineW( hinf, section, line, &context )) return NULL;
132 if (!SetupGetStringFieldW( &context, index, NULL, 0, &size )) return NULL;
133 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return NULL;
134 if (!SetupGetStringFieldW( &context, index, buffer, size, NULL )) buffer[0] = 0;
135 return buffer;
138 /***********************************************************************
139 * copy_files_callback
141 * Called once for each CopyFiles entry in a given section.
143 static BOOL copy_files_callback( HINF hinf, PCWSTR field, void *arg )
145 struct files_callback_info *info = arg;
147 if (field[0] == '@') /* special case: copy single file */
148 SetupQueueDefaultCopyW( info->queue, info->layout ? info->layout : hinf, info->src_root, NULL, field+1, info->copy_flags );
149 else
150 SetupQueueCopySectionW( info->queue, info->src_root, info->layout ? info->layout : hinf, hinf, field, info->copy_flags );
151 return TRUE;
155 /***********************************************************************
156 * delete_files_callback
158 * Called once for each DelFiles entry in a given section.
160 static BOOL delete_files_callback( HINF hinf, PCWSTR field, void *arg )
162 struct files_callback_info *info = arg;
163 SetupQueueDeleteSectionW( info->queue, hinf, 0, field );
164 return TRUE;
168 /***********************************************************************
169 * rename_files_callback
171 * Called once for each RenFiles entry in a given section.
173 static BOOL rename_files_callback( HINF hinf, PCWSTR field, void *arg )
175 struct files_callback_info *info = arg;
176 SetupQueueRenameSectionW( info->queue, hinf, 0, field );
177 return TRUE;
181 /***********************************************************************
182 * get_root_key
184 * Retrieve the registry root key from its name.
186 static HKEY get_root_key( const WCHAR *name, HKEY def_root )
188 static const WCHAR HKCR[] = {'H','K','C','R',0};
189 static const WCHAR HKCU[] = {'H','K','C','U',0};
190 static const WCHAR HKLM[] = {'H','K','L','M',0};
191 static const WCHAR HKU[] = {'H','K','U',0};
192 static const WCHAR HKR[] = {'H','K','R',0};
194 if (!strcmpiW( name, HKCR )) return HKEY_CLASSES_ROOT;
195 if (!strcmpiW( name, HKCU )) return HKEY_CURRENT_USER;
196 if (!strcmpiW( name, HKLM )) return HKEY_LOCAL_MACHINE;
197 if (!strcmpiW( name, HKU )) return HKEY_USERS;
198 if (!strcmpiW( name, HKR )) return def_root;
199 return 0;
203 /***********************************************************************
204 * append_multi_sz_value
206 * Append a multisz string to a multisz registry value.
208 static void append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *strings,
209 DWORD str_size )
211 DWORD size, type, total;
212 WCHAR *buffer, *p;
214 if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
215 if (type != REG_MULTI_SZ) return;
217 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return;
218 if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
220 /* compare each string against all the existing ones */
221 total = size;
222 while (*strings)
224 int len = strlenW(strings) + 1;
226 for (p = buffer; *p; p += strlenW(p) + 1)
227 if (!strcmpiW( p, strings )) break;
229 if (!*p) /* not found, need to append it */
231 memcpy( p, strings, len * sizeof(WCHAR) );
232 p[len] = 0;
233 total += len;
235 strings += len;
237 if (total != size)
239 TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(buffer) );
240 RegSetValueExW( hkey, value, 0, REG_MULTI_SZ, (BYTE *)buffer, total );
242 done:
243 HeapFree( GetProcessHeap(), 0, buffer );
247 /***********************************************************************
248 * delete_multi_sz_value
250 * Remove a string from a multisz registry value.
252 static void delete_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *string )
254 DWORD size, type;
255 WCHAR *buffer, *src, *dst;
257 if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
258 if (type != REG_MULTI_SZ) return;
259 /* allocate double the size, one for value before and one for after */
260 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * 2 * sizeof(WCHAR) ))) return;
261 if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
262 src = buffer;
263 dst = buffer + size;
264 while (*src)
266 int len = strlenW(src) + 1;
267 if (strcmpiW( src, string ))
269 memcpy( dst, src, len * sizeof(WCHAR) );
270 dst += len;
272 src += len;
274 *dst++ = 0;
275 if (dst != buffer + 2*size) /* did we remove something? */
277 TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(buffer + size) );
278 RegSetValueExW( hkey, value, 0, REG_MULTI_SZ,
279 (BYTE *)(buffer + size), dst - (buffer + size) );
281 done:
282 HeapFree( GetProcessHeap(), 0, buffer );
286 /***********************************************************************
287 * do_reg_operation
289 * Perform an add/delete registry operation depending on the flags.
291 static BOOL do_reg_operation( HKEY hkey, const WCHAR *value, INFCONTEXT *context, INT flags )
293 DWORD type, size;
295 if (flags & (FLG_ADDREG_DELREG_BIT | FLG_ADDREG_DELVAL)) /* deletion */
297 if (*value && !(flags & FLG_DELREG_KEYONLY_COMMON))
299 if ((flags & FLG_DELREG_MULTI_SZ_DELSTRING) == FLG_DELREG_MULTI_SZ_DELSTRING)
301 WCHAR *str;
303 if (!SetupGetStringFieldW( context, 5, NULL, 0, &size ) || !size) return TRUE;
304 if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
305 SetupGetStringFieldW( context, 5, str, size, NULL );
306 delete_multi_sz_value( hkey, value, str );
307 HeapFree( GetProcessHeap(), 0, str );
309 else RegDeleteValueW( hkey, value );
311 else NtDeleteKey( hkey );
312 return TRUE;
315 if (flags & (FLG_ADDREG_KEYONLY|FLG_ADDREG_KEYONLY_COMMON)) return TRUE;
317 if (flags & (FLG_ADDREG_NOCLOBBER|FLG_ADDREG_OVERWRITEONLY))
319 BOOL exists = !RegQueryValueExW( hkey, value, NULL, NULL, NULL, NULL );
320 if (exists && (flags & FLG_ADDREG_NOCLOBBER)) return TRUE;
321 if (!exists && (flags & FLG_ADDREG_OVERWRITEONLY)) return TRUE;
324 switch(flags & FLG_ADDREG_TYPE_MASK)
326 case FLG_ADDREG_TYPE_SZ: type = REG_SZ; break;
327 case FLG_ADDREG_TYPE_MULTI_SZ: type = REG_MULTI_SZ; break;
328 case FLG_ADDREG_TYPE_EXPAND_SZ: type = REG_EXPAND_SZ; break;
329 case FLG_ADDREG_TYPE_BINARY: type = REG_BINARY; break;
330 case FLG_ADDREG_TYPE_DWORD: type = REG_DWORD; break;
331 case FLG_ADDREG_TYPE_NONE: type = REG_NONE; break;
332 default: type = flags >> 16; break;
335 if (!(flags & FLG_ADDREG_BINVALUETYPE) ||
336 (type == REG_DWORD && SetupGetFieldCount(context) == 5))
338 static const WCHAR empty;
339 WCHAR *str = NULL;
341 if (type == REG_MULTI_SZ)
343 if (!SetupGetMultiSzFieldW( context, 5, NULL, 0, &size )) size = 0;
344 if (size)
346 if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
347 SetupGetMultiSzFieldW( context, 5, str, size, NULL );
349 if (flags & FLG_ADDREG_APPEND)
351 if (!str) return TRUE;
352 append_multi_sz_value( hkey, value, str, size );
353 HeapFree( GetProcessHeap(), 0, str );
354 return TRUE;
356 /* else fall through to normal string handling */
358 else
360 if (!SetupGetStringFieldW( context, 5, NULL, 0, &size )) size = 0;
361 if (size)
363 if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
364 SetupGetStringFieldW( context, 5, str, size, NULL );
368 if (type == REG_DWORD)
370 DWORD dw = str ? strtoulW( str, NULL, 0 ) : 0;
371 TRACE( "setting dword %s to %x\n", debugstr_w(value), dw );
372 RegSetValueExW( hkey, value, 0, type, (BYTE *)&dw, sizeof(dw) );
374 else
376 TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(str) );
377 if (str) RegSetValueExW( hkey, value, 0, type, (BYTE *)str, size * sizeof(WCHAR) );
378 else RegSetValueExW( hkey, value, 0, type, (const BYTE *)&empty, sizeof(WCHAR) );
380 HeapFree( GetProcessHeap(), 0, str );
381 return TRUE;
383 else /* get the binary data */
385 BYTE *data = NULL;
387 if (!SetupGetBinaryField( context, 5, NULL, 0, &size )) size = 0;
388 if (size)
390 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
391 TRACE( "setting binary data %s len %d\n", debugstr_w(value), size );
392 SetupGetBinaryField( context, 5, data, size, NULL );
394 RegSetValueExW( hkey, value, 0, type, data, size );
395 HeapFree( GetProcessHeap(), 0, data );
396 return TRUE;
401 /***********************************************************************
402 * registry_callback
404 * Called once for each AddReg and DelReg entry in a given section.
406 static BOOL registry_callback( HINF hinf, PCWSTR field, void *arg )
408 struct registry_callback_info *info = arg;
409 INFCONTEXT context;
410 HKEY root_key, hkey;
412 BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
414 for (; ok; ok = SetupFindNextLine( &context, &context ))
416 WCHAR buffer[MAX_INF_STRING_LENGTH];
417 INT flags;
419 /* get root */
420 if (!SetupGetStringFieldW( &context, 1, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
421 continue;
422 if (!(root_key = get_root_key( buffer, info->default_root )))
423 continue;
425 /* get key */
426 if (!SetupGetStringFieldW( &context, 2, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
427 *buffer = 0;
429 /* get flags */
430 if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
432 if (!info->delete)
434 if (flags & FLG_ADDREG_DELREG_BIT) continue; /* ignore this entry */
436 else
438 if (!flags) flags = FLG_ADDREG_DELREG_BIT;
439 else if (!(flags & FLG_ADDREG_DELREG_BIT)) continue; /* ignore this entry */
442 if (info->delete || (flags & FLG_ADDREG_OVERWRITEONLY))
444 if (RegOpenKeyW( root_key, buffer, &hkey )) continue; /* ignore if it doesn't exist */
446 else if (RegCreateKeyW( root_key, buffer, &hkey ))
448 ERR( "could not create key %p %s\n", root_key, debugstr_w(buffer) );
449 continue;
451 TRACE( "key %p %s\n", root_key, debugstr_w(buffer) );
453 /* get value name */
454 if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
455 *buffer = 0;
457 /* and now do it */
458 if (!do_reg_operation( hkey, buffer, &context, flags ))
460 RegCloseKey( hkey );
461 return FALSE;
463 RegCloseKey( hkey );
465 return TRUE;
469 /***********************************************************************
470 * do_register_dll
472 * Register or unregister a dll.
474 static BOOL do_register_dll( const struct register_dll_info *info, const WCHAR *path,
475 INT flags, INT timeout, const WCHAR *args )
477 HMODULE module;
478 HRESULT res;
479 SP_REGISTER_CONTROL_STATUSW status;
480 IMAGE_NT_HEADERS *nt;
482 status.cbSize = sizeof(status);
483 status.FileName = path;
484 status.FailureCode = SPREG_SUCCESS;
485 status.Win32Error = ERROR_SUCCESS;
487 if (info->callback)
489 switch(info->callback( info->callback_context, SPFILENOTIFY_STARTREGISTRATION,
490 (UINT_PTR)&status, !info->unregister ))
492 case FILEOP_ABORT:
493 SetLastError( ERROR_OPERATION_ABORTED );
494 return FALSE;
495 case FILEOP_SKIP:
496 return TRUE;
497 case FILEOP_DOIT:
498 break;
502 if (!(module = LoadLibraryExW( path, 0, LOAD_WITH_ALTERED_SEARCH_PATH )))
504 WARN( "could not load %s\n", debugstr_w(path) );
505 status.FailureCode = SPREG_LOADLIBRARY;
506 status.Win32Error = GetLastError();
507 goto done;
510 if ((nt = RtlImageNtHeader( module )) && !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL))
512 /* file is an executable, not a dll */
513 STARTUPINFOW startup;
514 PROCESS_INFORMATION info;
515 WCHAR *cmd_line;
516 BOOL res;
517 static const WCHAR format[] = {'"','%','s','"',' ','%','s',0};
518 static const WCHAR default_args[] = {'/','R','e','g','S','e','r','v','e','r',0};
520 FreeLibrary( module );
521 module = NULL;
522 if (!args) args = default_args;
523 cmd_line = HeapAlloc( GetProcessHeap(), 0, (strlenW(path) + strlenW(args) + 4) * sizeof(WCHAR) );
524 sprintfW( cmd_line, format, path, args );
525 memset( &startup, 0, sizeof(startup) );
526 startup.cb = sizeof(startup);
527 TRACE( "executing %s\n", debugstr_w(cmd_line) );
528 res = CreateProcessW( NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info );
529 HeapFree( GetProcessHeap(), 0, cmd_line );
530 if (!res)
532 status.FailureCode = SPREG_LOADLIBRARY;
533 status.Win32Error = GetLastError();
534 goto done;
536 CloseHandle( info.hThread );
538 if (WaitForSingleObject( info.hProcess, timeout*1000 ) == WAIT_TIMEOUT)
540 /* timed out, kill the process */
541 TerminateProcess( info.hProcess, 1 );
542 status.FailureCode = SPREG_TIMEOUT;
543 status.Win32Error = ERROR_TIMEOUT;
545 CloseHandle( info.hProcess );
546 goto done;
549 if (flags & FLG_REGSVR_DLLREGISTER)
551 const char *entry_point = info->unregister ? "DllUnregisterServer" : "DllRegisterServer";
552 HRESULT (WINAPI *func)(void) = (void *)GetProcAddress( module, entry_point );
554 if (!func)
556 status.FailureCode = SPREG_GETPROCADDR;
557 status.Win32Error = GetLastError();
558 goto done;
561 TRACE( "calling %s in %s\n", entry_point, debugstr_w(path) );
562 res = func();
564 if (FAILED(res))
566 WARN( "calling %s in %s returned error %x\n", entry_point, debugstr_w(path), res );
567 status.FailureCode = SPREG_REGSVR;
568 status.Win32Error = res;
569 goto done;
573 if (flags & FLG_REGSVR_DLLINSTALL)
575 HRESULT (WINAPI *func)(BOOL,LPCWSTR) = (void *)GetProcAddress( module, "DllInstall" );
577 if (!func)
579 status.FailureCode = SPREG_GETPROCADDR;
580 status.Win32Error = GetLastError();
581 goto done;
584 TRACE( "calling DllInstall(%d,%s) in %s\n",
585 !info->unregister, debugstr_w(args), debugstr_w(path) );
586 res = func( !info->unregister, args );
588 if (FAILED(res))
590 WARN( "calling DllInstall in %s returned error %x\n", debugstr_w(path), res );
591 status.FailureCode = SPREG_REGSVR;
592 status.Win32Error = res;
593 goto done;
597 done:
598 if (module) FreeLibrary( module );
599 if (info->callback) info->callback( info->callback_context, SPFILENOTIFY_ENDREGISTRATION,
600 (UINT_PTR)&status, !info->unregister );
601 return TRUE;
605 /***********************************************************************
606 * register_dlls_callback
608 * Called once for each RegisterDlls entry in a given section.
610 static BOOL register_dlls_callback( HINF hinf, PCWSTR field, void *arg )
612 struct register_dll_info *info = arg;
613 INFCONTEXT context;
614 BOOL ret = TRUE;
615 BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
617 for (; ok; ok = SetupFindNextLine( &context, &context ))
619 WCHAR *path, *args, *p;
620 WCHAR buffer[MAX_INF_STRING_LENGTH];
621 INT flags, timeout;
623 /* get directory */
624 if (!(path = PARSER_get_dest_dir( &context ))) continue;
626 /* get dll name */
627 if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
628 goto done;
629 if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
630 (strlenW(path) + strlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
631 path = p;
632 p += strlenW(p);
633 if (p == path || p[-1] != '\\') *p++ = '\\';
634 strcpyW( p, buffer );
636 /* get flags */
637 if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
639 /* get timeout */
640 if (!SetupGetIntField( &context, 5, &timeout )) timeout = 60;
642 /* get command line */
643 args = NULL;
644 if (SetupGetStringFieldW( &context, 6, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
645 args = buffer;
647 ret = do_register_dll( info, path, flags, timeout, args );
649 done:
650 HeapFree( GetProcessHeap(), 0, path );
651 if (!ret) break;
653 return ret;
656 /***********************************************************************
657 * fake_dlls_callback
659 * Called once for each WineFakeDlls entry in a given section.
661 static BOOL fake_dlls_callback( HINF hinf, PCWSTR field, void *arg )
663 INFCONTEXT context;
664 BOOL ret = TRUE;
665 BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
667 for (; ok; ok = SetupFindNextLine( &context, &context ))
669 WCHAR *path, *p;
670 WCHAR buffer[MAX_INF_STRING_LENGTH];
672 /* get directory */
673 if (!(path = PARSER_get_dest_dir( &context ))) continue;
675 /* get dll name */
676 if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
677 goto done;
678 if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
679 (strlenW(path) + strlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
680 path = p;
681 p += strlenW(p);
682 if (p == path || p[-1] != '\\') *p++ = '\\';
683 strcpyW( p, buffer );
685 /* get source dll */
686 if (SetupGetStringFieldW( &context, 4, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
687 p = buffer; /* otherwise use target base name as default source */
689 create_fake_dll( path, p ); /* ignore errors */
691 done:
692 HeapFree( GetProcessHeap(), 0, path );
693 if (!ret) break;
695 return ret;
698 /***********************************************************************
699 * update_ini_callback
701 * Called once for each UpdateInis entry in a given section.
703 static BOOL update_ini_callback( HINF hinf, PCWSTR field, void *arg )
705 INFCONTEXT context;
707 BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
709 for (; ok; ok = SetupFindNextLine( &context, &context ))
711 WCHAR buffer[MAX_INF_STRING_LENGTH];
712 WCHAR filename[MAX_INF_STRING_LENGTH];
713 WCHAR section[MAX_INF_STRING_LENGTH];
714 WCHAR entry[MAX_INF_STRING_LENGTH];
715 WCHAR string[MAX_INF_STRING_LENGTH];
716 LPWSTR divider;
718 if (!SetupGetStringFieldW( &context, 1, filename,
719 sizeof(filename)/sizeof(WCHAR), NULL ))
720 continue;
722 if (!SetupGetStringFieldW( &context, 2, section,
723 sizeof(section)/sizeof(WCHAR), NULL ))
724 continue;
726 if (!SetupGetStringFieldW( &context, 4, buffer,
727 sizeof(buffer)/sizeof(WCHAR), NULL ))
728 continue;
730 divider = strchrW(buffer,'=');
731 if (divider)
733 *divider = 0;
734 strcpyW(entry,buffer);
735 divider++;
736 strcpyW(string,divider);
738 else
740 strcpyW(entry,buffer);
741 string[0]=0;
744 TRACE("Writing %s = %s in %s of file %s\n",debugstr_w(entry),
745 debugstr_w(string),debugstr_w(section),debugstr_w(filename));
746 WritePrivateProfileStringW(section,entry,string,filename);
749 return TRUE;
752 static BOOL update_ini_fields_callback( HINF hinf, PCWSTR field, void *arg )
754 FIXME( "should update ini fields %s\n", debugstr_w(field) );
755 return TRUE;
758 static BOOL ini2reg_callback( HINF hinf, PCWSTR field, void *arg )
760 FIXME( "should do ini2reg %s\n", debugstr_w(field) );
761 return TRUE;
764 static BOOL logconf_callback( HINF hinf, PCWSTR field, void *arg )
766 FIXME( "should do logconf %s\n", debugstr_w(field) );
767 return TRUE;
770 static BOOL bitreg_callback( HINF hinf, PCWSTR field, void *arg )
772 FIXME( "should do bitreg %s\n", debugstr_w(field) );
773 return TRUE;
776 static BOOL profile_items_callback( HINF hinf, PCWSTR field, void *arg )
778 FIXME( "should do profile items %s\n", debugstr_w(field) );
779 return TRUE;
782 static BOOL copy_inf_callback( HINF hinf, PCWSTR field, void *arg )
784 FIXME( "should do copy inf %s\n", debugstr_w(field) );
785 return TRUE;
789 /***********************************************************************
790 * iterate_section_fields
792 * Iterate over all fields of a certain key of a certain section
794 static BOOL iterate_section_fields( HINF hinf, PCWSTR section, PCWSTR key,
795 iterate_fields_func callback, void *arg )
797 WCHAR static_buffer[200];
798 WCHAR *buffer = static_buffer;
799 DWORD size = sizeof(static_buffer)/sizeof(WCHAR);
800 INFCONTEXT context;
801 BOOL ret = FALSE;
803 BOOL ok = SetupFindFirstLineW( hinf, section, key, &context );
804 while (ok)
806 UINT i, count = SetupGetFieldCount( &context );
807 for (i = 1; i <= count; i++)
809 if (!(buffer = get_field_string( &context, i, buffer, static_buffer, &size )))
810 goto done;
811 if (!callback( hinf, buffer, arg ))
813 WARN("callback failed for %s %s err %d\n",
814 debugstr_w(section), debugstr_w(buffer), GetLastError() );
815 goto done;
818 ok = SetupFindNextMatchLineW( &context, key, &context );
820 ret = TRUE;
821 done:
822 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
823 return ret;
827 /***********************************************************************
828 * SetupInstallFilesFromInfSectionA (SETUPAPI.@)
830 BOOL WINAPI SetupInstallFilesFromInfSectionA( HINF hinf, HINF hlayout, HSPFILEQ queue,
831 PCSTR section, PCSTR src_root, UINT flags )
833 UNICODE_STRING sectionW;
834 BOOL ret = FALSE;
836 if (!RtlCreateUnicodeStringFromAsciiz( &sectionW, section ))
838 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
839 return FALSE;
841 if (!src_root)
842 ret = SetupInstallFilesFromInfSectionW( hinf, hlayout, queue, sectionW.Buffer,
843 NULL, flags );
844 else
846 UNICODE_STRING srcW;
847 if (RtlCreateUnicodeStringFromAsciiz( &srcW, src_root ))
849 ret = SetupInstallFilesFromInfSectionW( hinf, hlayout, queue, sectionW.Buffer,
850 srcW.Buffer, flags );
851 RtlFreeUnicodeString( &srcW );
853 else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
855 RtlFreeUnicodeString( &sectionW );
856 return ret;
860 /***********************************************************************
861 * SetupInstallFilesFromInfSectionW (SETUPAPI.@)
863 BOOL WINAPI SetupInstallFilesFromInfSectionW( HINF hinf, HINF hlayout, HSPFILEQ queue,
864 PCWSTR section, PCWSTR src_root, UINT flags )
866 struct files_callback_info info;
868 info.queue = queue;
869 info.src_root = src_root;
870 info.copy_flags = flags;
871 info.layout = hlayout;
872 return iterate_section_fields( hinf, section, CopyFiles, copy_files_callback, &info );
876 /***********************************************************************
877 * SetupInstallFromInfSectionA (SETUPAPI.@)
879 BOOL WINAPI SetupInstallFromInfSectionA( HWND owner, HINF hinf, PCSTR section, UINT flags,
880 HKEY key_root, PCSTR src_root, UINT copy_flags,
881 PSP_FILE_CALLBACK_A callback, PVOID context,
882 HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data )
884 UNICODE_STRING sectionW, src_rootW;
885 struct callback_WtoA_context ctx;
886 BOOL ret = FALSE;
888 src_rootW.Buffer = NULL;
889 if (src_root && !RtlCreateUnicodeStringFromAsciiz( &src_rootW, src_root ))
891 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
892 return FALSE;
895 if (RtlCreateUnicodeStringFromAsciiz( &sectionW, section ))
897 ctx.orig_context = context;
898 ctx.orig_handler = callback;
899 ret = SetupInstallFromInfSectionW( owner, hinf, sectionW.Buffer, flags, key_root,
900 src_rootW.Buffer, copy_flags, QUEUE_callback_WtoA,
901 &ctx, devinfo, devinfo_data );
902 RtlFreeUnicodeString( &sectionW );
904 else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
906 RtlFreeUnicodeString( &src_rootW );
907 return ret;
911 /***********************************************************************
912 * SetupInstallFromInfSectionW (SETUPAPI.@)
914 BOOL WINAPI SetupInstallFromInfSectionW( HWND owner, HINF hinf, PCWSTR section, UINT flags,
915 HKEY key_root, PCWSTR src_root, UINT copy_flags,
916 PSP_FILE_CALLBACK_W callback, PVOID context,
917 HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data )
919 if (flags & SPINST_FILES)
921 struct files_callback_info info;
922 HSPFILEQ queue;
923 BOOL ret;
925 if (!(queue = SetupOpenFileQueue())) return FALSE;
926 info.queue = queue;
927 info.src_root = src_root;
928 info.copy_flags = copy_flags;
929 info.layout = hinf;
930 ret = (iterate_section_fields( hinf, section, CopyFiles, copy_files_callback, &info ) &&
931 iterate_section_fields( hinf, section, DelFiles, delete_files_callback, &info ) &&
932 iterate_section_fields( hinf, section, RenFiles, rename_files_callback, &info ) &&
933 SetupCommitFileQueueW( owner, queue, callback, context ));
934 SetupCloseFileQueue( queue );
935 if (!ret) return FALSE;
937 if (flags & SPINST_INIFILES)
939 if (!iterate_section_fields( hinf, section, UpdateInis, update_ini_callback, NULL ) ||
940 !iterate_section_fields( hinf, section, UpdateIniFields,
941 update_ini_fields_callback, NULL ))
942 return FALSE;
944 if (flags & SPINST_INI2REG)
946 if (!iterate_section_fields( hinf, section, Ini2Reg, ini2reg_callback, NULL ))
947 return FALSE;
949 if (flags & SPINST_LOGCONFIG)
951 if (!iterate_section_fields( hinf, section, LogConf, logconf_callback, NULL ))
952 return FALSE;
954 if (flags & SPINST_REGSVR)
956 struct register_dll_info info;
958 info.unregister = FALSE;
959 if (flags & SPINST_REGISTERCALLBACKAWARE)
961 info.callback = callback;
962 info.callback_context = context;
964 else info.callback = NULL;
966 if (!iterate_section_fields( hinf, section, RegisterDlls, register_dlls_callback, &info ))
967 return FALSE;
969 if (!iterate_section_fields( hinf, section, WineFakeDlls, fake_dlls_callback, NULL ))
970 return FALSE;
972 if (flags & SPINST_UNREGSVR)
974 struct register_dll_info info;
976 info.unregister = TRUE;
977 if (flags & SPINST_REGISTERCALLBACKAWARE)
979 info.callback = callback;
980 info.callback_context = context;
982 else info.callback = NULL;
984 if (!iterate_section_fields( hinf, section, UnregisterDlls, register_dlls_callback, &info ))
985 return FALSE;
987 if (flags & SPINST_REGISTRY)
989 struct registry_callback_info info;
991 info.default_root = key_root;
992 info.delete = TRUE;
993 if (!iterate_section_fields( hinf, section, DelReg, registry_callback, &info ))
994 return FALSE;
995 info.delete = FALSE;
996 if (!iterate_section_fields( hinf, section, AddReg, registry_callback, &info ))
997 return FALSE;
999 if (flags & SPINST_BITREG)
1001 if (!iterate_section_fields( hinf, section, BitReg, bitreg_callback, NULL ))
1002 return FALSE;
1004 if (flags & SPINST_PROFILEITEMS)
1006 if (!iterate_section_fields( hinf, section, ProfileItems, profile_items_callback, NULL ))
1007 return FALSE;
1009 if (flags & SPINST_COPYINF)
1011 if (!iterate_section_fields( hinf, section, CopyINF, copy_inf_callback, NULL ))
1012 return FALSE;
1015 return TRUE;
1019 /***********************************************************************
1020 * InstallHinfSectionW (SETUPAPI.@)
1022 * NOTE: 'cmdline' is <section> <mode> <path> from
1023 * RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>
1025 void WINAPI InstallHinfSectionW( HWND hwnd, HINSTANCE handle, LPCWSTR cmdline, INT show )
1027 #ifdef __i386__
1028 static const WCHAR nt_platformW[] = {'.','n','t','x','8','6',0};
1029 #elif defined(__x86_64)
1030 static const WCHAR nt_platformW[] = {'.','n','t','a','m','d','6','4',0};
1031 #else /* FIXME: other platforms */
1032 static const WCHAR nt_platformW[] = {'.','n','t',0};
1033 #endif
1034 static const WCHAR nt_genericW[] = {'.','n','t',0};
1035 static const WCHAR servicesW[] = {'.','S','e','r','v','i','c','e','s',0};
1037 WCHAR *s, *path, section[MAX_PATH + (sizeof(nt_platformW) + sizeof(servicesW)) / sizeof(WCHAR)];
1038 void *callback_context;
1039 UINT mode;
1040 HINF hinf;
1042 TRACE("hwnd %p, handle %p, cmdline %s\n", hwnd, handle, debugstr_w(cmdline));
1044 lstrcpynW( section, cmdline, MAX_PATH );
1046 if (!(s = strchrW( section, ' ' ))) return;
1047 *s++ = 0;
1048 while (*s == ' ') s++;
1049 mode = atoiW( s );
1051 /* quoted paths are not allowed on native, the rest of the command line is taken as the path */
1052 if (!(s = strchrW( s, ' ' ))) return;
1053 while (*s == ' ') s++;
1054 path = s;
1056 hinf = SetupOpenInfFileW( path, NULL, INF_STYLE_WIN4, NULL );
1057 if (hinf == INVALID_HANDLE_VALUE) return;
1059 if (!(GetVersion() & 0x80000000))
1061 INFCONTEXT context;
1063 /* check for <section>.ntx86 (or corresponding name for the current platform)
1064 * and then <section>.nt */
1065 s = section + strlenW(section);
1066 memcpy( s, nt_platformW, sizeof(nt_platformW) );
1067 if (!(SetupFindFirstLineW( hinf, section, NULL, &context )))
1069 memcpy( s, nt_genericW, sizeof(nt_genericW) );
1070 if (!(SetupFindFirstLineW( hinf, section, NULL, &context ))) *s = 0;
1072 if (*s) TRACE( "using section %s instead\n", debugstr_w(section) );
1075 callback_context = SetupInitDefaultQueueCallback( hwnd );
1076 SetupInstallFromInfSectionW( hwnd, hinf, section, SPINST_ALL, NULL, NULL, SP_COPY_NEWER,
1077 SetupDefaultQueueCallbackW, callback_context,
1078 NULL, NULL );
1079 SetupTermDefaultQueueCallback( callback_context );
1080 strcatW( section, servicesW );
1081 SetupInstallServicesFromInfSectionW( hinf, section, 0 );
1082 SetupCloseInfFile( hinf );
1084 /* FIXME: should check the mode and maybe reboot */
1085 /* there isn't much point in doing that since we */
1086 /* don't yet handle deferred file copies anyway. */
1090 /***********************************************************************
1091 * InstallHinfSectionA (SETUPAPI.@)
1093 void WINAPI InstallHinfSectionA( HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show )
1095 UNICODE_STRING cmdlineW;
1097 if (RtlCreateUnicodeStringFromAsciiz( &cmdlineW, cmdline ))
1099 InstallHinfSectionW( hwnd, handle, cmdlineW.Buffer, show );
1100 RtlFreeUnicodeString( &cmdlineW );
1105 /***********************************************************************
1106 * add_service
1108 * Create a new service. Helper for SetupInstallServicesFromInfSectionW.
1110 static BOOL add_service( SC_HANDLE scm, HINF hinf, const WCHAR *name, const WCHAR *section, DWORD flags )
1112 struct registry_callback_info info;
1113 SC_HANDLE service;
1114 INFCONTEXT context;
1115 SERVICE_DESCRIPTIONW descr;
1116 WCHAR *display_name, *start_name, *load_order, *binary_path;
1117 INT service_type = 0, start_type = 0, error_control = 0;
1118 DWORD size;
1119 HKEY hkey;
1121 /* first the mandatory fields */
1123 if (!SetupFindFirstLineW( hinf, section, ServiceType, &context ) ||
1124 !SetupGetIntField( &context, 1, &service_type ))
1126 SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
1127 return FALSE;
1129 if (!SetupFindFirstLineW( hinf, section, StartType, &context ) ||
1130 !SetupGetIntField( &context, 1, &start_type ))
1132 SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
1133 return FALSE;
1135 if (!SetupFindFirstLineW( hinf, section, ErrorControl, &context ) ||
1136 !SetupGetIntField( &context, 1, &error_control ))
1138 SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
1139 return FALSE;
1141 if (!(binary_path = dup_section_line_field( hinf, section, ServiceBinary, 1 )))
1143 SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
1144 return FALSE;
1147 /* now the optional fields */
1149 display_name = dup_section_line_field( hinf, section, DisplayName, 1 );
1150 start_name = dup_section_line_field( hinf, section, StartName, 1 );
1151 load_order = dup_section_line_field( hinf, section, LoadOrderGroup, 1 );
1152 descr.lpDescription = dup_section_line_field( hinf, section, Description, 1 );
1154 /* FIXME: Dependencies field */
1155 /* FIXME: Security field */
1157 TRACE( "service %s display %s type %x start %x error %x binary %s order %s startname %s flags %x\n",
1158 debugstr_w(name), debugstr_w(display_name), service_type, start_type, error_control,
1159 debugstr_w(binary_path), debugstr_w(load_order), debugstr_w(start_name), flags );
1161 service = CreateServiceW( scm, name, display_name, SERVICE_ALL_ACCESS,
1162 service_type, start_type, error_control, binary_path,
1163 load_order, NULL, NULL, start_name, NULL );
1164 if (service)
1166 if (descr.lpDescription) ChangeServiceConfig2W( service, SERVICE_CONFIG_DESCRIPTION, &descr );
1168 else
1170 if (GetLastError() != ERROR_SERVICE_EXISTS) goto done;
1171 service = OpenServiceW( scm, name, SERVICE_QUERY_CONFIG|SERVICE_CHANGE_CONFIG|SERVICE_START );
1172 if (!service) goto done;
1174 if (flags & (SPSVCINST_NOCLOBBER_DISPLAYNAME | SPSVCINST_NOCLOBBER_STARTTYPE |
1175 SPSVCINST_NOCLOBBER_ERRORCONTROL | SPSVCINST_NOCLOBBER_LOADORDERGROUP))
1177 QUERY_SERVICE_CONFIGW *config = NULL;
1179 if (!QueryServiceConfigW( service, NULL, 0, &size ) &&
1180 GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1181 config = HeapAlloc( GetProcessHeap(), 0, size );
1182 if (config && QueryServiceConfigW( service, config, size, &size ))
1184 if (flags & SPSVCINST_NOCLOBBER_STARTTYPE) start_type = config->dwStartType;
1185 if (flags & SPSVCINST_NOCLOBBER_ERRORCONTROL) error_control = config->dwErrorControl;
1186 if (flags & SPSVCINST_NOCLOBBER_DISPLAYNAME)
1188 HeapFree( GetProcessHeap(), 0, display_name );
1189 display_name = strdupW( config->lpDisplayName );
1191 if (flags & SPSVCINST_NOCLOBBER_LOADORDERGROUP)
1193 HeapFree( GetProcessHeap(), 0, load_order );
1194 load_order = strdupW( config->lpLoadOrderGroup );
1197 HeapFree( GetProcessHeap(), 0, config );
1199 TRACE( "changing %s display %s type %x start %x error %x binary %s loadorder %s startname %s\n",
1200 debugstr_w(name), debugstr_w(display_name), service_type, start_type, error_control,
1201 debugstr_w(binary_path), debugstr_w(load_order), debugstr_w(start_name) );
1203 ChangeServiceConfigW( service, service_type, start_type, error_control, binary_path,
1204 load_order, NULL, NULL, start_name, NULL, display_name );
1206 if (!(flags & SPSVCINST_NOCLOBBER_DESCRIPTION))
1207 ChangeServiceConfig2W( service, SERVICE_CONFIG_DESCRIPTION, &descr );
1210 /* execute the AddReg, DelReg and BitReg entries */
1212 info.default_root = 0;
1213 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, ServicesKey, &hkey ))
1215 RegOpenKeyW( hkey, name, &info.default_root );
1216 RegCloseKey( hkey );
1218 if (info.default_root)
1220 info.delete = TRUE;
1221 iterate_section_fields( hinf, section, DelReg, registry_callback, &info );
1222 info.delete = FALSE;
1223 iterate_section_fields( hinf, section, AddReg, registry_callback, &info );
1224 RegCloseKey( info.default_root );
1226 iterate_section_fields( hinf, section, BitReg, bitreg_callback, NULL );
1228 if (flags & SPSVCINST_STARTSERVICE) StartServiceW( service, 0, NULL );
1229 CloseServiceHandle( service );
1231 done:
1232 if (!service) WARN( "failed err %u\n", GetLastError() );
1233 HeapFree( GetProcessHeap(), 0, binary_path );
1234 HeapFree( GetProcessHeap(), 0, display_name );
1235 HeapFree( GetProcessHeap(), 0, start_name );
1236 HeapFree( GetProcessHeap(), 0, load_order );
1237 HeapFree( GetProcessHeap(), 0, descr.lpDescription );
1238 return service != 0;
1242 /***********************************************************************
1243 * del_service
1245 * Delete service. Helper for SetupInstallServicesFromInfSectionW.
1247 static BOOL del_service( SC_HANDLE scm, HINF hinf, const WCHAR *name, DWORD flags )
1249 BOOL ret;
1250 SC_HANDLE service;
1251 SERVICE_STATUS status;
1253 if (!(service = OpenServiceW( scm, name, SERVICE_STOP | DELETE )))
1255 if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) return TRUE;
1256 WARN( "cannot open %s err %u\n", debugstr_w(name), GetLastError() );
1257 return FALSE;
1259 if (flags & SPSVCINST_STOPSERVICE) ControlService( service, SERVICE_CONTROL_STOP, &status );
1260 TRACE( "deleting %s\n", debugstr_w(name) );
1261 ret = DeleteService( service );
1262 CloseServiceHandle( service );
1263 return ret;
1267 /***********************************************************************
1268 * SetupInstallServicesFromInfSectionW (SETUPAPI.@)
1270 BOOL WINAPI SetupInstallServicesFromInfSectionW( HINF hinf, PCWSTR section, DWORD flags )
1272 WCHAR service_name[MAX_INF_STRING_LENGTH];
1273 WCHAR service_section[MAX_INF_STRING_LENGTH];
1274 SC_HANDLE scm;
1275 INFCONTEXT context;
1276 INT section_flags;
1277 BOOL ok, ret = FALSE;
1279 if (!(scm = OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS ))) return FALSE;
1281 if (!(ok = SetupFindFirstLineW( hinf, section, AddService, &context )))
1282 SetLastError( ERROR_SECTION_NOT_FOUND );
1283 while (ok)
1285 if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL ))
1286 continue;
1287 if (!SetupGetIntField( &context, 2, &section_flags )) section_flags = 0;
1288 if (!SetupGetStringFieldW( &context, 3, service_section, MAX_INF_STRING_LENGTH, NULL ))
1289 continue;
1290 if (!(ret = add_service( scm, hinf, service_name, service_section, section_flags | flags )))
1291 goto done;
1292 ok = SetupFindNextMatchLineW( &context, AddService, &context );
1295 if (!(ok = SetupFindFirstLineW( hinf, section, DelService, &context )))
1296 SetLastError( ERROR_SECTION_NOT_FOUND );
1297 while (ok)
1299 if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL ))
1300 continue;
1301 if (!SetupGetIntField( &context, 2, &section_flags )) section_flags = 0;
1302 if (!(ret = del_service( scm, hinf, service_name, section_flags | flags ))) goto done;
1303 ok = SetupFindNextMatchLineW( &context, AddService, &context );
1305 if (ret) SetLastError( ERROR_SUCCESS );
1306 done:
1307 CloseServiceHandle( scm );
1308 return ret;
1312 /***********************************************************************
1313 * SetupInstallServicesFromInfSectionA (SETUPAPI.@)
1315 BOOL WINAPI SetupInstallServicesFromInfSectionA( HINF Inf, PCSTR SectionName, DWORD Flags)
1317 UNICODE_STRING SectionNameW;
1318 BOOL ret = FALSE;
1320 if (RtlCreateUnicodeStringFromAsciiz( &SectionNameW, SectionName ))
1322 ret = SetupInstallServicesFromInfSectionW( Inf, SectionNameW.Buffer, Flags );
1323 RtlFreeUnicodeString( &SectionNameW );
1325 else
1326 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1328 return ret;