2 * Setupapi file queue 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 "setupapi_private.h"
25 /* Unicode constants */
26 static const WCHAR DotSecurity
[] = {'.','S','e','c','u','r','i','t','y',0};
28 /* context structure for the default queue callback */
29 struct default_callback_context
47 PSECURITY_DESCRIPTOR dst_sd
;
59 struct file_op_queue copy_queue
;
60 struct file_op_queue delete_queue
;
61 struct file_op_queue rename_queue
;
66 static inline WCHAR
*strdupW( const WCHAR
*str
)
71 int len
= (strlenW(str
) + 1) * sizeof(WCHAR
);
72 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
))) memcpy( ret
, str
, len
);
77 static inline char *strdupWtoA( const WCHAR
*str
)
82 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
83 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
84 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
89 /* append a file operation to a queue */
90 static inline void queue_file_op( struct file_op_queue
*queue
, struct file_op
*op
)
93 if (queue
->tail
) queue
->tail
->next
= op
;
94 else queue
->head
= op
;
99 /* free all the file operations on a given queue */
100 static void free_file_op_queue( struct file_op_queue
*queue
)
102 struct file_op
*t
, *op
= queue
->head
;
106 HeapFree( GetProcessHeap(), 0, op
->src_root
);
107 HeapFree( GetProcessHeap(), 0, op
->src_path
);
108 HeapFree( GetProcessHeap(), 0, op
->src_file
);
109 HeapFree( GetProcessHeap(), 0, op
->src_descr
);
110 HeapFree( GetProcessHeap(), 0, op
->src_tag
);
111 HeapFree( GetProcessHeap(), 0, op
->dst_path
);
112 if (op
->dst_sd
) LocalFree( op
->dst_sd
);
113 if (op
->dst_file
!= op
->src_file
) HeapFree( GetProcessHeap(), 0, op
->dst_file
);
116 HeapFree( GetProcessHeap(), 0, t
);
120 /* concat 3 strings to make a path, handling separators correctly */
121 static void concat_W( WCHAR
*buffer
, const WCHAR
*src1
, const WCHAR
*src2
, const WCHAR
*src3
)
126 strcpyW( buffer
, src1
);
127 buffer
+= strlenW(buffer
);
128 if (buffer
[-1] != '\\') *buffer
++ = '\\';
129 if (src2
) while (*src2
== '\\') src2
++;
134 strcpyW( buffer
, src2
);
135 buffer
+= strlenW(buffer
);
136 if (buffer
[-1] != '\\') *buffer
++ = '\\';
137 if (src3
) while (*src3
== '\\') src3
++;
141 strcpyW( buffer
, src3
);
142 buffer
+= strlenW(buffer
);
147 /***********************************************************************
150 * Build a FILEPATHS_W structure for a given file operation.
152 static BOOL
build_filepathsW( const struct file_op
*op
, FILEPATHS_W
*paths
)
154 unsigned int src_len
= 1, dst_len
= 1;
155 WCHAR
*source
= (PWSTR
)paths
->Source
, *target
= (PWSTR
)paths
->Target
;
157 if (op
->src_root
) src_len
+= strlenW(op
->src_root
) + 1;
158 if (op
->src_path
) src_len
+= strlenW(op
->src_path
) + 1;
159 if (op
->src_file
) src_len
+= strlenW(op
->src_file
) + 1;
160 if (op
->dst_path
) dst_len
+= strlenW(op
->dst_path
) + 1;
161 if (op
->dst_file
) dst_len
+= strlenW(op
->dst_file
) + 1;
162 src_len
*= sizeof(WCHAR
);
163 dst_len
*= sizeof(WCHAR
);
165 if (!source
|| HeapSize( GetProcessHeap(), 0, source
) < src_len
)
167 HeapFree( GetProcessHeap(), 0, source
);
168 paths
->Source
= source
= HeapAlloc( GetProcessHeap(), 0, src_len
);
170 if (!target
|| HeapSize( GetProcessHeap(), 0, target
) < dst_len
)
172 HeapFree( GetProcessHeap(), 0, target
);
173 paths
->Target
= target
= HeapAlloc( GetProcessHeap(), 0, dst_len
);
175 if (!source
|| !target
) return FALSE
;
176 concat_W( source
, op
->src_root
, op
->src_path
, op
->src_file
);
177 concat_W( target
, NULL
, op
->dst_path
, op
->dst_file
);
178 paths
->Win32Error
= 0;
184 /***********************************************************************
185 * QUEUE_callback_WtoA
187 * Map a file callback parameters from W to A and call the A callback.
189 UINT CALLBACK
QUEUE_callback_WtoA( void *context
, UINT notification
,
190 UINT_PTR param1
, UINT_PTR param2
)
192 struct callback_WtoA_context
*callback_ctx
= context
;
193 char buffer
[MAX_PATH
];
195 UINT_PTR old_param2
= param2
;
199 case SPFILENOTIFY_COPYERROR
:
200 param2
= (UINT_PTR
)&buffer
;
202 case SPFILENOTIFY_STARTDELETE
:
203 case SPFILENOTIFY_ENDDELETE
:
204 case SPFILENOTIFY_DELETEERROR
:
205 case SPFILENOTIFY_STARTRENAME
:
206 case SPFILENOTIFY_ENDRENAME
:
207 case SPFILENOTIFY_RENAMEERROR
:
208 case SPFILENOTIFY_STARTCOPY
:
209 case SPFILENOTIFY_ENDCOPY
:
210 case SPFILENOTIFY_QUEUESCAN_EX
:
212 FILEPATHS_W
*pathsW
= (FILEPATHS_W
*)param1
;
215 pathsA
.Source
= strdupWtoA( pathsW
->Source
);
216 pathsA
.Target
= strdupWtoA( pathsW
->Target
);
217 pathsA
.Win32Error
= pathsW
->Win32Error
;
218 pathsA
.Flags
= pathsW
->Flags
;
219 ret
= callback_ctx
->orig_handler( callback_ctx
->orig_context
, notification
,
220 (UINT_PTR
)&pathsA
, param2
);
221 HeapFree( GetProcessHeap(), 0, (void *)pathsA
.Source
);
222 HeapFree( GetProcessHeap(), 0, (void *)pathsA
.Target
);
224 if (notification
== SPFILENOTIFY_COPYERROR
)
225 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, (WCHAR
*)old_param2
, MAX_PATH
);
228 case SPFILENOTIFY_STARTREGISTRATION
:
229 case SPFILENOTIFY_ENDREGISTRATION
:
231 SP_REGISTER_CONTROL_STATUSW
*statusW
= (SP_REGISTER_CONTROL_STATUSW
*)param1
;
232 SP_REGISTER_CONTROL_STATUSA statusA
;
234 statusA
.cbSize
= sizeof(statusA
);
235 statusA
.FileName
= strdupWtoA( statusW
->FileName
);
236 statusA
.Win32Error
= statusW
->Win32Error
;
237 statusA
.FailureCode
= statusW
->FailureCode
;
238 ret
= callback_ctx
->orig_handler( callback_ctx
->orig_context
, notification
,
239 (UINT_PTR
)&statusA
, param2
);
240 HeapFree( GetProcessHeap(), 0, (LPSTR
)statusA
.FileName
);
244 case SPFILENOTIFY_QUEUESCAN
:
246 LPWSTR targetW
= (LPWSTR
)param1
;
247 LPSTR target
= strdupWtoA( targetW
);
249 ret
= callback_ctx
->orig_handler( callback_ctx
->orig_context
, notification
,
250 (UINT_PTR
)target
, param2
);
251 HeapFree( GetProcessHeap(), 0, target
);
255 case SPFILENOTIFY_NEEDMEDIA
:
256 FIXME("mapping for %d not implemented\n",notification
);
257 case SPFILENOTIFY_STARTQUEUE
:
258 case SPFILENOTIFY_ENDQUEUE
:
259 case SPFILENOTIFY_STARTSUBQUEUE
:
260 case SPFILENOTIFY_ENDSUBQUEUE
:
262 ret
= callback_ctx
->orig_handler( callback_ctx
->orig_context
, notification
, param1
, param2
);
269 /***********************************************************************
272 * Retrieve the source file information for a given file.
274 static void get_src_file_info( HINF hinf
, struct file_op
*op
)
276 static const WCHAR SourceDisksNames
[] =
277 {'S','o','u','r','c','e','D','i','s','k','s','N','a','m','e','s',0};
278 static const WCHAR SourceDisksFiles
[] =
279 {'S','o','u','r','c','e','D','i','s','k','s','F','i','l','e','s',0};
281 INFCONTEXT file_ctx
, disk_ctx
;
284 WCHAR SectionName
[MAX_PATH
];
286 /* find the SourceDisksFiles entry */
287 if(!SetupDiGetActualSectionToInstallW(hinf
, SourceDisksFiles
, SectionName
, MAX_PATH
, NULL
, NULL
))
289 if (!SetupFindFirstLineW( hinf
, SectionName
, op
->src_file
, &file_ctx
))
291 if ((op
->style
& (SP_COPY_SOURCE_ABSOLUTE
|SP_COPY_SOURCEPATH_ABSOLUTE
))) return;
292 /* no specific info, use .inf file source directory */
293 if (!op
->src_root
) op
->src_root
= PARSER_get_src_root( hinf
);
296 if (!SetupGetIntField( &file_ctx
, 1, &diskid
)) return;
298 /* now find the diskid in the SourceDisksNames section */
299 if(!SetupDiGetActualSectionToInstallW(hinf
, SourceDisksNames
, SectionName
, MAX_PATH
, NULL
, NULL
))
301 if (!SetupFindFirstLineW( hinf
, SectionName
, NULL
, &disk_ctx
)) return;
304 if (SetupGetIntField( &disk_ctx
, 0, &id
) && (id
== diskid
)) break;
305 if (!SetupFindNextLine( &disk_ctx
, &disk_ctx
)) return;
308 /* and fill in the missing info */
312 if (SetupGetStringFieldW( &disk_ctx
, 1, NULL
, 0, &len
) &&
313 (op
->src_descr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) )))
314 SetupGetStringFieldW( &disk_ctx
, 1, op
->src_descr
, len
, NULL
);
318 if (SetupGetStringFieldW( &disk_ctx
, 2, NULL
, 0, &len
) &&
319 (op
->src_tag
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) )))
320 SetupGetStringFieldW( &disk_ctx
, 2, op
->src_tag
, len
, NULL
);
322 if (!op
->src_path
&& !(op
->style
& SP_COPY_SOURCE_ABSOLUTE
))
325 if (!(op
->style
& SP_COPY_SOURCEPATH_ABSOLUTE
))
327 /* retrieve relative path for this disk */
328 if (!SetupGetStringFieldW( &disk_ctx
, 4, NULL
, 0, &len
)) len
= 0;
330 /* retrieve relative path for this file */
331 if (!SetupGetStringFieldW( &file_ctx
, 2, NULL
, 0, &len2
)) len2
= 0;
334 (op
->src_path
= HeapAlloc( GetProcessHeap(), 0, (len
+len2
)*sizeof(WCHAR
) )))
336 WCHAR
*ptr
= op
->src_path
;
339 SetupGetStringFieldW( &disk_ctx
, 4, op
->src_path
, len
, NULL
);
340 ptr
= op
->src_path
+ strlenW(op
->src_path
);
341 if (len2
&& ptr
> op
->src_path
&& ptr
[-1] != '\\') *ptr
++ = '\\';
343 if (!SetupGetStringFieldW( &file_ctx
, 2, ptr
, len2
, NULL
)) *ptr
= 0;
346 if (!op
->src_root
) op
->src_root
= PARSER_get_src_root(hinf
);
350 /***********************************************************************
351 * get_destination_dir
353 * Retrieve the destination dir for a given section.
355 static WCHAR
*get_destination_dir( HINF hinf
, const WCHAR
*section
)
357 static const WCHAR Dest
[] = {'D','e','s','t','i','n','a','t','i','o','n','D','i','r','s',0};
358 static const WCHAR Def
[] = {'D','e','f','a','u','l','t','D','e','s','t','D','i','r',0};
361 if (!SetupFindFirstLineW( hinf
, Dest
, section
, &context
) &&
362 !SetupFindFirstLineW( hinf
, Dest
, Def
, &context
)) return NULL
;
363 return PARSER_get_dest_dir( &context
);
367 static void (WINAPI
*pExtractFiles
)( LPSTR
, LPSTR
, DWORD
, DWORD
, DWORD
, DWORD
);
369 /***********************************************************************
370 * extract_cabinet_file
372 * Extract a file from a .cab file.
374 static BOOL
extract_cabinet_file( const WCHAR
*cabinet
, const WCHAR
*root
,
375 const WCHAR
*src
, const WCHAR
*dst
)
377 static const WCHAR extW
[] = {'.','c','a','b',0};
378 static HMODULE advpack
;
380 char *cab_path
, *cab_file
;
381 int len
= strlenW( cabinet
);
383 /* make sure the cabinet file has a .cab extension */
384 if (len
<= 4 || strcmpiW( cabinet
+ len
- 4, extW
)) return FALSE
;
387 if (!advpack
&& !(advpack
= LoadLibraryA( "advpack.dll" )))
389 ERR( "could not load advpack.dll\n" );
392 if (!(pExtractFiles
= (void *)GetProcAddress( advpack
, "ExtractFiles" )))
394 ERR( "could not find ExtractFiles in advpack.dll\n" );
399 if (!(cab_path
= strdupWtoA( root
))) return FALSE
;
400 len
= WideCharToMultiByte( CP_ACP
, 0, cabinet
, -1, NULL
, 0, NULL
, NULL
);
401 if (!(cab_file
= HeapAlloc( GetProcessHeap(), 0, strlen(cab_path
) + len
+ 1 )))
403 HeapFree( GetProcessHeap(), 0, cab_path
);
406 strcpy( cab_file
, cab_path
);
407 if (cab_file
[0] && cab_file
[strlen(cab_file
)-1] != '\\') strcat( cab_file
, "\\" );
408 WideCharToMultiByte( CP_ACP
, 0, cabinet
, -1, cab_file
+ strlen(cab_file
), len
, NULL
, NULL
);
409 FIXME( "awful hack: extracting cabinet %s\n", debugstr_a(cab_file
) );
410 pExtractFiles( cab_file
, cab_path
, 0, 0, 0, 0 );
411 HeapFree( GetProcessHeap(), 0, cab_file
);
412 HeapFree( GetProcessHeap(), 0, cab_path
);
413 return CopyFileW( src
, dst
, FALSE
/*FIXME*/ );
417 /***********************************************************************
418 * SetupOpenFileQueue (SETUPAPI.@)
420 HSPFILEQ WINAPI
SetupOpenFileQueue(void)
422 struct file_queue
*queue
;
424 if (!(queue
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*queue
))))
425 return INVALID_HANDLE_VALUE
;
430 /***********************************************************************
431 * SetupCloseFileQueue (SETUPAPI.@)
433 BOOL WINAPI
SetupCloseFileQueue( HSPFILEQ handle
)
435 struct file_queue
*queue
= handle
;
437 free_file_op_queue( &queue
->copy_queue
);
438 free_file_op_queue( &queue
->rename_queue
);
439 free_file_op_queue( &queue
->delete_queue
);
440 HeapFree( GetProcessHeap(), 0, queue
);
445 /***********************************************************************
446 * SetupQueueCopyIndirectA (SETUPAPI.@)
448 BOOL WINAPI
SetupQueueCopyIndirectA( PSP_FILE_COPY_PARAMS_A params
)
450 struct file_queue
*queue
= params
->QueueHandle
;
453 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
454 op
->style
= params
->CopyStyle
;
455 op
->src_root
= strdupAtoW( params
->SourceRootPath
);
456 op
->src_path
= strdupAtoW( params
->SourcePath
);
457 op
->src_file
= strdupAtoW( params
->SourceFilename
);
458 op
->src_descr
= strdupAtoW( params
->SourceDescription
);
459 op
->src_tag
= strdupAtoW( params
->SourceTagfile
);
460 op
->dst_path
= strdupAtoW( params
->TargetDirectory
);
461 op
->dst_file
= strdupAtoW( params
->TargetFilename
);
465 if (!op
->src_file
) op
->src_file
= op
->dst_file
;
466 if (params
->LayoutInf
)
468 get_src_file_info( params
->LayoutInf
, op
);
469 if (!op
->dst_path
) op
->dst_path
= get_destination_dir( params
->LayoutInf
, op
->dst_file
);
472 TRACE( "root=%s path=%s file=%s -> dir=%s file=%s descr=%s tag=%s\n",
473 debugstr_w(op
->src_root
), debugstr_w(op
->src_path
), debugstr_w(op
->src_file
),
474 debugstr_w(op
->dst_path
), debugstr_w(op
->dst_file
),
475 debugstr_w(op
->src_descr
), debugstr_w(op
->src_tag
) );
477 queue_file_op( &queue
->copy_queue
, op
);
482 /***********************************************************************
483 * SetupQueueCopyIndirectW (SETUPAPI.@)
485 BOOL WINAPI
SetupQueueCopyIndirectW( PSP_FILE_COPY_PARAMS_W params
)
487 struct file_queue
*queue
= params
->QueueHandle
;
490 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
491 op
->style
= params
->CopyStyle
;
492 op
->src_root
= strdupW( params
->SourceRootPath
);
493 op
->src_path
= strdupW( params
->SourcePath
);
494 op
->src_file
= strdupW( params
->SourceFilename
);
495 op
->src_descr
= strdupW( params
->SourceDescription
);
496 op
->src_tag
= strdupW( params
->SourceTagfile
);
497 op
->dst_path
= strdupW( params
->TargetDirectory
);
498 op
->dst_file
= strdupW( params
->TargetFilename
);
500 if (params
->SecurityDescriptor
)
501 ConvertStringSecurityDescriptorToSecurityDescriptorW( params
->SecurityDescriptor
, SDDL_REVISION_1
, &op
->dst_sd
, NULL
);
504 if (!op
->src_file
) op
->src_file
= op
->dst_file
;
505 if (params
->LayoutInf
)
507 get_src_file_info( params
->LayoutInf
, op
);
508 if (!op
->dst_path
) op
->dst_path
= get_destination_dir( params
->LayoutInf
, op
->dst_file
);
511 TRACE( "root=%s path=%s file=%s -> dir=%s file=%s descr=%s tag=%s\n",
512 debugstr_w(op
->src_root
), debugstr_w(op
->src_path
), debugstr_w(op
->src_file
),
513 debugstr_w(op
->dst_path
), debugstr_w(op
->dst_file
),
514 debugstr_w(op
->src_descr
), debugstr_w(op
->src_tag
) );
516 queue_file_op( &queue
->copy_queue
, op
);
521 /***********************************************************************
522 * SetupQueueCopyA (SETUPAPI.@)
524 BOOL WINAPI
SetupQueueCopyA( HSPFILEQ queue
, PCSTR src_root
, PCSTR src_path
, PCSTR src_file
,
525 PCSTR src_descr
, PCSTR src_tag
, PCSTR dst_dir
, PCSTR dst_file
,
528 SP_FILE_COPY_PARAMS_A params
;
530 params
.cbSize
= sizeof(params
);
531 params
.QueueHandle
= queue
;
532 params
.SourceRootPath
= src_root
;
533 params
.SourcePath
= src_path
;
534 params
.SourceFilename
= src_file
;
535 params
.SourceDescription
= src_descr
;
536 params
.SourceTagfile
= src_tag
;
537 params
.TargetDirectory
= dst_dir
;
538 params
.TargetFilename
= dst_file
;
539 params
.CopyStyle
= style
;
540 params
.LayoutInf
= 0;
541 params
.SecurityDescriptor
= NULL
;
542 return SetupQueueCopyIndirectA( ¶ms
);
546 /***********************************************************************
547 * SetupQueueCopyW (SETUPAPI.@)
549 BOOL WINAPI
SetupQueueCopyW( HSPFILEQ queue
, PCWSTR src_root
, PCWSTR src_path
, PCWSTR src_file
,
550 PCWSTR src_descr
, PCWSTR src_tag
, PCWSTR dst_dir
, PCWSTR dst_file
,
553 SP_FILE_COPY_PARAMS_W params
;
555 params
.cbSize
= sizeof(params
);
556 params
.QueueHandle
= queue
;
557 params
.SourceRootPath
= src_root
;
558 params
.SourcePath
= src_path
;
559 params
.SourceFilename
= src_file
;
560 params
.SourceDescription
= src_descr
;
561 params
.SourceTagfile
= src_tag
;
562 params
.TargetDirectory
= dst_dir
;
563 params
.TargetFilename
= dst_file
;
564 params
.CopyStyle
= style
;
565 params
.LayoutInf
= 0;
566 params
.SecurityDescriptor
= NULL
;
567 return SetupQueueCopyIndirectW( ¶ms
);
571 /***********************************************************************
572 * SetupQueueDefaultCopyA (SETUPAPI.@)
574 BOOL WINAPI
SetupQueueDefaultCopyA( HSPFILEQ queue
, HINF hinf
, PCSTR src_root
, PCSTR src_file
,
575 PCSTR dst_file
, DWORD style
)
577 SP_FILE_COPY_PARAMS_A params
;
579 params
.cbSize
= sizeof(params
);
580 params
.QueueHandle
= queue
;
581 params
.SourceRootPath
= src_root
;
582 params
.SourcePath
= NULL
;
583 params
.SourceFilename
= src_file
;
584 params
.SourceDescription
= NULL
;
585 params
.SourceTagfile
= NULL
;
586 params
.TargetDirectory
= NULL
;
587 params
.TargetFilename
= dst_file
;
588 params
.CopyStyle
= style
;
589 params
.LayoutInf
= hinf
;
590 params
.SecurityDescriptor
= NULL
;
591 return SetupQueueCopyIndirectA( ¶ms
);
595 /***********************************************************************
596 * SetupQueueDefaultCopyW (SETUPAPI.@)
598 BOOL WINAPI
SetupQueueDefaultCopyW( HSPFILEQ queue
, HINF hinf
, PCWSTR src_root
, PCWSTR src_file
,
599 PCWSTR dst_file
, DWORD style
)
601 SP_FILE_COPY_PARAMS_W params
;
603 params
.cbSize
= sizeof(params
);
604 params
.QueueHandle
= queue
;
605 params
.SourceRootPath
= src_root
;
606 params
.SourcePath
= NULL
;
607 params
.SourceFilename
= src_file
;
608 params
.SourceDescription
= NULL
;
609 params
.SourceTagfile
= NULL
;
610 params
.TargetDirectory
= NULL
;
611 params
.TargetFilename
= dst_file
;
612 params
.CopyStyle
= style
;
613 params
.LayoutInf
= hinf
;
614 params
.SecurityDescriptor
= NULL
;
615 return SetupQueueCopyIndirectW( ¶ms
);
619 /***********************************************************************
620 * SetupQueueDeleteA (SETUPAPI.@)
622 BOOL WINAPI
SetupQueueDeleteA( HSPFILEQ handle
, PCSTR part1
, PCSTR part2
)
624 struct file_queue
*queue
= handle
;
627 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
632 op
->src_descr
= NULL
;
634 op
->dst_path
= strdupAtoW( part1
);
635 op
->dst_file
= strdupAtoW( part2
);
637 queue_file_op( &queue
->delete_queue
, op
);
642 /***********************************************************************
643 * SetupQueueDeleteW (SETUPAPI.@)
645 BOOL WINAPI
SetupQueueDeleteW( HSPFILEQ handle
, PCWSTR part1
, PCWSTR part2
)
647 struct file_queue
*queue
= handle
;
650 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
655 op
->src_descr
= NULL
;
657 op
->dst_path
= strdupW( part1
);
658 op
->dst_file
= strdupW( part2
);
660 queue_file_op( &queue
->delete_queue
, op
);
665 /***********************************************************************
666 * SetupQueueRenameA (SETUPAPI.@)
668 BOOL WINAPI
SetupQueueRenameA( HSPFILEQ handle
, PCSTR SourcePath
, PCSTR SourceFilename
,
669 PCSTR TargetPath
, PCSTR TargetFilename
)
671 struct file_queue
*queue
= handle
;
674 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
677 op
->src_path
= strdupAtoW( SourcePath
);
678 op
->src_file
= strdupAtoW( SourceFilename
);
679 op
->src_descr
= NULL
;
681 op
->dst_path
= strdupAtoW( TargetPath
);
682 op
->dst_file
= strdupAtoW( TargetFilename
);
684 queue_file_op( &queue
->rename_queue
, op
);
689 /***********************************************************************
690 * SetupQueueRenameW (SETUPAPI.@)
692 BOOL WINAPI
SetupQueueRenameW( HSPFILEQ handle
, PCWSTR SourcePath
, PCWSTR SourceFilename
,
693 PCWSTR TargetPath
, PCWSTR TargetFilename
)
695 struct file_queue
*queue
= handle
;
698 if (!(op
= HeapAlloc( GetProcessHeap(), 0, sizeof(*op
) ))) return FALSE
;
701 op
->src_path
= strdupW( SourcePath
);
702 op
->src_file
= strdupW( SourceFilename
);
703 op
->src_descr
= NULL
;
705 op
->dst_path
= strdupW( TargetPath
);
706 op
->dst_file
= strdupW( TargetFilename
);
708 queue_file_op( &queue
->rename_queue
, op
);
713 /***********************************************************************
714 * SetupQueueCopySectionA (SETUPAPI.@)
716 BOOL WINAPI
SetupQueueCopySectionA( HSPFILEQ queue
, PCSTR src_root
, HINF hinf
, HINF hlist
,
717 PCSTR section
, DWORD style
)
719 UNICODE_STRING sectionW
;
722 if (!RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
724 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
728 ret
= SetupQueueCopySectionW( queue
, NULL
, hinf
, hlist
, sectionW
.Buffer
, style
);
732 if (RtlCreateUnicodeStringFromAsciiz( &srcW
, src_root
))
734 ret
= SetupQueueCopySectionW( queue
, srcW
.Buffer
, hinf
, hlist
, sectionW
.Buffer
, style
);
735 RtlFreeUnicodeString( &srcW
);
737 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
739 RtlFreeUnicodeString( §ionW
);
744 /***********************************************************************
745 * SetupQueueCopySectionW (SETUPAPI.@)
747 BOOL WINAPI
SetupQueueCopySectionW( HSPFILEQ queue
, PCWSTR src_root
, HINF hinf
, HINF hlist
,
748 PCWSTR section
, DWORD style
)
750 SP_FILE_COPY_PARAMS_W params
;
751 LPWSTR security_key
, security_descriptor
= NULL
;
752 INFCONTEXT context
, security_context
;
753 WCHAR dest
[MAX_PATH
], src
[MAX_PATH
];
758 TRACE( "hinf=%p/%p section=%s root=%s\n",
759 hinf
, hlist
, debugstr_w(section
), debugstr_w(src_root
) );
761 /* Check for .Security section */
762 security_key
= MyMalloc( (strlenW( section
) + strlenW( DotSecurity
)) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
) );
765 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
768 strcpyW( security_key
, section
);
769 strcatW( security_key
, DotSecurity
);
770 ret
= SetupFindFirstLineW( hinf
, security_key
, NULL
, &security_context
);
771 MyFree(security_key
);
774 if (!SetupGetLineTextW( &security_context
, NULL
, NULL
, NULL
, NULL
, 0, &required
))
776 security_descriptor
= MyMalloc( required
* sizeof(WCHAR
) );
777 if (!security_descriptor
)
779 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
782 if (!SetupGetLineTextW( &security_context
, NULL
, NULL
, NULL
, security_descriptor
, required
, NULL
))
784 MyFree( security_descriptor
);
789 params
.cbSize
= sizeof(params
);
790 params
.QueueHandle
= queue
;
791 params
.SourceRootPath
= src_root
;
792 params
.SourcePath
= NULL
;
793 params
.SourceDescription
= NULL
;
794 params
.SourceTagfile
= NULL
;
795 params
.TargetFilename
= dest
;
796 params
.CopyStyle
= style
;
797 params
.LayoutInf
= hinf
;
798 params
.SecurityDescriptor
= security_descriptor
;
801 if (!hlist
) hlist
= hinf
;
802 if (!hinf
) hinf
= hlist
;
803 if (!SetupFindFirstLineW( hlist
, section
, NULL
, &context
)) goto done
;
804 if (!(params
.TargetDirectory
= get_destination_dir( hinf
, section
))) goto done
;
807 if (!SetupGetStringFieldW( &context
, 1, dest
, sizeof(dest
)/sizeof(WCHAR
), NULL
))
809 if (!SetupGetStringFieldW( &context
, 2, src
, sizeof(src
)/sizeof(WCHAR
), NULL
)) *src
= 0;
810 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0; /* FIXME */
812 params
.SourceFilename
= *src
? src
: NULL
;
813 if (!SetupQueueCopyIndirectW( ¶ms
)) goto done
;
814 } while (SetupFindNextLine( &context
, &context
));
818 if (security_descriptor
)
819 MyFree( security_descriptor
);
824 /***********************************************************************
825 * SetupQueueDeleteSectionA (SETUPAPI.@)
827 BOOL WINAPI
SetupQueueDeleteSectionA( HSPFILEQ queue
, HINF hinf
, HINF hlist
, PCSTR section
)
829 UNICODE_STRING sectionW
;
832 if (RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
834 ret
= SetupQueueDeleteSectionW( queue
, hinf
, hlist
, sectionW
.Buffer
);
835 RtlFreeUnicodeString( §ionW
);
837 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
842 /***********************************************************************
843 * SetupQueueDeleteSectionW (SETUPAPI.@)
845 BOOL WINAPI
SetupQueueDeleteSectionW( HSPFILEQ queue
, HINF hinf
, HINF hlist
, PCWSTR section
)
849 WCHAR buffer
[MAX_PATH
];
853 TRACE( "hinf=%p/%p section=%s\n", hinf
, hlist
, debugstr_w(section
) );
855 if (!hlist
) hlist
= hinf
;
856 if (!SetupFindFirstLineW( hlist
, section
, NULL
, &context
)) return FALSE
;
857 if (!(dest_dir
= get_destination_dir( hinf
, section
))) return FALSE
;
860 if (!SetupGetStringFieldW( &context
, 1, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
862 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0;
863 if (!SetupQueueDeleteW( queue
, dest_dir
, buffer
)) goto done
;
864 } while (SetupFindNextLine( &context
, &context
));
868 HeapFree( GetProcessHeap(), 0, dest_dir
);
873 /***********************************************************************
874 * SetupQueueRenameSectionA (SETUPAPI.@)
876 BOOL WINAPI
SetupQueueRenameSectionA( HSPFILEQ queue
, HINF hinf
, HINF hlist
, PCSTR section
)
878 UNICODE_STRING sectionW
;
881 if (RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
883 ret
= SetupQueueRenameSectionW( queue
, hinf
, hlist
, sectionW
.Buffer
);
884 RtlFreeUnicodeString( §ionW
);
886 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
891 /***********************************************************************
892 * SetupQueueRenameSectionW (SETUPAPI.@)
894 BOOL WINAPI
SetupQueueRenameSectionW( HSPFILEQ queue
, HINF hinf
, HINF hlist
, PCWSTR section
)
898 WCHAR src
[MAX_PATH
], dst
[MAX_PATH
];
901 TRACE( "hinf=%p/%p section=%s\n", hinf
, hlist
, debugstr_w(section
) );
903 if (!hlist
) hlist
= hinf
;
904 if (!SetupFindFirstLineW( hlist
, section
, NULL
, &context
)) return FALSE
;
905 if (!(dest_dir
= get_destination_dir( hinf
, section
))) return FALSE
;
908 if (!SetupGetStringFieldW( &context
, 1, dst
, sizeof(dst
)/sizeof(WCHAR
), NULL
))
910 if (!SetupGetStringFieldW( &context
, 2, src
, sizeof(src
)/sizeof(WCHAR
), NULL
))
912 if (!SetupQueueRenameW( queue
, dest_dir
, src
, NULL
, dst
)) goto done
;
913 } while (SetupFindNextLine( &context
, &context
));
917 HeapFree( GetProcessHeap(), 0, dest_dir
);
922 /***********************************************************************
923 * SetupCommitFileQueueA (SETUPAPI.@)
925 BOOL WINAPI
SetupCommitFileQueueA( HWND owner
, HSPFILEQ queue
, PSP_FILE_CALLBACK_A handler
,
928 struct callback_WtoA_context ctx
;
930 ctx
.orig_context
= context
;
931 ctx
.orig_handler
= handler
;
932 return SetupCommitFileQueueW( owner
, queue
, QUEUE_callback_WtoA
, &ctx
);
936 /***********************************************************************
939 * Recursively create all directories in the path.
941 static BOOL
create_full_pathW(const WCHAR
*path
)
947 new_path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(path
) + 1) * sizeof(WCHAR
));
948 strcpyW(new_path
, path
);
950 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
951 new_path
[len
- 1] = 0;
953 while(!CreateDirectoryW(new_path
, NULL
))
956 DWORD last_error
= GetLastError();
958 if(last_error
== ERROR_ALREADY_EXISTS
)
961 if(last_error
!= ERROR_PATH_NOT_FOUND
)
967 if(!(slash
= strrchrW(new_path
, '\\')))
973 len
= slash
- new_path
;
975 if(!create_full_pathW(new_path
))
980 new_path
[len
] = '\\';
983 HeapFree(GetProcessHeap(), 0, new_path
);
987 static BOOL
do_file_copyW( LPCWSTR source
, LPCWSTR target
, DWORD style
,
988 PSP_FILE_CALLBACK_W handler
, PVOID context
)
992 WCHAR TempFile
[MAX_PATH
];
995 WCHAR TempPath
[MAX_PATH
];
997 TRACE("copy %s to %s style 0x%x\n",debugstr_w(source
),debugstr_w(target
),style
);
999 hSource
= LZOpenFileW((LPWSTR
)source
, &OfStruct
, OF_READ
);
1003 /* Get a temp file name */
1004 GetTempPathW(sizeof(TempPath
) / sizeof(WCHAR
), TempPath
);
1005 GetTempFileNameW(TempPath
, L
"", 0, TempFile
);
1007 /* Extract the compressed file to a temp location */
1008 hTemp
= LZOpenFileW(TempFile
, &OfStruct
, OF_CREATE
);
1009 LZCopy(hSource
, hTemp
);
1013 /* before copy processing */
1014 if (style
& SP_COPY_REPLACEONLY
)
1016 if (GetFileAttributesW(target
) == INVALID_FILE_ATTRIBUTES
)
1019 if (style
& (SP_COPY_NEWER_OR_SAME
| SP_COPY_NEWER_ONLY
| SP_COPY_FORCE_NEWER
))
1021 DWORD VersionSizeSource
=0;
1022 DWORD VersionSizeTarget
=0;
1026 * This is sort of an interesting workaround. You see, calling
1027 * GetVersionInfoSize on a builtin dll loads that dll into memory
1028 * and we do not properly unload builtin dlls.. so we effectively
1029 * lock into memory all the targets we are replacing. This leads
1030 * to problems when we try to register the replaced dlls.
1032 * So I will test for the existence of the files first so that
1033 * we just basically unconditionally replace the builtin versions.
1035 if ((GetFileAttributesW(target
) != INVALID_FILE_ATTRIBUTES
) &&
1036 (GetFileAttributesW(TempFile
) != INVALID_FILE_ATTRIBUTES
))
1038 VersionSizeSource
= GetFileVersionInfoSizeW(TempFile
,&zero
);
1039 VersionSizeTarget
= GetFileVersionInfoSizeW((LPWSTR
)target
,&zero
);
1042 TRACE("SizeTarget %i ... SizeSource %i\n",VersionSizeTarget
,
1045 if (VersionSizeSource
&& VersionSizeTarget
)
1047 LPVOID VersionSource
;
1048 LPVOID VersionTarget
;
1049 VS_FIXEDFILEINFO
*TargetInfo
;
1050 VS_FIXEDFILEINFO
*SourceInfo
;
1052 WCHAR SubBlock
[2]={'\\',0};
1055 VersionSource
= HeapAlloc(GetProcessHeap(),0,VersionSizeSource
);
1056 VersionTarget
= HeapAlloc(GetProcessHeap(),0,VersionSizeTarget
);
1058 ret
= GetFileVersionInfoW(TempFile
,0,VersionSizeSource
,VersionSource
);
1060 ret
= GetFileVersionInfoW((LPWSTR
)target
, 0, VersionSizeTarget
,
1065 ret
= VerQueryValueW(VersionSource
, SubBlock
,
1066 (LPVOID
*)&SourceInfo
, &length
);
1068 ret
= VerQueryValueW(VersionTarget
, SubBlock
,
1069 (LPVOID
*)&TargetInfo
, &length
);
1073 FILEPATHS_W filepaths
;
1075 TRACE("Versions: Source %i.%i target %i.%i\n",
1076 SourceInfo
->dwFileVersionMS
, SourceInfo
->dwFileVersionLS
,
1077 TargetInfo
->dwFileVersionMS
, TargetInfo
->dwFileVersionLS
);
1079 /* used in case of notification */
1080 filepaths
.Target
= target
;
1081 filepaths
.Source
= source
;
1082 filepaths
.Win32Error
= 0;
1083 filepaths
.Flags
= 0;
1085 if (TargetInfo
->dwFileVersionMS
> SourceInfo
->dwFileVersionMS
)
1088 docopy
= handler (context
, SPFILENOTIFY_TARGETNEWER
, (UINT_PTR
)&filepaths
, 0);
1092 else if ((TargetInfo
->dwFileVersionMS
== SourceInfo
->dwFileVersionMS
)
1093 && (TargetInfo
->dwFileVersionLS
> SourceInfo
->dwFileVersionLS
))
1096 docopy
= handler (context
, SPFILENOTIFY_TARGETNEWER
, (UINT_PTR
)&filepaths
, 0);
1100 else if ((style
& SP_COPY_NEWER_ONLY
) &&
1101 (TargetInfo
->dwFileVersionMS
==
1102 SourceInfo
->dwFileVersionMS
)
1103 &&(TargetInfo
->dwFileVersionLS
==
1104 SourceInfo
->dwFileVersionLS
))
1107 docopy
= handler (context
, SPFILENOTIFY_TARGETNEWER
, (UINT_PTR
)&filepaths
, 0);
1113 HeapFree(GetProcessHeap(),0,VersionSource
);
1114 HeapFree(GetProcessHeap(),0,VersionTarget
);
1117 if (style
& (SP_COPY_NOOVERWRITE
| SP_COPY_FORCE_NOOVERWRITE
))
1119 if (GetFileAttributesW(target
) != INVALID_FILE_ATTRIBUTES
)
1121 FIXME("Notify user target file exists\n");
1125 if (style
& (SP_COPY_NODECOMP
| SP_COPY_LANGUAGEAWARE
| SP_COPY_FORCE_IN_USE
|
1126 SP_COPY_IN_USE_NEEDS_REBOOT
| SP_COPY_NOSKIP
| SP_COPY_WARNIFSKIP
))
1128 ERR("Unsupported style(s) 0x%x\n",style
);
1133 rc
= MoveFileExW(TempFile
,target
,MOVEFILE_REPLACE_EXISTING
);
1134 TRACE("Did copy... rc was %i\n",rc
);
1137 /* after copy processing */
1138 if (style
& SP_COPY_DELETESOURCE
)
1141 DeleteFileW(source
);
1147 /***********************************************************************
1148 * SetupInstallFileA (SETUPAPI.@)
1150 BOOL WINAPI
SetupInstallFileA( HINF hinf
, PINFCONTEXT inf_context
, PCSTR source
, PCSTR root
,
1151 PCSTR dest
, DWORD style
, PSP_FILE_CALLBACK_A handler
, PVOID context
)
1154 struct callback_WtoA_context ctx
;
1155 UNICODE_STRING sourceW
, rootW
, destW
;
1157 TRACE("%p %p %s %s %s %x %p %p\n", hinf
, inf_context
, debugstr_a(source
), debugstr_a(root
),
1158 debugstr_a(dest
), style
, handler
, context
);
1160 sourceW
.Buffer
= rootW
.Buffer
= destW
.Buffer
= NULL
;
1161 if (source
&& !RtlCreateUnicodeStringFromAsciiz( &sourceW
, source
))
1163 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1166 if (root
&& !RtlCreateUnicodeStringFromAsciiz( &rootW
, root
))
1168 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1171 if (dest
&& !RtlCreateUnicodeStringFromAsciiz( &destW
, dest
))
1173 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1177 ctx
.orig_context
= context
;
1178 ctx
.orig_handler
= handler
;
1180 ret
= SetupInstallFileW( hinf
, inf_context
, sourceW
.Buffer
, rootW
.Buffer
, destW
.Buffer
, style
, QUEUE_callback_WtoA
, &ctx
);
1183 RtlFreeUnicodeString( &sourceW
);
1184 RtlFreeUnicodeString( &rootW
);
1185 RtlFreeUnicodeString( &destW
);
1189 /***********************************************************************
1190 * SetupInstallFileW (SETUPAPI.@)
1192 BOOL WINAPI
SetupInstallFileW( HINF hinf
, PINFCONTEXT inf_context
, PCWSTR source
, PCWSTR root
,
1193 PCWSTR dest
, DWORD style
, PSP_FILE_CALLBACK_W handler
, PVOID context
)
1195 static const WCHAR CopyFiles
[] = {'C','o','p','y','F','i','l','e','s',0};
1197 BOOL ret
, absolute
= (root
&& *root
&& !(style
& SP_COPY_SOURCE_ABSOLUTE
));
1198 WCHAR
*buffer
, *p
, *inf_source
= NULL
;
1201 TRACE("%p %p %s %s %s %x %p %p\n", hinf
, inf_context
, debugstr_w(source
), debugstr_w(root
),
1202 debugstr_w(dest
), style
, handler
, context
);
1211 if (!SetupFindFirstLineW( hinf
, CopyFiles
, NULL
, inf_context
)) return FALSE
;
1213 if (!SetupGetStringFieldW( inf_context
, 1, NULL
, 0, (PDWORD
) &len
)) return FALSE
;
1214 if (!(inf_source
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1216 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1219 if (!SetupGetStringFieldW( inf_context
, 1, inf_source
, len
, NULL
))
1221 HeapFree( GetProcessHeap(), 0, inf_source
);
1224 source
= inf_source
;
1228 SetLastError( ERROR_INVALID_PARAMETER
);
1232 len
= strlenW( source
) + 1;
1233 if (absolute
) len
+= strlenW( root
) + 1;
1235 if (!(p
= buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1237 HeapFree( GetProcessHeap(), 0, inf_source
);
1238 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1244 strcpyW( buffer
, root
);
1245 p
+= strlenW( buffer
);
1246 if (p
[-1] != '\\') *p
++ = '\\';
1248 while (*source
== '\\') source
++;
1249 strcpyW( p
, source
);
1251 ret
= do_file_copyW( buffer
, dest
, style
, handler
, context
);
1253 HeapFree( GetProcessHeap(), 0, inf_source
);
1254 HeapFree( GetProcessHeap(), 0, buffer
);
1258 /***********************************************************************
1259 * SetupCommitFileQueueW (SETUPAPI.@)
1261 BOOL WINAPI
SetupCommitFileQueueW( HWND owner
, HSPFILEQ handle
, PSP_FILE_CALLBACK_W handler
,
1264 struct file_queue
*queue
= handle
;
1266 BOOL result
= FALSE
;
1270 paths
.Source
= paths
.Target
= NULL
;
1272 if (!queue
->copy_queue
.count
&& !queue
->delete_queue
.count
&& !queue
->rename_queue
.count
)
1273 return TRUE
; /* nothing to do */
1275 if (!handler( context
, SPFILENOTIFY_STARTQUEUE
, (UINT_PTR
)owner
, 0 )) return FALSE
;
1277 /* perform deletes */
1279 if (queue
->delete_queue
.count
)
1281 if (!(handler( context
, SPFILENOTIFY_STARTSUBQUEUE
, FILEOP_DELETE
,
1282 queue
->delete_queue
.count
))) goto done
;
1283 for (op
= queue
->delete_queue
.head
; op
; op
= op
->next
)
1285 build_filepathsW( op
, &paths
);
1286 op_result
= handler( context
, SPFILENOTIFY_STARTDELETE
, (UINT_PTR
)&paths
, FILEOP_DELETE
);
1287 if (op_result
== FILEOP_ABORT
) goto done
;
1288 while (op_result
== FILEOP_DOIT
)
1290 TRACE( "deleting file %s\n", debugstr_w(paths
.Target
) );
1291 if (DeleteFileW( paths
.Target
)) break; /* success */
1292 paths
.Win32Error
= GetLastError();
1293 op_result
= handler( context
, SPFILENOTIFY_DELETEERROR
, (UINT_PTR
)&paths
, 0 );
1294 if (op_result
== FILEOP_ABORT
) goto done
;
1296 handler( context
, SPFILENOTIFY_ENDDELETE
, (UINT_PTR
)&paths
, 0 );
1298 handler( context
, SPFILENOTIFY_ENDSUBQUEUE
, FILEOP_DELETE
, 0 );
1301 /* perform renames */
1303 if (queue
->rename_queue
.count
)
1305 if (!(handler( context
, SPFILENOTIFY_STARTSUBQUEUE
, FILEOP_RENAME
,
1306 queue
->rename_queue
.count
))) goto done
;
1307 for (op
= queue
->rename_queue
.head
; op
; op
= op
->next
)
1309 build_filepathsW( op
, &paths
);
1310 op_result
= handler( context
, SPFILENOTIFY_STARTRENAME
, (UINT_PTR
)&paths
, FILEOP_RENAME
);
1311 if (op_result
== FILEOP_ABORT
) goto done
;
1312 while (op_result
== FILEOP_DOIT
)
1314 TRACE( "renaming file %s -> %s\n",
1315 debugstr_w(paths
.Source
), debugstr_w(paths
.Target
) );
1316 if (MoveFileW( paths
.Source
, paths
.Target
)) break; /* success */
1317 paths
.Win32Error
= GetLastError();
1318 op_result
= handler( context
, SPFILENOTIFY_RENAMEERROR
, (UINT_PTR
)&paths
, 0 );
1319 if (op_result
== FILEOP_ABORT
) goto done
;
1321 handler( context
, SPFILENOTIFY_ENDRENAME
, (UINT_PTR
)&paths
, 0 );
1323 handler( context
, SPFILENOTIFY_ENDSUBQUEUE
, FILEOP_RENAME
, 0 );
1326 /* perform copies */
1328 if (queue
->copy_queue
.count
)
1330 if (!(handler( context
, SPFILENOTIFY_STARTSUBQUEUE
, FILEOP_COPY
,
1331 queue
->copy_queue
.count
))) goto done
;
1332 for (op
= queue
->copy_queue
.head
; op
; op
= op
->next
)
1334 WCHAR newpath
[MAX_PATH
];
1336 build_filepathsW( op
, &paths
);
1337 op_result
= handler( context
, SPFILENOTIFY_STARTCOPY
, (UINT_PTR
)&paths
, FILEOP_COPY
);
1338 if (op_result
== FILEOP_ABORT
) goto done
;
1339 if (op_result
== FILEOP_NEWPATH
) op_result
= FILEOP_DOIT
;
1340 while (op_result
== FILEOP_DOIT
|| op_result
== FILEOP_NEWPATH
)
1342 TRACE( "copying file %s -> %s\n",
1343 debugstr_w( op_result
== FILEOP_NEWPATH
? newpath
: paths
.Source
),
1344 debugstr_w(paths
.Target
) );
1347 if (!create_full_pathW( op
->dst_path
))
1349 paths
.Win32Error
= GetLastError();
1350 op_result
= handler( context
, SPFILENOTIFY_COPYERROR
,
1351 (UINT_PTR
)&paths
, (UINT_PTR
)newpath
);
1352 if (op_result
== FILEOP_ABORT
) goto done
;
1355 if (do_file_copyW( op_result
== FILEOP_NEWPATH
? newpath
: paths
.Source
,
1356 paths
.Target
, op
->style
, handler
, context
)) break; /* success */
1357 /* try to extract it from the cabinet file */
1360 if (extract_cabinet_file( op
->src_tag
, op
->src_root
,
1361 paths
.Source
, paths
.Target
)) break;
1363 paths
.Win32Error
= GetLastError();
1364 op_result
= handler( context
, SPFILENOTIFY_COPYERROR
,
1365 (UINT_PTR
)&paths
, (UINT_PTR
)newpath
);
1366 if (op_result
== FILEOP_ABORT
) goto done
;
1370 PSID psidOwner
= NULL
, psidGroup
= NULL
;
1371 PACL pDacl
= NULL
, pSacl
= NULL
;
1372 SECURITY_INFORMATION security_info
= 0;
1373 BOOL present
, dummy
;
1375 if (GetSecurityDescriptorOwner( op
->dst_sd
, &psidOwner
, &dummy
) && psidOwner
)
1376 security_info
|= OWNER_SECURITY_INFORMATION
;
1377 if (GetSecurityDescriptorGroup( op
->dst_sd
, &psidGroup
, &dummy
) && psidGroup
)
1378 security_info
|= GROUP_SECURITY_INFORMATION
;
1379 if (GetSecurityDescriptorDacl( op
->dst_sd
, &present
, &pDacl
, &dummy
))
1380 security_info
|= DACL_SECURITY_INFORMATION
;
1381 if (GetSecurityDescriptorSacl( op
->dst_sd
, &present
, &pSacl
, &dummy
))
1382 security_info
|= DACL_SECURITY_INFORMATION
;
1383 SetNamedSecurityInfoW( (LPWSTR
)paths
.Target
, SE_FILE_OBJECT
, security_info
,
1384 psidOwner
, psidGroup
, pDacl
, pSacl
);
1385 /* Yes, ignore the return code... */
1387 handler( context
, SPFILENOTIFY_ENDCOPY
, (UINT_PTR
)&paths
, 0 );
1389 handler( context
, SPFILENOTIFY_ENDSUBQUEUE
, FILEOP_COPY
, 0 );
1396 handler( context
, SPFILENOTIFY_ENDQUEUE
, result
, 0 );
1397 HeapFree( GetProcessHeap(), 0, (void *)paths
.Source
);
1398 HeapFree( GetProcessHeap(), 0, (void *)paths
.Target
);
1403 /***********************************************************************
1404 * SetupScanFileQueueA (SETUPAPI.@)
1406 BOOL WINAPI
SetupScanFileQueueA( HSPFILEQ handle
, DWORD flags
, HWND window
,
1407 PSP_FILE_CALLBACK_A handler
, PVOID context
, PDWORD result
)
1409 struct callback_WtoA_context ctx
;
1411 TRACE("%p %x %p %p %p %p\n", handle
, flags
, window
, handler
, context
, result
);
1413 ctx
.orig_context
= context
;
1414 ctx
.orig_handler
= handler
;
1416 return SetupScanFileQueueW( handle
, flags
, window
, QUEUE_callback_WtoA
, &ctx
, result
);
1420 /***********************************************************************
1421 * SetupScanFileQueueW (SETUPAPI.@)
1423 BOOL WINAPI
SetupScanFileQueueW( HSPFILEQ handle
, DWORD flags
, HWND window
,
1424 PSP_FILE_CALLBACK_W handler
, PVOID context
, PDWORD result
)
1426 struct file_queue
*queue
= handle
;
1429 UINT notification
= 0;
1432 TRACE("%p %x %p %p %p %p\n", handle
, flags
, window
, handler
, context
, result
);
1436 if (!queue
->copy_queue
.count
) return TRUE
;
1438 if (flags
& SPQ_SCAN_USE_CALLBACK
) notification
= SPFILENOTIFY_QUEUESCAN
;
1439 else if (flags
& SPQ_SCAN_USE_CALLBACKEX
) notification
= SPFILENOTIFY_QUEUESCAN_EX
;
1441 if (flags
& ~(SPQ_SCAN_USE_CALLBACK
| SPQ_SCAN_USE_CALLBACKEX
))
1443 FIXME("flags %x not fully implemented\n", flags
);
1446 paths
.Source
= paths
.Target
= NULL
;
1448 for (op
= queue
->copy_queue
.head
; op
; op
= op
->next
)
1450 build_filepathsW( op
, &paths
);
1451 switch (notification
)
1453 case SPFILENOTIFY_QUEUESCAN
:
1454 /* FIXME: handle delay flag */
1455 if (handler( context
, notification
, (UINT_PTR
)paths
.Target
, 0 )) goto done
;
1457 case SPFILENOTIFY_QUEUESCAN_EX
:
1458 if (handler( context
, notification
, (UINT_PTR
)&paths
, 0 )) goto done
;
1461 ret
= TRUE
; goto done
;
1468 HeapFree( GetProcessHeap(), 0, (void *)paths
.Source
);
1469 HeapFree( GetProcessHeap(), 0, (void *)paths
.Target
);
1474 /***********************************************************************
1475 * SetupGetFileQueueCount (SETUPAPI.@)
1477 BOOL WINAPI
SetupGetFileQueueCount( HSPFILEQ handle
, UINT op
, PUINT result
)
1479 struct file_queue
*queue
= handle
;
1484 *result
= queue
->copy_queue
.count
;
1487 *result
= queue
->rename_queue
.count
;
1490 *result
= queue
->delete_queue
.count
;
1497 /***********************************************************************
1498 * SetupGetFileQueueFlags (SETUPAPI.@)
1500 BOOL WINAPI
SetupGetFileQueueFlags( HSPFILEQ handle
, PDWORD flags
)
1502 struct file_queue
*queue
= handle
;
1503 *flags
= queue
->flags
;
1508 /***********************************************************************
1509 * SetupSetFileQueueFlags (SETUPAPI.@)
1511 BOOL WINAPI
SetupSetFileQueueFlags( HSPFILEQ handle
, DWORD mask
, DWORD flags
)
1513 struct file_queue
*queue
= handle
;
1514 queue
->flags
= (queue
->flags
& ~mask
) | flags
;
1519 /***********************************************************************
1520 * SetupSetFileQueueAlternatePlatformA (SETUPAPI.@)
1522 BOOL WINAPI
SetupSetFileQueueAlternatePlatformA(HSPFILEQ handle
, PSP_ALTPLATFORM_INFO platform
, PCSTR catalogfile
)
1524 FIXME("(%p, %p, %s) stub!\n", handle
, platform
, debugstr_a(catalogfile
));
1529 /***********************************************************************
1530 * SetupSetFileQueueAlternatePlatformW (SETUPAPI.@)
1532 BOOL WINAPI
SetupSetFileQueueAlternatePlatformW(HSPFILEQ handle
, PSP_ALTPLATFORM_INFO platform
, PCWSTR catalogfile
)
1534 FIXME("(%p, %p, %s) stub!\n", handle
, platform
, debugstr_w(catalogfile
));
1539 /***********************************************************************
1540 * SetupInitDefaultQueueCallback (SETUPAPI.@)
1542 PVOID WINAPI
SetupInitDefaultQueueCallback( HWND owner
)
1544 return SetupInitDefaultQueueCallbackEx( owner
, 0, 0, 0, NULL
);
1548 /***********************************************************************
1549 * SetupInitDefaultQueueCallbackEx (SETUPAPI.@)
1551 PVOID WINAPI
SetupInitDefaultQueueCallbackEx( HWND owner
, HWND progress
, UINT msg
,
1552 DWORD reserved1
, PVOID reserved2
)
1554 struct default_callback_context
*context
;
1556 if ((context
= HeapAlloc( GetProcessHeap(), 0, sizeof(*context
) )))
1558 context
->owner
= owner
;
1559 context
->progress
= progress
;
1560 context
->message
= msg
;
1566 /***********************************************************************
1567 * SetupTermDefaultQueueCallback (SETUPAPI.@)
1569 void WINAPI
SetupTermDefaultQueueCallback( PVOID context
)
1571 HeapFree( GetProcessHeap(), 0, context
);
1575 /***********************************************************************
1576 * SetupDefaultQueueCallbackA (SETUPAPI.@)
1578 UINT WINAPI
SetupDefaultQueueCallbackA( PVOID context
, UINT notification
,
1579 UINT_PTR param1
, UINT_PTR param2
)
1581 FILEPATHS_A
*paths
= (FILEPATHS_A
*)param1
;
1582 struct default_callback_context
*ctx
= (struct default_callback_context
*)context
;
1584 switch(notification
)
1586 case SPFILENOTIFY_STARTQUEUE
:
1587 TRACE( "start queue\n" );
1589 case SPFILENOTIFY_ENDQUEUE
:
1590 TRACE( "end queue\n" );
1592 case SPFILENOTIFY_STARTSUBQUEUE
:
1593 TRACE( "start subqueue %ld count %ld\n", param1
, param2
);
1595 case SPFILENOTIFY_ENDSUBQUEUE
:
1596 TRACE( "end subqueue %ld\n", param1
);
1598 case SPFILENOTIFY_STARTDELETE
:
1599 TRACE( "start delete %s\n", debugstr_a(paths
->Target
) );
1601 case SPFILENOTIFY_ENDDELETE
:
1602 TRACE( "end delete %s\n", debugstr_a(paths
->Target
) );
1604 case SPFILENOTIFY_DELETEERROR
:
1605 /*Windows Ignores attempts to delete files / folders which do not exist*/
1606 if ((paths
->Win32Error
!= ERROR_FILE_NOT_FOUND
) && (paths
->Win32Error
!= ERROR_PATH_NOT_FOUND
))
1607 SetupDeleteErrorA(ctx
->owner
, NULL
, paths
->Target
, paths
->Win32Error
, 0);
1609 case SPFILENOTIFY_STARTRENAME
:
1610 TRACE( "start rename %s -> %s\n", debugstr_a(paths
->Source
), debugstr_a(paths
->Target
) );
1612 case SPFILENOTIFY_ENDRENAME
:
1613 TRACE( "end rename %s -> %s\n", debugstr_a(paths
->Source
), debugstr_a(paths
->Target
) );
1615 case SPFILENOTIFY_RENAMEERROR
:
1616 SetupRenameErrorA(ctx
->owner
, NULL
, paths
->Source
, paths
->Target
, paths
->Win32Error
, 0);
1618 case SPFILENOTIFY_STARTCOPY
:
1619 TRACE( "start copy %s -> %s\n", debugstr_a(paths
->Source
), debugstr_a(paths
->Target
) );
1621 case SPFILENOTIFY_ENDCOPY
:
1622 TRACE( "end copy %s -> %s\n", debugstr_a(paths
->Source
), debugstr_a(paths
->Target
) );
1624 case SPFILENOTIFY_COPYERROR
:
1625 ERR( "copy error %d %s -> %s\n", paths
->Win32Error
,
1626 debugstr_a(paths
->Source
), debugstr_a(paths
->Target
) );
1628 case SPFILENOTIFY_NEEDMEDIA
:
1629 TRACE( "need media\n" );
1632 FIXME( "notification %d params %lx,%lx\n", notification
, param1
, param2
);
1639 /***********************************************************************
1640 * SetupDefaultQueueCallbackW (SETUPAPI.@)
1642 UINT WINAPI
SetupDefaultQueueCallbackW( PVOID context
, UINT notification
,
1643 UINT_PTR param1
, UINT_PTR param2
)
1645 FILEPATHS_W
*paths
= (FILEPATHS_W
*)param1
;
1646 struct default_callback_context
*ctx
= (struct default_callback_context
*)context
;
1648 switch(notification
)
1650 case SPFILENOTIFY_STARTQUEUE
:
1651 TRACE( "start queue\n" );
1653 case SPFILENOTIFY_ENDQUEUE
:
1654 TRACE( "end queue\n" );
1656 case SPFILENOTIFY_STARTSUBQUEUE
:
1657 TRACE( "start subqueue %ld count %ld\n", param1
, param2
);
1659 case SPFILENOTIFY_ENDSUBQUEUE
:
1660 TRACE( "end subqueue %ld\n", param1
);
1662 case SPFILENOTIFY_STARTDELETE
:
1663 TRACE( "start delete %s\n", debugstr_w(paths
->Target
) );
1665 case SPFILENOTIFY_ENDDELETE
:
1666 TRACE( "end delete %s\n", debugstr_w(paths
->Target
) );
1668 case SPFILENOTIFY_DELETEERROR
:
1669 /*Windows Ignores attempts to delete files / folders which do not exist*/
1670 if ((paths
->Win32Error
!= ERROR_FILE_NOT_FOUND
) && (paths
->Win32Error
!= ERROR_PATH_NOT_FOUND
))
1671 SetupDeleteErrorW(ctx
->owner
, NULL
, paths
->Target
, paths
->Win32Error
, 0);
1673 case SPFILENOTIFY_STARTRENAME
:
1674 SetupRenameErrorW(ctx
->owner
, NULL
, paths
->Source
, paths
->Target
, paths
->Win32Error
, 0);
1676 case SPFILENOTIFY_ENDRENAME
:
1677 TRACE( "end rename %s -> %s\n", debugstr_w(paths
->Source
), debugstr_w(paths
->Target
) );
1679 case SPFILENOTIFY_RENAMEERROR
:
1680 ERR( "rename error %d %s -> %s\n", paths
->Win32Error
,
1681 debugstr_w(paths
->Source
), debugstr_w(paths
->Target
) );
1683 case SPFILENOTIFY_STARTCOPY
:
1684 TRACE( "start copy %s -> %s\n", debugstr_w(paths
->Source
), debugstr_w(paths
->Target
) );
1686 case SPFILENOTIFY_ENDCOPY
:
1687 TRACE( "end copy %s -> %s\n", debugstr_w(paths
->Source
), debugstr_w(paths
->Target
) );
1689 case SPFILENOTIFY_COPYERROR
:
1690 ERR( "copy error %d %s -> %s\n", paths
->Win32Error
,
1691 debugstr_w(paths
->Source
), debugstr_w(paths
->Target
) );
1693 case SPFILENOTIFY_NEEDMEDIA
:
1694 TRACE( "need media\n" );
1697 FIXME( "notification %d params %lx,%lx\n", notification
, param1
, param2
);
1703 /***********************************************************************
1704 * SetupDeleteErrorA (SETUPAPI.@)
1707 UINT WINAPI
SetupDeleteErrorA( HWND parent
, PCSTR dialogTitle
, PCSTR file
,
1708 UINT w32error
, DWORD style
)
1710 FIXME( "stub: (Error Number %d when attempting to delete %s)\n",
1711 w32error
, debugstr_a(file
) );
1712 return DPROMPT_SKIPFILE
;
1715 /***********************************************************************
1716 * SetupDeleteErrorW (SETUPAPI.@)
1719 UINT WINAPI
SetupDeleteErrorW( HWND parent
, PCWSTR dialogTitle
, PCWSTR file
,
1720 UINT w32error
, DWORD style
)
1722 FIXME( "stub: (Error Number %d when attempting to delete %s)\n",
1723 w32error
, debugstr_w(file
) );
1724 return DPROMPT_SKIPFILE
;
1727 /***********************************************************************
1728 * SetupRenameErrorA (SETUPAPI.@)
1731 UINT WINAPI
SetupRenameErrorA( HWND parent
, PCSTR dialogTitle
, PCSTR source
,
1732 PCSTR target
, UINT w32error
, DWORD style
)
1734 FIXME( "stub: (Error Number %d when attempting to rename %s to %s)\n",
1735 w32error
, debugstr_a(source
), debugstr_a(target
));
1736 return DPROMPT_SKIPFILE
;
1739 /***********************************************************************
1740 * SetupRenameErrorW (SETUPAPI.@)
1743 UINT WINAPI
SetupRenameErrorW( HWND parent
, PCWSTR dialogTitle
, PCWSTR source
,
1744 PCWSTR target
, UINT w32error
, DWORD style
)
1746 FIXME( "stub: (Error Number %d when attempting to rename %s to %s)\n",
1747 w32error
, debugstr_w(source
), debugstr_w(target
));
1748 return DPROMPT_SKIPFILE
;
1752 /***********************************************************************
1753 * SetupCopyErrorA (SETUPAPI.@)
1756 UINT WINAPI
SetupCopyErrorA( HWND parent
, PCSTR dialogTitle
, PCSTR diskname
,
1757 PCSTR sourcepath
, PCSTR sourcefile
, PCSTR targetpath
,
1758 UINT w32error
, DWORD style
, PSTR pathbuffer
,
1759 DWORD buffersize
, PDWORD requiredsize
)
1761 FIXME( "stub: (Error Number %d when attempting to copy file %s from %s to %s)\n",
1762 w32error
, debugstr_a(sourcefile
), debugstr_a(sourcepath
) ,debugstr_a(targetpath
));
1763 return DPROMPT_SKIPFILE
;
1766 /***********************************************************************
1767 * SetupCopyErrorW (SETUPAPI.@)
1770 UINT WINAPI
SetupCopyErrorW( HWND parent
, PCWSTR dialogTitle
, PCWSTR diskname
,
1771 PCWSTR sourcepath
, PCWSTR sourcefile
, PCWSTR targetpath
,
1772 UINT w32error
, DWORD style
, PWSTR pathbuffer
,
1773 DWORD buffersize
, PDWORD requiredsize
)
1775 FIXME( "stub: (Error Number %d when attempting to copy file %s from %s to %s)\n",
1776 w32error
, debugstr_w(sourcefile
), debugstr_w(sourcepath
) ,debugstr_w(targetpath
));
1777 return DPROMPT_SKIPFILE
;
1780 /***********************************************************************
1781 * pSetupGetQueueFlags (SETUPAPI.@)
1783 DWORD WINAPI
pSetupGetQueueFlags( HSPFILEQ handle
)
1785 struct file_queue
*queue
= handle
;
1786 return queue
->flags
;
1789 /***********************************************************************
1790 * pSetupSetQueueFlags (SETUPAPI.@)
1792 BOOL WINAPI
pSetupSetQueueFlags( HSPFILEQ handle
, DWORD flags
)
1794 struct file_queue
*queue
= handle
;
1795 queue
->flags
= flags
;