Newer
Older
/*
* Setupapi file queue routines
*
* Copyright 2002 Alexandre Julliard for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winternl.h"
#include "winerror.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "setupapi.h"
#include "wine/unicode.h"
#include "setupapi_private.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
static const WCHAR backslashW[] = {'\\',0};
/* context structure for the default queue callback */
struct default_callback_context
{
DWORD magic;
HWND owner;
DWORD unk1[4];
DWORD_PTR unk2[7];
HWND progress;
UINT message;
DWORD_PTR unk3[5];
};
struct file_op
{
struct file_op *next;
UINT style;
WCHAR *src_root;
WCHAR *src_path;
WCHAR *src_file;
WCHAR *src_descr;
WCHAR *src_tag;
WCHAR *dst_path;
WCHAR *dst_file;
};
struct file_op_queue
{
struct file_op *head;
struct file_op *tail;
unsigned int count;
};
struct file_queue
{
struct file_op_queue copy_queue;
struct file_op_queue delete_queue;
struct file_op_queue rename_queue;
DWORD flags;
};
/* append a file operation to a queue */
static inline void queue_file_op( struct file_op_queue *queue, struct file_op *op )
{
op->next = NULL;
if (queue->tail) queue->tail->next = op;
else queue->head = op;
queue->tail = op;
queue->count++;
}
/* free all the file operations on a given queue */
static void free_file_op_queue( struct file_op_queue *queue )
{

Alexandre Julliard
committed
struct file_op *t, *op = queue->head;

Alexandre Julliard
committed
while( op )
{
HeapFree( GetProcessHeap(), 0, op->src_root );
HeapFree( GetProcessHeap(), 0, op->src_path );
HeapFree( GetProcessHeap(), 0, op->src_file );
HeapFree( GetProcessHeap(), 0, op->src_descr );
HeapFree( GetProcessHeap(), 0, op->src_tag );
HeapFree( GetProcessHeap(), 0, op->dst_path );
if (op->dst_file != op->src_file) HeapFree( GetProcessHeap(), 0, op->dst_file );

Alexandre Julliard
committed
t = op;
op = op->next;
HeapFree( GetProcessHeap(), 0, t );
}
}
/* concat 3 strings to make a path, handling separators correctly */
static void concat_W( WCHAR *buffer, const WCHAR *src1, const WCHAR *src2, const WCHAR *src3 )
{
*buffer = 0;
if (src1 && *src1)
{
strcpyW( buffer, src1 );
buffer += strlenW(buffer );
if (buffer[-1] != '\\') *buffer++ = '\\';
if (src2) while (*src2 == '\\') src2++;
}
if (src2)
{
strcpyW( buffer, src2 );
buffer += strlenW(buffer );
if (buffer[-1] != '\\') *buffer++ = '\\';
if (src3) while (*src3 == '\\') src3++;
}
if (src3)
strcpyW( buffer, src3 );
}
/***********************************************************************
* build_filepathsW
*
* Build a FILEPATHS_W structure for a given file operation.
*/
static BOOL build_filepathsW( const struct file_op *op, FILEPATHS_W *paths )
{
unsigned int src_len = 1, dst_len = 1;
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
WCHAR *source = (PWSTR)paths->Source, *target = (PWSTR)paths->Target;
if (op->src_root) src_len += strlenW(op->src_root) + 1;
if (op->src_path) src_len += strlenW(op->src_path) + 1;
if (op->src_file) src_len += strlenW(op->src_file) + 1;
if (op->dst_path) dst_len += strlenW(op->dst_path) + 1;
if (op->dst_file) dst_len += strlenW(op->dst_file) + 1;
src_len *= sizeof(WCHAR);
dst_len *= sizeof(WCHAR);
if (!source || HeapSize( GetProcessHeap(), 0, source ) < src_len )
{
HeapFree( GetProcessHeap(), 0, source );
paths->Source = source = HeapAlloc( GetProcessHeap(), 0, src_len );
}
if (!target || HeapSize( GetProcessHeap(), 0, target ) < dst_len )
{
HeapFree( GetProcessHeap(), 0, target );
paths->Target = target = HeapAlloc( GetProcessHeap(), 0, dst_len );
}
if (!source || !target) return FALSE;
concat_W( source, op->src_root, op->src_path, op->src_file );
concat_W( target, NULL, op->dst_path, op->dst_file );
paths->Win32Error = 0;
paths->Flags = 0;
return TRUE;
}
/***********************************************************************
* QUEUE_callback_WtoA
*
* Map a file callback parameters from W to A and call the A callback.
*/
UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification,
UINT_PTR param1, UINT_PTR param2 )
{
struct callback_WtoA_context *callback_ctx = context;
char buffer[MAX_PATH];
UINT ret;
UINT_PTR old_param2 = param2;
switch(notification)
{
case SPFILENOTIFY_COPYERROR:
param2 = (UINT_PTR)buffer;
/* fall through */
case SPFILENOTIFY_STARTDELETE:
case SPFILENOTIFY_ENDDELETE:
case SPFILENOTIFY_DELETEERROR:
case SPFILENOTIFY_STARTRENAME:
case SPFILENOTIFY_ENDRENAME:
case SPFILENOTIFY_RENAMEERROR:
case SPFILENOTIFY_STARTCOPY:
case SPFILENOTIFY_ENDCOPY:
case SPFILENOTIFY_QUEUESCAN_EX:
{
FILEPATHS_W *pathsW = (FILEPATHS_W *)param1;
FILEPATHS_A pathsA;
pathsA.Source = strdupWtoA( pathsW->Source );
pathsA.Target = strdupWtoA( pathsW->Target );
pathsA.Win32Error = pathsW->Win32Error;
pathsA.Flags = pathsW->Flags;
ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification,
(UINT_PTR)&pathsA, param2 );
HeapFree( GetProcessHeap(), 0, (void *)pathsA.Source );
HeapFree( GetProcessHeap(), 0, (void *)pathsA.Target );
}
if (notification == SPFILENOTIFY_COPYERROR)
MultiByteToWideChar( CP_ACP, 0, buffer, -1, (WCHAR *)old_param2, MAX_PATH );
break;
case SPFILENOTIFY_STARTREGISTRATION:
case SPFILENOTIFY_ENDREGISTRATION:
{
SP_REGISTER_CONTROL_STATUSW *statusW = (SP_REGISTER_CONTROL_STATUSW *)param1;
SP_REGISTER_CONTROL_STATUSA statusA;
statusA.cbSize = sizeof(statusA);
statusA.FileName = strdupWtoA( statusW->FileName );
statusA.Win32Error = statusW->Win32Error;
statusA.FailureCode = statusW->FailureCode;
ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification,
(UINT_PTR)&statusA, param2 );
HeapFree( GetProcessHeap(), 0, (LPSTR)statusA.FileName );
}
break;
case SPFILENOTIFY_QUEUESCAN:
{
LPWSTR targetW = (LPWSTR)param1;
LPSTR target = strdupWtoA( targetW );
ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification,
(UINT_PTR)target, param2 );
HeapFree( GetProcessHeap(), 0, target );
}
break;
case SPFILENOTIFY_NEEDMEDIA:
FIXME("mapping for %d not implemented\n",notification);
case SPFILENOTIFY_STARTQUEUE:
case SPFILENOTIFY_ENDQUEUE:
case SPFILENOTIFY_STARTSUBQUEUE:
case SPFILENOTIFY_ENDSUBQUEUE:
default:
ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification, param1, param2 );
break;
}
return ret;
}
/***********************************************************************
* get_src_file_info
*
* Retrieve the source file information for a given file.
*/
static void get_src_file_info( HINF hinf, struct file_op *op )
{
static const WCHAR SourceDisksNames[] =
{'S','o','u','r','c','e','D','i','s','k','s','N','a','m','e','s',0};
static const WCHAR SourceDisksFiles[] =
{'S','o','u','r','c','e','D','i','s','k','s','F','i','l','e','s',0};
INFCONTEXT file_ctx, disk_ctx;
INT id, diskid;
DWORD len, len2;
/* find the SourceDisksFiles entry */
if (!SetupFindFirstLineW( hinf, SourceDisksFiles, op->src_file, &file_ctx ))
{
if ((op->style & (SP_COPY_SOURCE_ABSOLUTE|SP_COPY_SOURCEPATH_ABSOLUTE))) return;
/* no specific info, use .inf file source directory */

Alexandre Julliard
committed
if (!op->src_root) op->src_root = PARSER_get_src_root( hinf );
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
return;
}
if (!SetupGetIntField( &file_ctx, 1, &diskid )) return;
/* now find the diskid in the SourceDisksNames section */
if (!SetupFindFirstLineW( hinf, SourceDisksNames, NULL, &disk_ctx )) return;
for (;;)
{
if (SetupGetIntField( &disk_ctx, 0, &id ) && (id == diskid)) break;
if (!SetupFindNextLine( &disk_ctx, &disk_ctx )) return;
}
/* and fill in the missing info */
if (!op->src_descr)
{
if (SetupGetStringFieldW( &disk_ctx, 1, NULL, 0, &len ) &&
(op->src_descr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) )))
SetupGetStringFieldW( &disk_ctx, 1, op->src_descr, len, NULL );
}
if (!op->src_tag)
{
if (SetupGetStringFieldW( &disk_ctx, 2, NULL, 0, &len ) &&
(op->src_tag = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) )))
SetupGetStringFieldW( &disk_ctx, 2, op->src_tag, len, NULL );
}
if (!op->src_path && !(op->style & SP_COPY_SOURCE_ABSOLUTE))
{
if (!(op->style & SP_COPY_SOURCEPATH_ABSOLUTE))
{
/* retrieve relative path for this disk */
if (!SetupGetStringFieldW( &disk_ctx, 4, NULL, 0, &len )) len = 0;
}
/* retrieve relative path for this file */
if (!SetupGetStringFieldW( &file_ctx, 2, NULL, 0, &len2 )) len2 = 0;
if ((len || len2) &&
(op->src_path = HeapAlloc( GetProcessHeap(), 0, (len+len2)*sizeof(WCHAR) )))
{
WCHAR *ptr = op->src_path;
if (len)
{
SetupGetStringFieldW( &disk_ctx, 4, op->src_path, len, NULL );
ptr = op->src_path + strlenW(op->src_path);
if (len2 && ptr > op->src_path && ptr[-1] != '\\') *ptr++ = '\\';
}
if (!SetupGetStringFieldW( &file_ctx, 2, ptr, len2, NULL )) *ptr = 0;
}
}

Alexandre Julliard
committed
if (!op->src_root) op->src_root = PARSER_get_src_root(hinf);
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
static void get_source_info( HINF hinf, const WCHAR *src_file, SP_FILE_COPY_PARAMS_W *params,
WCHAR *src_root, WCHAR *src_path)
{
static const WCHAR SourceDisksNames[] =
{'S','o','u','r','c','e','D','i','s','k','s','N','a','m','e','s',0};
static const WCHAR SourceDisksFiles[] =
{'S','o','u','r','c','e','D','i','s','k','s','F','i','l','e','s',0};
INFCONTEXT file_ctx, disk_ctx;
INT id, diskid;
DWORD len;
/* find the SourceDisksFiles entry */
if (!SetupFindFirstLineW( hinf, SourceDisksFiles, src_file, &file_ctx )) return;
if (!SetupGetIntField( &file_ctx, 1, &diskid )) return;
/* now find the diskid in the SourceDisksNames section */
if (!SetupFindFirstLineW( hinf, SourceDisksNames, NULL, &disk_ctx )) return;
for (;;)
{
if (SetupGetIntField( &disk_ctx, 0, &id ) && (id == diskid)) break;
if (!SetupFindNextLine( &disk_ctx, &disk_ctx )) return;
}
if (SetupGetStringFieldW( &disk_ctx, 1, NULL, 0, &len ) && len > sizeof(WCHAR)
&& (params->SourceDescription = heap_alloc( len * sizeof(WCHAR) )))
SetupGetStringFieldW( &disk_ctx, 1, (WCHAR *)params->SourceDescription, len, NULL );
if (SetupGetStringFieldW( &disk_ctx, 2, NULL, 0, &len ) && len > sizeof(WCHAR)
&& (params->SourceTagfile = heap_alloc( len * sizeof(WCHAR) )))
SetupGetStringFieldW( &disk_ctx, 2, (WCHAR *)params->SourceTagfile, len, NULL );
if (SetupGetStringFieldW( &disk_ctx, 4, NULL, 0, &len ) && len > sizeof(WCHAR)
&& len < MAX_PATH - strlenW( src_root ) - 1)
{
strcatW( src_root, backslashW );
SetupGetStringFieldW( &disk_ctx, 4, src_root + strlenW( src_root ),
MAX_PATH - strlenW( src_root ), NULL );
}
if (SetupGetStringFieldW( &file_ctx, 2, NULL, 0, &len ) && len > sizeof(WCHAR) && len < MAX_PATH)
{
SetupGetStringFieldW( &file_ctx, 2, src_path, MAX_PATH, NULL );
params->SourcePath = src_path;
}
}
/***********************************************************************
* get_destination_dir
*
* Retrieve the destination dir for a given section.
*/
static WCHAR *get_destination_dir( HINF hinf, const WCHAR *section )
{
static const WCHAR Dest[] = {'D','e','s','t','i','n','a','t','i','o','n','D','i','r','s',0};
static const WCHAR Def[] = {'D','e','f','a','u','l','t','D','e','s','t','D','i','r',0};
INFCONTEXT context;
WCHAR systemdir[MAX_PATH], *dir;
BOOL ret;
if (!section || !(ret = SetupFindFirstLineW( hinf, Dest, section, &context )))
ret = SetupFindFirstLineW( hinf, Dest, Def, &context );
if (ret && (dir = PARSER_get_dest_dir( &context )))
return dir;
GetSystemDirectoryW( systemdir, MAX_PATH );
return strdupW( systemdir );
struct extract_cab_ctx
{
const WCHAR *src;
const WCHAR *dst;
};
static UINT WINAPI extract_cab_cb( void *arg, UINT message, UINT_PTR param1, UINT_PTR param2 )
{
struct extract_cab_ctx *ctx = arg;
switch (message)
{
case SPFILENOTIFY_FILEINCABINET:
{
FILE_IN_CABINET_INFO_W *info = (FILE_IN_CABINET_INFO_W *)param1;
const WCHAR *filename;
if ((filename = strrchrW( info->NameInCabinet, '\\' )))
filename++;
else
filename = info->NameInCabinet;
if (lstrcmpiW( filename, ctx->src ))
return FILEOP_SKIP;
strcpyW( info->FullTargetName, ctx->dst );
return FILEOP_DOIT;
}
case SPFILENOTIFY_FILEEXTRACTED:
{
const FILEPATHS_W *paths = (const FILEPATHS_W *)param1;
return paths->Win32Error;
}
case SPFILENOTIFY_NEEDNEWCABINET:
{
const CABINET_INFO_W *info = (const CABINET_INFO_W *)param1;
strcpyW( (WCHAR *)param2, info->CabinetPath );
return ERROR_SUCCESS;
}
case SPFILENOTIFY_CABINETINFO:
return 0;
default:
FIXME("Unexpected message %#x.\n", message);
return 0;
}
}
/***********************************************************************
* extract_cabinet_file
*
* Extract a file from a .cab file.
*/
static BOOL extract_cabinet_file( const WCHAR *cabinet, const WCHAR *root,
const WCHAR *src, const WCHAR *dst )
{
static const WCHAR extW[] = {'.','c','a','b',0};
static const WCHAR backslashW[] = {'\\',0};
struct extract_cab_ctx ctx = {src, dst};
int len = strlenW( cabinet );
WCHAR path[MAX_PATH];
/* make sure the cabinet file has a .cab extension */
if (len <= 4 || strcmpiW( cabinet + len - 4, extW )) return FALSE;
strcpyW(path, root);
strcatW(path, backslashW);
strcatW(path, cabinet);
return SetupIterateCabinetW( path, 0, extract_cab_cb, &ctx );
}
/***********************************************************************
* SetupOpenFileQueue (SETUPAPI.@)
*/
HSPFILEQ WINAPI SetupOpenFileQueue(void)
{
struct file_queue *queue;
if (!(queue = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*queue))))
return queue;
}
/***********************************************************************
* SetupCloseFileQueue (SETUPAPI.@)
*/
BOOL WINAPI SetupCloseFileQueue( HSPFILEQ handle )
{
struct file_queue *queue = handle;
free_file_op_queue( &queue->copy_queue );
free_file_op_queue( &queue->rename_queue );
free_file_op_queue( &queue->delete_queue );
HeapFree( GetProcessHeap(), 0, queue );
return TRUE;
}
/***********************************************************************
* SetupQueueCopyIndirectA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopyIndirectA( SP_FILE_COPY_PARAMS_A *paramsA )
SP_FILE_COPY_PARAMS_W paramsW;
BOOL ret;
paramsW.cbSize = sizeof(paramsW);
paramsW.QueueHandle = paramsA->QueueHandle;
paramsW.SourceRootPath = strdupAtoW( paramsA->SourceRootPath );
paramsW.SourcePath = strdupAtoW( paramsA->SourcePath );
paramsW.SourceFilename = strdupAtoW( paramsA->SourceFilename );
paramsW.SourceDescription = strdupAtoW( paramsA->SourceDescription );
paramsW.SourceTagfile = strdupAtoW( paramsA->SourceTagfile );
paramsW.TargetDirectory = strdupAtoW( paramsA->TargetDirectory );
paramsW.TargetFilename = strdupAtoW( paramsA->TargetFilename );
paramsW.CopyStyle = paramsA->CopyStyle;
paramsW.LayoutInf = paramsA->LayoutInf;
paramsW.SecurityDescriptor = strdupAtoW( paramsA->SecurityDescriptor );
ret = SetupQueueCopyIndirectW( ¶msW );
heap_free( (WCHAR *)paramsW.SourceRootPath );
heap_free( (WCHAR *)paramsW.SourcePath );
heap_free( (WCHAR *)paramsW.SourceFilename );
heap_free( (WCHAR *)paramsW.SourceDescription );
heap_free( (WCHAR *)paramsW.SourceTagfile );
heap_free( (WCHAR *)paramsW.TargetDirectory );
heap_free( (WCHAR *)paramsW.TargetFilename );
heap_free( (WCHAR *)paramsW.SecurityDescriptor );
return ret;
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
}
/***********************************************************************
* SetupQueueCopyIndirectW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopyIndirectW( PSP_FILE_COPY_PARAMS_W params )
{
struct file_queue *queue = params->QueueHandle;
struct file_op *op;
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE;
op->style = params->CopyStyle;
op->src_root = strdupW( params->SourceRootPath );
op->src_path = strdupW( params->SourcePath );
op->src_file = strdupW( params->SourceFilename );
op->src_descr = strdupW( params->SourceDescription );
op->src_tag = strdupW( params->SourceTagfile );
op->dst_path = strdupW( params->TargetDirectory );
op->dst_file = strdupW( params->TargetFilename );
/* some defaults */
if (!op->src_file) op->src_file = op->dst_file;
if (params->LayoutInf)
{
get_src_file_info( params->LayoutInf, op );
if (!op->dst_path) op->dst_path = get_destination_dir( params->LayoutInf, op->dst_file );
}
TRACE( "root=%s path=%s file=%s -> dir=%s file=%s descr=%s tag=%s\n",
debugstr_w(op->src_root), debugstr_w(op->src_path), debugstr_w(op->src_file),
debugstr_w(op->dst_path), debugstr_w(op->dst_file),
debugstr_w(op->src_descr), debugstr_w(op->src_tag) );
queue_file_op( &queue->copy_queue, op );
return TRUE;
}
/***********************************************************************
* SetupQueueCopyA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopyA( HSPFILEQ queue, PCSTR src_root, PCSTR src_path, PCSTR src_file,
PCSTR src_descr, PCSTR src_tag, PCSTR dst_dir, PCSTR dst_file,
DWORD style )
{
SP_FILE_COPY_PARAMS_A params;
params.cbSize = sizeof(params);
params.QueueHandle = queue;
params.SourceRootPath = src_root;
params.SourcePath = src_path;
params.SourceFilename = src_file;
params.SourceDescription = src_descr;
params.SourceTagfile = src_tag;
params.TargetDirectory = dst_dir;
params.TargetFilename = dst_file;
params.CopyStyle = style;
params.LayoutInf = 0;
params.SecurityDescriptor = NULL;
return SetupQueueCopyIndirectA( ¶ms );
}
/***********************************************************************
* SetupQueueCopyW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopyW( HSPFILEQ queue, PCWSTR src_root, PCWSTR src_path, PCWSTR src_file,
PCWSTR src_descr, PCWSTR src_tag, PCWSTR dst_dir, PCWSTR dst_file,
DWORD style )
{
SP_FILE_COPY_PARAMS_W params;
params.cbSize = sizeof(params);
params.QueueHandle = queue;
params.SourceRootPath = src_root;
params.SourcePath = src_path;
params.SourceFilename = src_file;
params.SourceDescription = src_descr;
params.SourceTagfile = src_tag;
params.TargetDirectory = dst_dir;
params.TargetFilename = dst_file;
params.CopyStyle = style;
params.LayoutInf = 0;
params.SecurityDescriptor = NULL;
return SetupQueueCopyIndirectW( ¶ms );
}
/***********************************************************************
* SetupQueueDefaultCopyA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDefaultCopyA( HSPFILEQ queue, HINF hinf, const char *src_rootA,
const char *src_fileA, const char *dst_fileA, DWORD style )
WCHAR src_rootW[MAX_PATH], src_fileW[MAX_PATH], dst_fileW[MAX_PATH];
if (!src_rootA || !src_fileA || !dst_fileA)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
MultiByteToWideChar( CP_ACP, 0, src_rootA, -1, src_rootW, ARRAY_SIZE(src_rootW) );
MultiByteToWideChar( CP_ACP, 0, src_fileA, -1, src_fileW, ARRAY_SIZE(src_fileW) );
MultiByteToWideChar( CP_ACP, 0, dst_fileA, -1, dst_fileW, ARRAY_SIZE(dst_fileW) );
return SetupQueueDefaultCopyW( queue, hinf, src_rootW, src_fileW, dst_fileW, style );
}
/***********************************************************************
* SetupQueueDefaultCopyW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDefaultCopyW( HSPFILEQ queue, HINF hinf, PCWSTR src_root, PCWSTR src_file,
PCWSTR dst_file, DWORD style )
{
WCHAR src_root_buffer[MAX_PATH], src_path[MAX_PATH];
SP_FILE_COPY_PARAMS_W params;
BOOL ret;
if (!src_root || !src_file || !dst_file)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
params.cbSize = sizeof(params);
params.QueueHandle = queue;
params.SourceRootPath = src_root_buffer;
params.SourcePath = NULL;
params.SourceFilename = src_file;
params.SourceDescription = NULL;
params.SourceTagfile = NULL;
params.TargetFilename = dst_file;
params.CopyStyle = style;
params.LayoutInf = NULL;
params.SecurityDescriptor = NULL;
strcpyW( src_root_buffer, src_root );
src_path[0] = 0;
if (!(params.TargetDirectory = get_destination_dir( hinf, NULL ))) return FALSE;
get_source_info( hinf, src_file, ¶ms, src_root_buffer, src_path );
ret = SetupQueueCopyIndirectW( ¶ms );
heap_free( (WCHAR *)params.TargetDirectory );
heap_free( (WCHAR *)params.SourceDescription );
heap_free( (WCHAR *)params.SourceTagfile );
return ret;
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
}
/***********************************************************************
* SetupQueueDeleteA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDeleteA( HSPFILEQ handle, PCSTR part1, PCSTR part2 )
{
struct file_queue *queue = handle;
struct file_op *op;
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE;
op->style = 0;
op->src_root = NULL;
op->src_path = NULL;
op->src_file = NULL;
op->src_descr = NULL;
op->src_tag = NULL;
op->dst_path = strdupAtoW( part1 );
op->dst_file = strdupAtoW( part2 );
queue_file_op( &queue->delete_queue, op );
return TRUE;
}
/***********************************************************************
* SetupQueueDeleteW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDeleteW( HSPFILEQ handle, PCWSTR part1, PCWSTR part2 )
{
struct file_queue *queue = handle;
struct file_op *op;
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE;
op->style = 0;
op->src_root = NULL;
op->src_path = NULL;
op->src_file = NULL;
op->src_descr = NULL;
op->src_tag = NULL;
op->dst_path = strdupW( part1 );
op->dst_file = strdupW( part2 );
queue_file_op( &queue->delete_queue, op );
return TRUE;
}
/***********************************************************************
* SetupQueueRenameA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueRenameA( HSPFILEQ handle, PCSTR SourcePath, PCSTR SourceFilename,
PCSTR TargetPath, PCSTR TargetFilename )
{
struct file_queue *queue = handle;
struct file_op *op;
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE;
op->style = 0;
op->src_root = NULL;
op->src_path = strdupAtoW( SourcePath );
op->src_file = strdupAtoW( SourceFilename );
op->src_descr = NULL;
op->src_tag = NULL;
op->dst_path = strdupAtoW( TargetPath );
op->dst_file = strdupAtoW( TargetFilename );
queue_file_op( &queue->rename_queue, op );
return TRUE;
}
/***********************************************************************
* SetupQueueRenameW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueRenameW( HSPFILEQ handle, PCWSTR SourcePath, PCWSTR SourceFilename,
PCWSTR TargetPath, PCWSTR TargetFilename )
{
struct file_queue *queue = handle;
struct file_op *op;
if (!(op = HeapAlloc( GetProcessHeap(), 0, sizeof(*op) ))) return FALSE;
op->style = 0;
op->src_root = NULL;
op->src_path = strdupW( SourcePath );
op->src_file = strdupW( SourceFilename );
op->src_descr = NULL;
op->src_tag = NULL;
op->dst_path = strdupW( TargetPath );
op->dst_file = strdupW( TargetFilename );
queue_file_op( &queue->rename_queue, op );
return TRUE;
}
/***********************************************************************
* SetupQueueCopySectionA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopySectionA( HSPFILEQ queue, PCSTR src_root, HINF hinf, HINF hlist,
PCSTR section, DWORD style )
{
UNICODE_STRING sectionW;
BOOL ret = FALSE;
if (!RtlCreateUnicodeStringFromAsciiz( §ionW, section ))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return FALSE;
}
if (!src_root)
ret = SetupQueueCopySectionW( queue, NULL, hinf, hlist, sectionW.Buffer, style );
else
{
UNICODE_STRING srcW;
if (RtlCreateUnicodeStringFromAsciiz( &srcW, src_root ))
{
ret = SetupQueueCopySectionW( queue, srcW.Buffer, hinf, hlist, sectionW.Buffer, style );
RtlFreeUnicodeString( &srcW );
}
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
}
RtlFreeUnicodeString( §ionW );
return ret;
}
/***********************************************************************
* SetupQueueCopySectionW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueCopySectionW( HSPFILEQ queue, PCWSTR src_root, HINF hinf, HINF hlist,
PCWSTR section, DWORD style )
{
WCHAR src_root_buffer[MAX_PATH], src_path[MAX_PATH], src_file[MAX_PATH], dst_file[MAX_PATH], *dest_dir;
INFCONTEXT context;
SP_FILE_COPY_PARAMS_W params;
INT flags;
TRACE("queue %p, src_root %s, hinf %p, hlist %p, section %s, style %#x.\n",
queue, debugstr_w(src_root), hinf, hlist, debugstr_w(section), style);
if (!src_root)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
params.cbSize = sizeof(params);
params.QueueHandle = queue;
params.SourceRootPath = src_root_buffer;
params.SourceFilename = src_file;
params.TargetFilename = dst_file;
params.CopyStyle = style;
params.LayoutInf = NULL;
params.SecurityDescriptor = NULL;
strcpyW( src_root_buffer, src_root );
if (!hlist) hlist = hinf;
if (!SetupFindFirstLineW( hlist, section, NULL, &context )) return FALSE;
if (!(params.TargetDirectory = dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
params.SourcePath = NULL;
params.SourceDescription = NULL;
params.SourceTagfile = NULL;
strcpyW( src_root_buffer, src_root );
src_path[0] = 0;
if (!SetupGetStringFieldW( &context, 1, dst_file, ARRAY_SIZE( dst_file ), NULL ))
if (!SetupGetStringFieldW( &context, 2, src_file, ARRAY_SIZE( src_file ), NULL ))
strcpyW( src_file, dst_file );
if (!SetupGetIntField( &context, 4, &flags )) flags = 0; /* FIXME */
get_source_info( hinf, src_file, ¶ms, src_root_buffer, src_path );
if (!SetupQueueCopyIndirectW( ¶ms )) goto end;
heap_free( (WCHAR *)params.SourceDescription );
heap_free( (WCHAR *)params.SourceTagfile );
} while (SetupFindNextLine( &context, &context ));
end:
HeapFree(GetProcessHeap(), 0, dest_dir);
return ret;
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
}
/***********************************************************************
* SetupQueueDeleteSectionA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDeleteSectionA( HSPFILEQ queue, HINF hinf, HINF hlist, PCSTR section )
{
UNICODE_STRING sectionW;
BOOL ret = FALSE;
if (RtlCreateUnicodeStringFromAsciiz( §ionW, section ))
{
ret = SetupQueueDeleteSectionW( queue, hinf, hlist, sectionW.Buffer );
RtlFreeUnicodeString( §ionW );
}
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return ret;
}
/***********************************************************************
* SetupQueueDeleteSectionW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueDeleteSectionW( HSPFILEQ queue, HINF hinf, HINF hlist, PCWSTR section )
{
INFCONTEXT context;
WCHAR *dest_dir;
WCHAR buffer[MAX_PATH];
BOOL ret = FALSE;
INT flags;
TRACE( "hinf=%p/%p section=%s\n", hinf, hlist, debugstr_w(section) );
if (!hlist) hlist = hinf;
if (!SetupFindFirstLineW( hlist, section, NULL, &context )) return FALSE;
if (!(dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
if (!SetupGetStringFieldW( &context, 1, buffer, ARRAY_SIZE( buffer ), NULL ))
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
goto done;
if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
if (!SetupQueueDeleteW( queue, dest_dir, buffer )) goto done;
} while (SetupFindNextLine( &context, &context ));
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, dest_dir );
return ret;
}
/***********************************************************************
* SetupQueueRenameSectionA (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueRenameSectionA( HSPFILEQ queue, HINF hinf, HINF hlist, PCSTR section )
{
UNICODE_STRING sectionW;
BOOL ret = FALSE;
if (RtlCreateUnicodeStringFromAsciiz( §ionW, section ))
{
ret = SetupQueueRenameSectionW( queue, hinf, hlist, sectionW.Buffer );
RtlFreeUnicodeString( §ionW );
}
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return ret;
}
/***********************************************************************
* SetupQueueRenameSectionW (SETUPAPI.@)
*/
BOOL WINAPI SetupQueueRenameSectionW( HSPFILEQ queue, HINF hinf, HINF hlist, PCWSTR section )
{
INFCONTEXT context;
WCHAR *dest_dir;
WCHAR src[MAX_PATH], dst[MAX_PATH];
BOOL ret = FALSE;
TRACE( "hinf=%p/%p section=%s\n", hinf, hlist, debugstr_w(section) );
if (!hlist) hlist = hinf;
if (!SetupFindFirstLineW( hlist, section, NULL, &context )) return FALSE;
if (!(dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
if (!SetupGetStringFieldW( &context, 1, dst, ARRAY_SIZE( dst ), NULL ))
goto done;
if (!SetupGetStringFieldW( &context, 2, src, ARRAY_SIZE( src ), NULL ))
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
goto done;
if (!SetupQueueRenameW( queue, dest_dir, src, NULL, dst )) goto done;
} while (SetupFindNextLine( &context, &context ));
ret = TRUE;
done:
HeapFree( GetProcessHeap(), 0, dest_dir );
return ret;
}
/***********************************************************************
* SetupCommitFileQueueA (SETUPAPI.@)
*/
BOOL WINAPI SetupCommitFileQueueA( HWND owner, HSPFILEQ queue, PSP_FILE_CALLBACK_A handler,
PVOID context )
{
struct callback_WtoA_context ctx;
ctx.orig_context = context;
ctx.orig_handler = handler;
return SetupCommitFileQueueW( owner, queue, QUEUE_callback_WtoA, &ctx );
}
/***********************************************************************
* create_full_pathW
*
* Recursively create all directories in the path.
*/
static BOOL create_full_pathW(const WCHAR *path)
{
BOOL ret = TRUE;
int len;
WCHAR *new_path;
new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) * sizeof(WCHAR));
strcpyW(new_path, path);
while((len = strlenW(new_path)) && new_path[len - 1] == '\\')