2 * Setupapi install routines
4 * Copyright 2002 Alexandre Julliard for CodeWeavers
5 * 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "setupapi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
26 /* info passed to callback functions dealing with files */
27 struct files_callback_info
35 /* info passed to callback functions dealing with the registry */
36 struct registry_callback_info
42 /* info passed to callback functions dealing with registering dlls */
43 struct register_dll_info
45 PSP_FILE_CALLBACK_W callback
;
46 PVOID callback_context
;
50 /* info passed to callback functions dealing with Needs directives */
51 struct needs_callback_info
63 PSP_DEVINFO_DATA devinfo_data
;
68 typedef BOOL (*iterate_fields_func
)( HINF hinf
, PCWSTR field
, void *arg
);
70 /* Unicode constants */
71 static const WCHAR AddService
[] = {'A','d','d','S','e','r','v','i','c','e',0};
72 static const WCHAR CopyFiles
[] = {'C','o','p','y','F','i','l','e','s',0};
73 static const WCHAR DelFiles
[] = {'D','e','l','F','i','l','e','s',0};
74 static const WCHAR RenFiles
[] = {'R','e','n','F','i','l','e','s',0};
75 static const WCHAR Ini2Reg
[] = {'I','n','i','2','R','e','g',0};
76 static const WCHAR LogConf
[] = {'L','o','g','C','o','n','f',0};
77 static const WCHAR AddReg
[] = {'A','d','d','R','e','g',0};
78 static const WCHAR DelReg
[] = {'D','e','l','R','e','g',0};
79 static const WCHAR BitReg
[] = {'B','i','t','R','e','g',0};
80 static const WCHAR UpdateInis
[] = {'U','p','d','a','t','e','I','n','i','s',0};
81 static const WCHAR CopyINF
[] = {'C','o','p','y','I','N','F',0};
82 static const WCHAR UpdateIniFields
[] = {'U','p','d','a','t','e','I','n','i','F','i','e','l','d','s',0};
83 static const WCHAR RegisterDlls
[] = {'R','e','g','i','s','t','e','r','D','l','l','s',0};
84 static const WCHAR UnregisterDlls
[] = {'U','n','r','e','g','i','s','t','e','r','D','l','l','s',0};
85 static const WCHAR ProfileItems
[] = {'P','r','o','f','i','l','e','I','t','e','m','s',0};
86 static const WCHAR Include
[] = {'I','n','c','l','u','d','e',0};
87 static const WCHAR Needs
[] = {'N','e','e','d','s',0};
90 /***********************************************************************
93 * Retrieve the contents of a field, dynamically growing the buffer if necessary.
95 static WCHAR
*get_field_string( INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
96 WCHAR
*static_buffer
, DWORD
*size
)
100 if (SetupGetStringFieldW( context
, index
, buffer
, *size
, &required
)) return buffer
;
101 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
103 /* now grow the buffer */
104 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
105 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, required
*sizeof(WCHAR
) ))) return NULL
;
107 if (SetupGetStringFieldW( context
, index
, buffer
, *size
, &required
)) return buffer
;
109 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
114 /***********************************************************************
115 * copy_files_callback
117 * Called once for each CopyFiles entry in a given section.
119 static BOOL
copy_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
121 struct files_callback_info
*info
= arg
;
123 if (field
[0] == '@') /* special case: copy single file */
124 SetupQueueDefaultCopyW( info
->queue
, info
->layout
, info
->src_root
, NULL
, field
, info
->copy_flags
);
126 SetupQueueCopySectionW( info
->queue
, info
->src_root
, info
->layout
, hinf
, field
, info
->copy_flags
);
131 /***********************************************************************
132 * delete_files_callback
134 * Called once for each DelFiles entry in a given section.
136 static BOOL
delete_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
138 struct files_callback_info
*info
= arg
;
139 SetupQueueDeleteSectionW( info
->queue
, hinf
, 0, field
);
144 /***********************************************************************
145 * rename_files_callback
147 * Called once for each RenFiles entry in a given section.
149 static BOOL
rename_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
151 struct files_callback_info
*info
= arg
;
152 SetupQueueRenameSectionW( info
->queue
, hinf
, 0, field
);
157 /***********************************************************************
160 * Retrieve the registry root key from its name.
162 static HKEY
get_root_key( const WCHAR
*name
, HKEY def_root
)
164 static const WCHAR HKCR
[] = {'H','K','C','R',0};
165 static const WCHAR HKCU
[] = {'H','K','C','U',0};
166 static const WCHAR HKLM
[] = {'H','K','L','M',0};
167 static const WCHAR HKU
[] = {'H','K','U',0};
168 static const WCHAR HKR
[] = {'H','K','R',0};
170 if (!strcmpiW( name
, HKCR
)) return HKEY_CLASSES_ROOT
;
171 if (!strcmpiW( name
, HKCU
)) return HKEY_CURRENT_USER
;
172 if (!strcmpiW( name
, HKLM
)) return HKEY_LOCAL_MACHINE
;
173 if (!strcmpiW( name
, HKU
)) return HKEY_USERS
;
174 if (!strcmpiW( name
, HKR
)) return def_root
;
179 /***********************************************************************
180 * append_multi_sz_value
182 * Append a multisz string to a multisz registry value.
184 static void append_multi_sz_value( HKEY hkey
, const WCHAR
*value
, const WCHAR
*strings
,
187 DWORD size
, type
, total
;
190 if (RegQueryValueExW( hkey
, value
, NULL
, &type
, NULL
, &size
)) return;
191 if (type
!= REG_MULTI_SZ
) return;
193 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+ str_size
) * sizeof(WCHAR
) ))) return;
194 if (RegQueryValueExW( hkey
, value
, NULL
, NULL
, (BYTE
*)buffer
, &size
)) goto done
;
196 /* compare each string against all the existing ones */
200 int len
= strlenW(strings
) + 1;
202 for (p
= buffer
; *p
; p
+= strlenW(p
) + 1)
203 if (!strcmpiW( p
, strings
)) break;
205 if (!*p
) /* not found, need to append it */
207 memcpy( p
, strings
, len
* sizeof(WCHAR
) );
215 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(buffer
) );
216 RegSetValueExW( hkey
, value
, 0, REG_MULTI_SZ
, (BYTE
*)buffer
, total
);
219 HeapFree( GetProcessHeap(), 0, buffer
);
223 /***********************************************************************
224 * delete_multi_sz_value
226 * Remove a string from a multisz registry value.
228 static void delete_multi_sz_value( HKEY hkey
, const WCHAR
*value
, const WCHAR
*string
)
231 WCHAR
*buffer
, *src
, *dst
;
233 if (RegQueryValueExW( hkey
, value
, NULL
, &type
, NULL
, &size
)) return;
234 if (type
!= REG_MULTI_SZ
) return;
235 /* allocate double the size, one for value before and one for after */
236 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* 2 * sizeof(WCHAR
) ))) return;
237 if (RegQueryValueExW( hkey
, value
, NULL
, NULL
, (BYTE
*)buffer
, &size
)) goto done
;
242 int len
= strlenW(src
) + 1;
243 if (strcmpiW( src
, string
))
245 memcpy( dst
, src
, len
* sizeof(WCHAR
) );
251 if (dst
!= buffer
+ 2*size
) /* did we remove something? */
253 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(buffer
+ size
) );
254 RegSetValueExW( hkey
, value
, 0, REG_MULTI_SZ
,
255 (BYTE
*)(buffer
+ size
), dst
- (buffer
+ size
) );
258 HeapFree( GetProcessHeap(), 0, buffer
);
262 /***********************************************************************
265 * Perform an add/delete registry operation depending on the flags.
267 static BOOL
do_reg_operation( HKEY hkey
, const WCHAR
*value
, INFCONTEXT
*context
, INT flags
)
271 if (flags
& (FLG_ADDREG_DELREG_BIT
| FLG_ADDREG_DELVAL
)) /* deletion */
273 if (*value
&& !(flags
& FLG_DELREG_KEYONLY_COMMON
))
275 if ((flags
& FLG_DELREG_MULTI_SZ_DELSTRING
) == FLG_DELREG_MULTI_SZ_DELSTRING
)
279 if (!SetupGetStringFieldW( context
, 5, NULL
, 0, &size
) || !size
) return TRUE
;
280 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
281 SetupGetStringFieldW( context
, 5, str
, size
, NULL
);
282 delete_multi_sz_value( hkey
, value
, str
);
283 HeapFree( GetProcessHeap(), 0, str
);
285 else RegDeleteValueW( hkey
, value
);
287 else RegDeleteKeyW( hkey
, NULL
);
291 if (flags
& (FLG_ADDREG_KEYONLY
|FLG_ADDREG_KEYONLY_COMMON
)) return TRUE
;
293 if (flags
& (FLG_ADDREG_NOCLOBBER
|FLG_ADDREG_OVERWRITEONLY
))
295 BOOL exists
= !RegQueryValueExW( hkey
, value
, NULL
, NULL
, NULL
, NULL
);
296 if (exists
&& (flags
& FLG_ADDREG_NOCLOBBER
)) return TRUE
;
297 if (!exists
& (flags
& FLG_ADDREG_OVERWRITEONLY
)) return TRUE
;
300 switch(flags
& FLG_ADDREG_TYPE_MASK
)
302 case FLG_ADDREG_TYPE_SZ
: type
= REG_SZ
; break;
303 case FLG_ADDREG_TYPE_MULTI_SZ
: type
= REG_MULTI_SZ
; break;
304 case FLG_ADDREG_TYPE_EXPAND_SZ
: type
= REG_EXPAND_SZ
; break;
305 case FLG_ADDREG_TYPE_BINARY
: type
= REG_BINARY
; break;
306 case FLG_ADDREG_TYPE_DWORD
: type
= REG_DWORD
; break;
307 case FLG_ADDREG_TYPE_NONE
: type
= REG_NONE
; break;
308 default: type
= flags
>> 16; break;
311 if (!(flags
& FLG_ADDREG_BINVALUETYPE
) ||
312 (type
== REG_DWORD
&& SetupGetFieldCount(context
) == 5))
314 static const WCHAR empty
;
317 if (type
== REG_MULTI_SZ
)
319 if (!SetupGetMultiSzFieldW( context
, 5, NULL
, 0, &size
)) size
= 0;
322 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
323 SetupGetMultiSzFieldW( context
, 5, str
, size
, NULL
);
325 if (flags
& FLG_ADDREG_APPEND
)
327 if (!str
) return TRUE
;
328 append_multi_sz_value( hkey
, value
, str
, size
);
329 HeapFree( GetProcessHeap(), 0, str
);
332 /* else fall through to normal string handling */
336 if (!SetupGetStringFieldW( context
, 5, NULL
, 0, &size
)) size
= 0;
339 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
340 SetupGetStringFieldW( context
, 5, str
, size
, NULL
);
344 if (type
== REG_DWORD
)
346 DWORD dw
= str
? strtoulW( str
, NULL
, 0 ) : 0;
347 TRACE( "setting dword %s to %lx\n", debugstr_w(value
), dw
);
348 RegSetValueExW( hkey
, value
, 0, type
, (BYTE
*)&dw
, sizeof(dw
) );
352 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(str
) );
353 if (str
) RegSetValueExW( hkey
, value
, 0, type
, (BYTE
*)str
, size
* sizeof(WCHAR
) );
354 else RegSetValueExW( hkey
, value
, 0, type
, (const BYTE
*)&empty
, sizeof(WCHAR
) );
356 HeapFree( GetProcessHeap(), 0, str
);
359 else /* get the binary data */
363 if (!SetupGetBinaryField( context
, 5, NULL
, 0, &size
)) size
= 0;
366 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
367 TRACE( "setting binary data %s len %ld\n", debugstr_w(value
), size
);
368 SetupGetBinaryField( context
, 5, data
, size
, NULL
);
370 RegSetValueExW( hkey
, value
, 0, type
, data
, size
);
371 HeapFree( GetProcessHeap(), 0, data
);
377 /***********************************************************************
380 * Called once for each AddReg and DelReg entry in a given section.
382 static BOOL
registry_callback( HINF hinf
, PCWSTR field
, void *arg
)
384 struct registry_callback_info
*info
= arg
;
388 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
390 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
392 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
396 if (!SetupGetStringFieldW( &context
, 1, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
398 if (!(root_key
= get_root_key( buffer
, info
->default_root
)))
402 if (!SetupGetStringFieldW( &context
, 2, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
406 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0;
410 if (flags
& FLG_ADDREG_DELREG_BIT
) continue; /* ignore this entry */
414 if (!flags
) flags
= FLG_ADDREG_DELREG_BIT
;
415 else if (!(flags
& FLG_ADDREG_DELREG_BIT
)) continue; /* ignore this entry */
418 if (info
->delete || (flags
& FLG_ADDREG_OVERWRITEONLY
))
420 if (RegOpenKeyW( root_key
, buffer
, &hkey
)) continue; /* ignore if it doesn't exist */
422 else if (RegCreateKeyW( root_key
, buffer
, &hkey
))
424 ERR( "could not create key %p %s\n", root_key
, debugstr_w(buffer
) );
427 TRACE( "key %p %s\n", root_key
, debugstr_w(buffer
) );
430 if (!SetupGetStringFieldW( &context
, 3, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
434 if (!do_reg_operation( hkey
, buffer
, &context
, flags
))
436 if (hkey
!= root_key
) RegCloseKey( hkey
);
439 if (hkey
!= root_key
) RegCloseKey( hkey
);
445 /***********************************************************************
448 * Register or unregister a dll.
450 static BOOL
do_register_dll( const struct register_dll_info
*info
, const WCHAR
*path
,
451 INT flags
, INT timeout
, const WCHAR
*args
)
455 SP_REGISTER_CONTROL_STATUSW status
;
457 status
.cbSize
= sizeof(status
);
458 status
.FileName
= path
;
459 status
.FailureCode
= SPREG_SUCCESS
;
460 status
.Win32Error
= ERROR_SUCCESS
;
464 switch(info
->callback( info
->callback_context
, SPFILENOTIFY_STARTREGISTRATION
,
465 (UINT_PTR
)&status
, !info
->unregister
))
468 SetLastError( ERROR_OPERATION_ABORTED
);
477 if (!(module
= LoadLibraryExW( path
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)))
479 WARN( "could not load %s\n", debugstr_w(path
) );
480 status
.FailureCode
= SPREG_LOADLIBRARY
;
481 status
.Win32Error
= GetLastError();
485 if (flags
& FLG_REGSVR_DLLREGISTER
)
487 const char *entry_point
= info
->unregister
? "DllUnregisterServer" : "DllRegisterServer";
488 HRESULT (WINAPI
*func
)(void) = (void *)GetProcAddress( module
, entry_point
);
492 status
.FailureCode
= SPREG_GETPROCADDR
;
493 status
.Win32Error
= GetLastError();
497 TRACE( "calling %s in %s\n", entry_point
, debugstr_w(path
) );
502 WARN( "calling %s in %s returned error %lx\n", entry_point
, debugstr_w(path
), res
);
503 status
.FailureCode
= SPREG_REGSVR
;
504 status
.Win32Error
= res
;
509 if (flags
& FLG_REGSVR_DLLINSTALL
)
511 HRESULT (WINAPI
*func
)(BOOL
,LPCWSTR
) = (void *)GetProcAddress( module
, "DllInstall" );
515 status
.FailureCode
= SPREG_GETPROCADDR
;
516 status
.Win32Error
= GetLastError();
520 TRACE( "calling DllInstall(%d,%s) in %s\n",
521 !info
->unregister
, debugstr_w(args
), debugstr_w(path
) );
522 res
= func( !info
->unregister
, args
);
526 WARN( "calling DllInstall in %s returned error %lx\n", debugstr_w(path
), res
);
527 status
.FailureCode
= SPREG_REGSVR
;
528 status
.Win32Error
= res
;
534 if (module
) FreeLibrary( module
);
535 if (info
->callback
) info
->callback( info
->callback_context
, SPFILENOTIFY_ENDREGISTRATION
,
536 (UINT_PTR
)&status
, !info
->unregister
);
541 /***********************************************************************
542 * register_dlls_callback
544 * Called once for each RegisterDlls entry in a given section.
546 static BOOL
register_dlls_callback( HINF hinf
, PCWSTR field
, void *arg
)
548 struct register_dll_info
*info
= arg
;
551 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
553 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
555 WCHAR
*path
, *args
, *p
;
556 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
560 if (!(path
= PARSER_get_dest_dir( &context
))) continue;
563 if (!SetupGetStringFieldW( &context
, 3, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
565 if (!(p
= HeapReAlloc( GetProcessHeap(), 0, path
,
566 (strlenW(path
) + strlenW(buffer
) + 2) * sizeof(WCHAR
) ))) goto done
;
569 if (p
== path
|| p
[-1] != '\\') *p
++ = '\\';
570 strcpyW( p
, buffer
);
573 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0;
576 if (!SetupGetIntField( &context
, 5, &timeout
)) timeout
= 60;
578 /* get command line */
580 if (SetupGetStringFieldW( &context
, 6, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
583 ret
= do_register_dll( info
, path
, flags
, timeout
, args
);
586 HeapFree( GetProcessHeap(), 0, path
);
592 /***********************************************************************
593 * update_ini_callback
595 * Called once for each UpdateInis entry in a given section.
597 static BOOL
update_ini_callback( HINF hinf
, PCWSTR field
, void *arg
)
601 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
603 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
605 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
606 WCHAR filename
[MAX_INF_STRING_LENGTH
];
607 WCHAR section
[MAX_INF_STRING_LENGTH
];
608 WCHAR entry
[MAX_INF_STRING_LENGTH
];
609 WCHAR string
[MAX_INF_STRING_LENGTH
];
612 if (!SetupGetStringFieldW( &context
, 1, filename
,
613 sizeof(filename
)/sizeof(WCHAR
), NULL
))
616 if (!SetupGetStringFieldW( &context
, 2, section
,
617 sizeof(section
)/sizeof(WCHAR
), NULL
))
620 if (!SetupGetStringFieldW( &context
, 4, buffer
,
621 sizeof(buffer
)/sizeof(WCHAR
), NULL
))
624 divider
= strchrW(buffer
,'=');
628 strcpyW(entry
,buffer
);
630 strcpyW(string
,divider
);
634 strcpyW(entry
,buffer
);
638 TRACE("Writing %s = %s in %s of file %s\n",debugstr_w(entry
),
639 debugstr_w(string
),debugstr_w(section
),debugstr_w(filename
));
640 WritePrivateProfileStringW(section
,entry
,string
,filename
);
646 static BOOL
update_ini_fields_callback( HINF hinf
, PCWSTR field
, void *arg
)
648 FIXME( "should update ini fields %s\n", debugstr_w(field
) );
652 static BOOL
ini2reg_callback( HINF hinf
, PCWSTR field
, void *arg
)
654 FIXME( "should do ini2reg %s\n", debugstr_w(field
) );
658 static BOOL
logconf_callback( HINF hinf
, PCWSTR field
, void *arg
)
660 FIXME( "should do logconf %s\n", debugstr_w(field
) );
664 static BOOL
bitreg_callback( HINF hinf
, PCWSTR field
, void *arg
)
666 FIXME( "should do bitreg %s\n", debugstr_w(field
) );
670 static BOOL
profile_items_callback( HINF hinf
, PCWSTR field
, void *arg
)
672 FIXME( "should do profile items %s\n", debugstr_w(field
) );
676 static BOOL
copy_inf_callback( HINF hinf
, PCWSTR field
, void *arg
)
678 FIXME( "should do copy inf %s\n", debugstr_w(field
) );
683 /***********************************************************************
684 * iterate_section_fields
686 * Iterate over all fields of a certain key of a certain section
688 static BOOL
iterate_section_fields( HINF hinf
, PCWSTR section
, PCWSTR key
,
689 iterate_fields_func callback
, void *arg
)
691 WCHAR static_buffer
[200];
692 WCHAR
*buffer
= static_buffer
;
693 DWORD size
= sizeof(static_buffer
)/sizeof(WCHAR
);
697 BOOL ok
= SetupFindFirstLineW( hinf
, section
, key
, &context
);
700 UINT i
, count
= SetupGetFieldCount( &context
);
701 for (i
= 1; i
<= count
; i
++)
703 if (!(buffer
= get_field_string( &context
, i
, buffer
, static_buffer
, &size
)))
705 if (!callback( hinf
, buffer
, arg
))
707 WARN("callback failed for %s %s err %ld\n",
708 debugstr_w(section
), debugstr_w(buffer
), GetLastError() );
712 ok
= SetupFindNextMatchLineW( &context
, key
, &context
);
716 if (buffer
&& buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
721 /***********************************************************************
722 * SetupInstallFilesFromInfSectionA (SETUPAPI.@)
724 BOOL WINAPI
SetupInstallFilesFromInfSectionA( HINF hinf
, HINF hlayout
, HSPFILEQ queue
,
725 PCSTR section
, PCSTR src_root
, UINT flags
)
727 UNICODE_STRING sectionW
;
730 if (!RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
732 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
736 ret
= SetupInstallFilesFromInfSectionW( hinf
, hlayout
, queue
, sectionW
.Buffer
,
741 if (RtlCreateUnicodeStringFromAsciiz( &srcW
, src_root
))
743 ret
= SetupInstallFilesFromInfSectionW( hinf
, hlayout
, queue
, sectionW
.Buffer
,
744 srcW
.Buffer
, flags
);
745 RtlFreeUnicodeString( &srcW
);
747 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
749 RtlFreeUnicodeString( §ionW
);
754 /***********************************************************************
755 * SetupInstallFilesFromInfSectionW (SETUPAPI.@)
757 BOOL WINAPI
SetupInstallFilesFromInfSectionW( HINF hinf
, HINF hlayout
, HSPFILEQ queue
,
758 PCWSTR section
, PCWSTR src_root
, UINT flags
)
760 struct files_callback_info info
;
763 info
.src_root
= src_root
;
764 info
.copy_flags
= flags
;
765 info
.layout
= hlayout
;
766 return iterate_section_fields( hinf
, section
, CopyFiles
, copy_files_callback
, &info
);
770 /***********************************************************************
771 * SetupInstallFromInfSectionA (SETUPAPI.@)
773 BOOL WINAPI
SetupInstallFromInfSectionA( HWND owner
, HINF hinf
, PCSTR section
, UINT flags
,
774 HKEY key_root
, PCSTR src_root
, UINT copy_flags
,
775 PSP_FILE_CALLBACK_A callback
, PVOID context
,
776 HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
)
778 UNICODE_STRING sectionW
, src_rootW
;
779 struct callback_WtoA_context ctx
;
782 src_rootW
.Buffer
= NULL
;
783 if (src_root
&& !RtlCreateUnicodeStringFromAsciiz( &src_rootW
, src_root
))
785 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
789 if (RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
791 ctx
.orig_context
= context
;
792 ctx
.orig_handler
= callback
;
793 ret
= SetupInstallFromInfSectionW( owner
, hinf
, sectionW
.Buffer
, flags
, key_root
,
794 src_rootW
.Buffer
, copy_flags
, QUEUE_callback_WtoA
,
795 &ctx
, devinfo
, devinfo_data
);
796 RtlFreeUnicodeString( §ionW
);
798 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
800 RtlFreeUnicodeString( &src_rootW
);
805 /***********************************************************************
808 * Called once for each Include entry in a given section.
810 static BOOL
include_callback( HINF hinf
, PCWSTR field
, void *arg
)
812 return SetupOpenAppendInfFileW( field
, hinf
, NULL
);
816 /***********************************************************************
819 * Called once for each Needs entry in a given section.
821 static BOOL
needs_callback( HINF hinf
, PCWSTR field
, void *arg
)
823 struct needs_callback_info
*info
= arg
;
828 return SetupInstallFromInfSectionW(info
->owner
, hinf
, field
, info
->flags
,
829 info
->key_root
, info
->src_root
, info
->copy_flags
, info
->callback
,
830 info
->context
, info
->devinfo
, info
->devinfo_data
);
832 return SetupInstallServicesFromInfSectionExW(hinf
, field
, info
->flags
,
833 info
->devinfo
, info
->devinfo_data
, info
->reserved1
, info
->reserved2
);
835 ERR("Unknown info type %ld\n", info
->type
);
841 /***********************************************************************
842 * SetupInstallFromInfSectionW (SETUPAPI.@)
844 BOOL WINAPI
SetupInstallFromInfSectionW( HWND owner
, HINF hinf
, PCWSTR section
, UINT flags
,
845 HKEY key_root
, PCWSTR src_root
, UINT copy_flags
,
846 PSP_FILE_CALLBACK_W callback
, PVOID context
,
847 HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
)
849 struct needs_callback_info needs_info
;
851 /* Parse 'Include' and 'Needs' directives */
852 iterate_section_fields( hinf
, section
, Include
, include_callback
, NULL
);
854 needs_info
.owner
= owner
;
855 needs_info
.flags
= flags
;
856 needs_info
.key_root
= key_root
;
857 needs_info
.src_root
= src_root
;
858 needs_info
.copy_flags
= copy_flags
;
859 needs_info
.callback
= callback
;
860 needs_info
.context
= context
;
861 needs_info
.devinfo
= devinfo
;
862 needs_info
.devinfo_data
= devinfo_data
;
863 iterate_section_fields( hinf
, section
, Needs
, needs_callback
, &needs_info
);
865 if (flags
& SPINST_FILES
)
867 SP_DEVINSTALL_PARAMS_W install_params
;
868 struct files_callback_info info
;
869 HSPFILEQ queue
= NULL
;
870 BOOL use_custom_queue
;
873 install_params
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
874 use_custom_queue
= SetupDiGetDeviceInstallParamsW(devinfo
, devinfo_data
, &install_params
) && (install_params
.Flags
& DI_NOVCP
);
875 if (!use_custom_queue
&& ((queue
= SetupOpenFileQueue()) == (HSPFILEQ
)INVALID_HANDLE_VALUE
))
877 info
.queue
= use_custom_queue
? install_params
.FileQueue
: queue
;
878 info
.src_root
= src_root
;
879 info
.copy_flags
= copy_flags
;
881 ret
= (iterate_section_fields( hinf
, section
, CopyFiles
, copy_files_callback
, &info
) &&
882 iterate_section_fields( hinf
, section
, DelFiles
, delete_files_callback
, &info
) &&
883 iterate_section_fields( hinf
, section
, RenFiles
, rename_files_callback
, &info
));
884 if (!use_custom_queue
)
887 ret
= SetupCommitFileQueueW( owner
, queue
, callback
, context
);
888 SetupCloseFileQueue( queue
);
890 if (!ret
) return FALSE
;
892 if (flags
& SPINST_INIFILES
)
894 if (!iterate_section_fields( hinf
, section
, UpdateInis
, update_ini_callback
, NULL
) ||
895 !iterate_section_fields( hinf
, section
, UpdateIniFields
,
896 update_ini_fields_callback
, NULL
))
899 if (flags
& SPINST_INI2REG
)
901 if (!iterate_section_fields( hinf
, section
, Ini2Reg
, ini2reg_callback
, NULL
))
904 if (flags
& SPINST_LOGCONFIG
)
906 if (!iterate_section_fields( hinf
, section
, LogConf
, logconf_callback
, NULL
))
909 if (flags
& SPINST_REGSVR
)
911 struct register_dll_info info
;
913 info
.unregister
= FALSE
;
914 if (flags
& SPINST_REGISTERCALLBACKAWARE
)
916 info
.callback
= callback
;
917 info
.callback_context
= context
;
919 else info
.callback
= NULL
;
921 if (!iterate_section_fields( hinf
, section
, RegisterDlls
, register_dlls_callback
, &info
))
924 if (flags
& SPINST_UNREGSVR
)
926 struct register_dll_info info
;
928 info
.unregister
= TRUE
;
929 if (flags
& SPINST_REGISTERCALLBACKAWARE
)
931 info
.callback
= callback
;
932 info
.callback_context
= context
;
934 else info
.callback
= NULL
;
936 if (!iterate_section_fields( hinf
, section
, UnregisterDlls
, register_dlls_callback
, &info
))
939 if (flags
& SPINST_REGISTRY
)
941 struct registry_callback_info info
;
943 info
.default_root
= key_root
;
945 if (!iterate_section_fields( hinf
, section
, DelReg
, registry_callback
, &info
))
948 if (!iterate_section_fields( hinf
, section
, AddReg
, registry_callback
, &info
))
951 if (flags
& SPINST_BITREG
)
953 if (!iterate_section_fields( hinf
, section
, BitReg
, bitreg_callback
, NULL
))
956 if (flags
& SPINST_PROFILEITEMS
)
958 if (!iterate_section_fields( hinf
, section
, ProfileItems
, profile_items_callback
, NULL
))
961 if (flags
& SPINST_COPYINF
)
963 if (!iterate_section_fields( hinf
, section
, CopyINF
, copy_inf_callback
, NULL
))
971 /***********************************************************************
972 * InstallHinfSectionW (SETUPAPI.@)
974 * NOTE: 'cmdline' is <section> <mode> <path> from
975 * RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>
977 void WINAPI
InstallHinfSectionW( HWND hwnd
, HINSTANCE handle
, LPCWSTR cmdline
, INT show
)
979 WCHAR
*p
, *path
, section
[MAX_PATH
];
980 void *callback_context
;
984 TRACE("hwnd %p, handle %p, cmdline %s\n", hwnd
, handle
, debugstr_w(cmdline
));
986 lstrcpynW( section
, cmdline
, sizeof(section
)/sizeof(WCHAR
) );
988 if (!(p
= strchrW( section
, ' ' ))) return;
990 while (*p
== ' ') p
++;
993 if (!(p
= strchrW( p
, ' ' ))) return;
995 while (*path
== ' ') path
++;
997 hinf
= SetupOpenInfFileW( path
, NULL
, INF_STYLE_WIN4
, NULL
);
998 if (hinf
== INVALID_HANDLE_VALUE
) return;
1000 callback_context
= SetupInitDefaultQueueCallback( hwnd
);
1001 SetupInstallFromInfSectionW( hwnd
, hinf
, section
, SPINST_ALL
, NULL
, NULL
, SP_COPY_NEWER
,
1002 SetupDefaultQueueCallbackW
, callback_context
,
1004 SetupTermDefaultQueueCallback( callback_context
);
1005 SetupCloseInfFile( hinf
);
1007 /* FIXME: should check the mode and maybe reboot */
1008 /* there isn't much point in doing that since we */
1009 /* don't yet handle deferred file copies anyway. */
1013 /***********************************************************************
1014 * InstallHinfSectionA (SETUPAPI.@)
1016 void WINAPI
InstallHinfSectionA( HWND hwnd
, HINSTANCE handle
, LPCSTR cmdline
, INT show
)
1018 UNICODE_STRING cmdlineW
;
1020 if (RtlCreateUnicodeStringFromAsciiz( &cmdlineW
, cmdline
))
1022 InstallHinfSectionW( hwnd
, handle
, cmdlineW
.Buffer
, show
);
1023 RtlFreeUnicodeString( &cmdlineW
);
1028 /***********************************************************************
1029 * SetupInstallServicesFromInfSectionA (SETUPAPI.@)
1031 BOOL WINAPI
SetupInstallServicesFromInfSectionA( HINF hinf
, PCSTR sectionname
, DWORD flags
)
1033 return SetupInstallServicesFromInfSectionExA( hinf
, sectionname
, flags
,
1034 NULL
, NULL
, NULL
, NULL
);
1038 /***********************************************************************
1039 * SetupInstallServicesFromInfSectionW (SETUPAPI.@)
1041 BOOL WINAPI
SetupInstallServicesFromInfSectionW( HINF hinf
, PCWSTR sectionname
, DWORD flags
)
1043 return SetupInstallServicesFromInfSectionExW( hinf
, sectionname
, flags
,
1044 NULL
, NULL
, NULL
, NULL
);
1048 /***********************************************************************
1049 * SetupInstallServicesFromInfSectionExA (SETUPAPI.@)
1051 BOOL WINAPI
SetupInstallServicesFromInfSectionExA( HINF hinf
, PCSTR sectionname
, DWORD flags
, HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
, PVOID reserved1
, PVOID reserved2
)
1053 UNICODE_STRING sectionnameW
;
1056 if (RtlCreateUnicodeStringFromAsciiz( §ionnameW
, sectionname
))
1058 ret
= SetupInstallServicesFromInfSectionExW( hinf
, sectionnameW
.Buffer
, flags
, devinfo
, devinfo_data
, reserved1
, reserved2
);
1059 RtlFreeUnicodeString( §ionnameW
);
1062 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1068 static BOOL
GetLineText( HINF hinf
, PCWSTR section_name
, PCWSTR key_name
, PWSTR
*value
)
1075 if (! SetupGetLineTextW( NULL
, hinf
, section_name
, key_name
, NULL
, 0, &required
)
1076 && GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1079 buf
= HeapAlloc( GetProcessHeap(), 0, required
* sizeof(WCHAR
) );
1082 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1086 if (! SetupGetLineTextW( NULL
, hinf
, section_name
, key_name
, buf
, required
, &required
) )
1088 HeapFree( GetProcessHeap(), 0, buf
);
1097 static BOOL
GetIntField( HINF hinf
, PCWSTR section_name
, PCWSTR key_name
, INT
*value
)
1102 if (! GetLineText( hinf
, section_name
, key_name
, &buffer
) )
1105 res
= wcstol( buffer
, &end
, 0 );
1106 if (end
!= buffer
&& !*end
)
1108 HeapFree(GetProcessHeap(), 0, buffer
);
1114 HeapFree(GetProcessHeap(), 0, buffer
);
1115 SetLastError( ERROR_INVALID_DATA
);
1121 BOOL
GetStringField( PINFCONTEXT context
, DWORD index
, PWSTR
*value
)
1126 ret
= SetupGetStringFieldW(
1133 else if (RequiredSize
== 0)
1139 /* We got the needed size for the buffer */
1140 *value
= MyMalloc(RequiredSize
* sizeof(WCHAR
));
1143 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1146 ret
= SetupGetStringFieldW(
1149 *value
, RequiredSize
, NULL
);
1157 static BOOL
InstallOneService(
1158 struct DeviceInfoSet
*list
,
1160 IN LPCWSTR ServiceSection
,
1161 IN LPCWSTR ServiceName
,
1162 IN UINT ServiceFlags
)
1164 SC_HANDLE hSCManager
= NULL
;
1165 SC_HANDLE hService
= NULL
;
1166 LPDWORD GroupOrder
= NULL
;
1167 LPQUERY_SERVICE_CONFIG ServiceConfig
= NULL
;
1170 HKEY hGroupOrderListKey
= INVALID_HANDLE_VALUE
;
1171 LPWSTR ServiceBinary
= NULL
;
1172 LPWSTR LoadOrderGroup
= NULL
;
1173 LPWSTR DisplayName
= NULL
;
1174 LPWSTR Description
= NULL
;
1175 LPWSTR Dependencies
= NULL
;
1176 INT ServiceType
, StartType
, ErrorControl
;
1178 DWORD tagId
= (DWORD
)-1;
1181 if (!GetIntField(hInf
, ServiceSection
, L
"ServiceType", &ServiceType
))
1183 if (!GetIntField(hInf
, ServiceSection
, L
"StartType", &StartType
))
1185 if (!GetIntField(hInf
, ServiceSection
, L
"ErrorControl", &ErrorControl
))
1187 useTag
= (ServiceType
== SERVICE_BOOT_START
|| ServiceType
== SERVICE_SYSTEM_START
);
1189 hSCManager
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASE
, SC_MANAGER_CREATE_SERVICE
);
1190 if (hSCManager
== NULL
)
1193 if (!GetLineText(hInf
, ServiceSection
, L
"ServiceBinary", &ServiceBinary
))
1196 /* Don't check return value, as these fields are optional and
1197 * GetLineText initialize output parameter even on failure */
1198 GetLineText(hInf
, ServiceSection
, L
"LoadOrderGroup", &LoadOrderGroup
);
1199 GetLineText(hInf
, ServiceSection
, L
"DisplayName", &DisplayName
);
1200 GetLineText(hInf
, ServiceSection
, L
"Description", &Description
);
1201 GetLineText(hInf
, ServiceSection
, L
"Dependencies", &Dependencies
);
1203 hService
= OpenServiceW(
1206 GENERIC_READ
| GENERIC_WRITE
);
1207 if (hService
== NULL
&& GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST
)
1210 if (hService
&& (ServiceFlags
& SPSVCINST_DELETEEVENTLOGENTRY
))
1212 ret
= DeleteService(hService
);
1213 if (!ret
&& GetLastError() != ERROR_SERVICE_MARKED_FOR_DELETE
)
1217 if (hService
== NULL
)
1219 /* Create new service */
1220 hService
= CreateServiceW(
1230 useTag
? &tagId
: NULL
,
1233 if (hService
== NULL
)
1239 /* Read current configuration */
1240 if (!QueryServiceConfigW(hService
, NULL
, 0, &bufferSize
))
1242 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1244 ServiceConfig
= MyMalloc(bufferSize
);
1247 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1250 if (!QueryServiceConfigW(hService
, ServiceConfig
, bufferSize
, &bufferSize
))
1253 tagId
= ServiceConfig
->dwTagId
;
1255 /* Update configuration */
1256 ret
= ChangeServiceConfigW(
1259 (ServiceFlags
& SPSVCINST_NOCLOBBER_STARTTYPE
) ? SERVICE_NO_CHANGE
: StartType
,
1260 (ServiceFlags
& SPSVCINST_NOCLOBBER_ERRORCONTROL
) ? SERVICE_NO_CHANGE
: ErrorControl
,
1262 (ServiceFlags
& SPSVCINST_NOCLOBBER_LOADORDERGROUP
&& ServiceConfig
->lpLoadOrderGroup
) ? NULL
: LoadOrderGroup
,
1263 useTag
? &tagId
: NULL
,
1264 (ServiceFlags
& SPSVCINST_NOCLOBBER_DEPENDENCIES
&& ServiceConfig
->lpDependencies
) ? NULL
: Dependencies
,
1266 (ServiceFlags
& SPSVCINST_NOCLOBBER_DISPLAYNAME
&& ServiceConfig
->lpDisplayName
) ? NULL
: DisplayName
);
1271 /* FIXME: use Description and SPSVCINST_NOCLOBBER_DESCRIPTION */
1275 /* Add the tag to SYSTEM\CurrentControlSet\Control\GroupOrderList key */
1277 LPCWSTR lpLoadOrderGroup
;
1280 lpLoadOrderGroup
= LoadOrderGroup
;
1281 if ((ServiceFlags
& SPSVCINST_NOCLOBBER_LOADORDERGROUP
) && ServiceConfig
&& ServiceConfig
->lpLoadOrderGroup
)
1282 lpLoadOrderGroup
= ServiceConfig
->lpLoadOrderGroup
;
1285 list
? list
->HKLM
: HKEY_LOCAL_MACHINE
,
1286 L
"SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
1287 &hGroupOrderListKey
);
1288 if (rc
!= ERROR_SUCCESS
)
1293 rc
= RegQueryValueExW(hGroupOrderListKey
, lpLoadOrderGroup
, NULL
, &dwRegType
, NULL
, &bufferSize
);
1294 if (rc
== ERROR_FILE_NOT_FOUND
)
1295 bufferSize
= sizeof(DWORD
);
1296 else if (rc
!= ERROR_SUCCESS
)
1301 else if (dwRegType
!= REG_BINARY
|| bufferSize
== 0 || bufferSize
% sizeof(DWORD
) != 0)
1303 SetLastError(ERROR_GEN_FAILURE
);
1306 /* Allocate buffer to store existing data + the new tag */
1307 GroupOrder
= MyMalloc(bufferSize
+ sizeof(DWORD
));
1310 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1313 if (rc
== ERROR_SUCCESS
)
1315 /* Read existing data */
1316 rc
= RegQueryValueExW(
1323 if (rc
!= ERROR_SUCCESS
)
1328 if (ServiceFlags
& SPSVCINST_TAGTOFRONT
)
1329 memmove(&GroupOrder
[2], &GroupOrder
[1], bufferSize
- sizeof(DWORD
));
1336 if (ServiceFlags
& SPSVCINST_TAGTOFRONT
)
1337 GroupOrder
[1] = tagId
;
1339 GroupOrder
[bufferSize
/ sizeof(DWORD
)] = tagId
;
1341 rc
= RegSetValueExW(
1347 bufferSize
+ sizeof(DWORD
));
1348 if (rc
!= ERROR_SUCCESS
)
1358 if (hSCManager
!= NULL
)
1359 CloseServiceHandle(hSCManager
);
1360 if (hService
!= NULL
)
1361 CloseServiceHandle(hService
);
1362 if (hGroupOrderListKey
!= INVALID_HANDLE_VALUE
)
1363 RegCloseKey(hGroupOrderListKey
);
1364 MyFree(ServiceConfig
);
1365 MyFree(ServiceBinary
);
1366 MyFree(LoadOrderGroup
);
1367 MyFree(DisplayName
);
1368 MyFree(Description
);
1369 MyFree(Dependencies
);
1372 TRACE("Returning %d\n", ret
);
1377 /***********************************************************************
1378 * SetupInstallServicesFromInfSectionExW (SETUPAPI.@)
1380 BOOL WINAPI
SetupInstallServicesFromInfSectionExW( HINF hinf
, PCWSTR sectionname
, DWORD flags
, HDEVINFO DeviceInfoSet
, PSP_DEVINFO_DATA DeviceInfoData
, PVOID reserved1
, PVOID reserved2
)
1382 struct DeviceInfoSet
*list
= NULL
;
1385 TRACE("%p, %s, 0x%lx, %p, %p, %p, %p\n", hinf
, debugstr_w(sectionname
),
1386 flags
, DeviceInfoSet
, DeviceInfoData
, reserved1
, reserved2
);
1389 SetLastError(ERROR_INVALID_PARAMETER
);
1390 else if (flags
& ~(SPSVCINST_TAGTOFRONT
| SPSVCINST_DELETEEVENTLOGENTRY
| SPSVCINST_NOCLOBBER_DISPLAYNAME
| SPSVCINST_NOCLOBBER_STARTTYPE
| SPSVCINST_NOCLOBBER_ERRORCONTROL
| SPSVCINST_NOCLOBBER_LOADORDERGROUP
| SPSVCINST_NOCLOBBER_DEPENDENCIES
| SPSVCINST_STOPSERVICE
))
1392 TRACE("Unknown flags: 0x%08lx\n", flags
& ~(SPSVCINST_TAGTOFRONT
| SPSVCINST_DELETEEVENTLOGENTRY
| SPSVCINST_NOCLOBBER_DISPLAYNAME
| SPSVCINST_NOCLOBBER_STARTTYPE
| SPSVCINST_NOCLOBBER_ERRORCONTROL
| SPSVCINST_NOCLOBBER_LOADORDERGROUP
| SPSVCINST_NOCLOBBER_DEPENDENCIES
| SPSVCINST_STOPSERVICE
));
1393 SetLastError(ERROR_INVALID_FLAGS
);
1395 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
1396 SetLastError(ERROR_INVALID_HANDLE
);
1397 else if (DeviceInfoSet
&& (list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
1398 SetLastError(ERROR_INVALID_HANDLE
);
1399 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1400 SetLastError(ERROR_INVALID_USER_BUFFER
);
1401 else if (reserved1
!= NULL
|| reserved2
!= NULL
)
1402 SetLastError(ERROR_INVALID_PARAMETER
);
1405 struct needs_callback_info needs_info
;
1406 LPWSTR ServiceName
= NULL
;
1407 LPWSTR ServiceSection
= NULL
;
1409 INFCONTEXT ContextService
;
1410 BOOL bNeedReboot
= FALSE
;
1412 /* Parse 'Include' and 'Needs' directives */
1413 iterate_section_fields( hinf
, sectionname
, Include
, include_callback
, NULL
);
1414 needs_info
.type
= 1;
1415 needs_info
.flags
= flags
;
1416 needs_info
.devinfo
= DeviceInfoSet
;
1417 needs_info
.devinfo_data
= DeviceInfoData
;
1418 needs_info
.reserved1
= reserved1
;
1419 needs_info
.reserved2
= reserved2
;
1420 iterate_section_fields( hinf
, sectionname
, Needs
, needs_callback
, &needs_info
);
1422 if (flags
& SPSVCINST_STOPSERVICE
)
1424 FIXME("Stopping the device not implemented\n");
1425 /* This may lead to require a reboot */
1426 /* bNeedReboot = TRUE; */
1428 SERVICE_STATUS ServiceStatus
;
1429 ret
= ControlService(hService
, SERVICE_CONTROL_STOP
, &ServiceStatus
);
1430 if (!ret
&& GetLastError() != ERROR_SERVICE_NOT_ACTIVE
)
1432 if (ServiceStatus
.dwCurrentState
!= SERVICE_STOP_PENDING
&& ServiceStatus
.dwCurrentState
!= SERVICE_STOPPED
)
1434 SetLastError(ERROR_INSTALL_SERVICE_FAILURE
);
1438 flags
&= ~SPSVCINST_STOPSERVICE
;
1441 ret
= SetupFindFirstLineW(hinf
, sectionname
, AddService
, &ContextService
);
1444 if (!GetStringField(&ContextService
, 1, &ServiceName
))
1447 ret
= SetupGetIntField(
1449 2, /* Field index */
1453 /* The field may be empty. Ignore the error */
1457 if (!GetStringField(&ContextService
, 3, &ServiceSection
))
1460 ret
= InstallOneService(list
, hinf
, ServiceSection
, ServiceName
, (ServiceFlags
& ~SPSVCINST_ASSOCSERVICE
) | flags
);
1464 if (ServiceFlags
& SPSVCINST_ASSOCSERVICE
)
1466 ret
= SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet
, DeviceInfoData
, SPDRP_SERVICE
, (LPBYTE
)ServiceName
, (strlenW(ServiceName
) + 1) * sizeof(WCHAR
));
1472 HeapFree(GetProcessHeap(), 0, ServiceName
);
1473 HeapFree(GetProcessHeap(), 0, ServiceSection
);
1474 ServiceName
= ServiceSection
= NULL
;
1475 ret
= SetupFindNextMatchLineW(&ContextService
, AddService
, &ContextService
);
1479 SetLastError(ERROR_SUCCESS_REBOOT_REQUIRED
);
1481 SetLastError(ERROR_SUCCESS
);
1485 TRACE("Returning %d\n", ret
);
1490 /***********************************************************************
1491 * SetupCopyOEMInfA (SETUPAPI.@)
1493 BOOL WINAPI
SetupCopyOEMInfA(
1494 IN PCSTR SourceInfFileName
,
1495 IN PCSTR OEMSourceMediaLocation
,
1496 IN DWORD OEMSourceMediaType
,
1498 OUT PSTR DestinationInfFileName OPTIONAL
,
1499 IN DWORD DestinationInfFileNameSize
,
1500 OUT PDWORD RequiredSize OPTIONAL
,
1501 OUT PSTR
* DestinationInfFileNameComponent OPTIONAL
)
1503 PWSTR SourceInfFileNameW
= NULL
;
1504 PWSTR OEMSourceMediaLocationW
= NULL
;
1505 PWSTR DestinationInfFileNameW
= NULL
;
1506 PWSTR DestinationInfFileNameComponentW
= NULL
;
1509 TRACE("%s %s 0x%lx 0x%lx %p 0%lu %p %p\n",
1510 SourceInfFileName
, OEMSourceMediaLocation
, OEMSourceMediaType
,
1511 CopyStyle
, DestinationInfFileName
, DestinationInfFileNameSize
,
1512 RequiredSize
, DestinationInfFileNameComponent
);
1514 if (!DestinationInfFileName
&& DestinationInfFileNameSize
> 0)
1515 SetLastError(ERROR_INVALID_PARAMETER
);
1516 else if (!(SourceInfFileNameW
= MultiByteToUnicode(SourceInfFileName
, CP_ACP
)))
1517 SetLastError(ERROR_INVALID_PARAMETER
);
1518 else if (!(OEMSourceMediaLocationW
= MultiByteToUnicode(OEMSourceMediaLocation
, CP_ACP
)))
1519 SetLastError(ERROR_INVALID_PARAMETER
);
1522 if (DestinationInfFileNameSize
!= 0)
1524 DestinationInfFileNameW
= MyMalloc(DestinationInfFileNameSize
* sizeof(WCHAR
));
1525 if (!DestinationInfFileNameW
)
1527 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1532 ret
= SetupCopyOEMInfW(
1534 OEMSourceMediaLocationW
,
1537 DestinationInfFileNameW
,
1538 DestinationInfFileNameSize
,
1540 DestinationInfFileNameComponent
? &DestinationInfFileNameComponentW
: NULL
);
1544 if (DestinationInfFileNameSize
!= 0)
1546 if (WideCharToMultiByte(CP_ACP
, 0, DestinationInfFileNameW
, -1,
1547 DestinationInfFileName
, DestinationInfFileNameSize
, NULL
, NULL
) == 0)
1549 DestinationInfFileName
[0] = '\0';
1553 if (DestinationInfFileNameComponent
)
1555 if (DestinationInfFileNameComponentW
)
1556 *DestinationInfFileNameComponent
= &DestinationInfFileName
[DestinationInfFileNameComponentW
- DestinationInfFileNameW
];
1558 *DestinationInfFileNameComponent
= NULL
;
1564 MyFree(SourceInfFileNameW
);
1565 MyFree(OEMSourceMediaLocationW
);
1566 MyFree(DestinationInfFileNameW
);
1568 TRACE("Returning %d\n", ret
);