2002-04-02 04:57:50 +02:00
|
|
|
/*
|
|
|
|
* Setupapi install 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-02 04:57:50 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-10-31 16:34:16 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-04-02 04:57:50 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-04-02 04:57:50 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winnls.h"
|
2008-04-16 12:36:08 +02:00
|
|
|
#include "winsvc.h"
|
2008-10-31 16:34:16 +01:00
|
|
|
#include "shlobj.h"
|
2020-06-11 18:16:32 +02:00
|
|
|
#include "shlwapi.h"
|
2008-10-31 16:34:16 +01:00
|
|
|
#include "objidl.h"
|
|
|
|
#include "objbase.h"
|
2002-04-02 04:57:50 +02:00
|
|
|
#include "setupapi.h"
|
|
|
|
#include "setupapi_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
|
|
|
|
|
|
|
|
/* info passed to callback functions dealing with files */
|
|
|
|
struct files_callback_info
|
|
|
|
{
|
|
|
|
HSPFILEQ queue;
|
|
|
|
PCWSTR src_root;
|
|
|
|
UINT copy_flags;
|
|
|
|
HINF layout;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* info passed to callback functions dealing with the registry */
|
|
|
|
struct registry_callback_info
|
|
|
|
{
|
|
|
|
HKEY default_root;
|
|
|
|
BOOL delete;
|
|
|
|
};
|
|
|
|
|
2004-02-27 01:47:10 +01:00
|
|
|
/* info passed to callback functions dealing with registering dlls */
|
|
|
|
struct register_dll_info
|
|
|
|
{
|
|
|
|
PSP_FILE_CALLBACK_W callback;
|
|
|
|
PVOID callback_context;
|
|
|
|
BOOL unregister;
|
2011-08-26 13:12:26 +02:00
|
|
|
int modules_size;
|
|
|
|
int modules_count;
|
|
|
|
HMODULE *modules;
|
2004-02-27 01:47:10 +01:00
|
|
|
};
|
|
|
|
|
2002-04-02 04:57:50 +02:00
|
|
|
typedef BOOL (*iterate_fields_func)( HINF hinf, PCWSTR field, void *arg );
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_field_string
|
|
|
|
*
|
|
|
|
* Retrieve the contents of a field, dynamically growing the buffer if necessary.
|
|
|
|
*/
|
|
|
|
static WCHAR *get_field_string( INFCONTEXT *context, DWORD index, WCHAR *buffer,
|
|
|
|
WCHAR *static_buffer, DWORD *size )
|
|
|
|
{
|
|
|
|
DWORD required;
|
|
|
|
|
|
|
|
if (SetupGetStringFieldW( context, index, buffer, *size, &required )) return buffer;
|
|
|
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
|
|
|
/* now grow the buffer */
|
|
|
|
if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, required*sizeof(WCHAR) ))) return NULL;
|
|
|
|
*size = required;
|
|
|
|
if (SetupGetStringFieldW( context, index, buffer, *size, &required )) return buffer;
|
|
|
|
}
|
|
|
|
if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 12:36:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* dup_section_line_field
|
|
|
|
*
|
|
|
|
* Retrieve the contents of a field in a newly-allocated buffer.
|
|
|
|
*/
|
|
|
|
static WCHAR *dup_section_line_field( HINF hinf, const WCHAR *section, const WCHAR *line, DWORD index )
|
|
|
|
{
|
|
|
|
INFCONTEXT context;
|
|
|
|
DWORD size;
|
|
|
|
WCHAR *buffer;
|
|
|
|
|
|
|
|
if (!SetupFindFirstLineW( hinf, section, line, &context )) return NULL;
|
|
|
|
if (!SetupGetStringFieldW( &context, index, NULL, 0, &size )) return NULL;
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return NULL;
|
|
|
|
if (!SetupGetStringFieldW( &context, index, buffer, size, NULL )) buffer[0] = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-06-11 18:16:32 +02:00
|
|
|
static void get_inf_src_path( HINF hinf, WCHAR *path )
|
|
|
|
{
|
|
|
|
const WCHAR *inf_path = PARSER_get_inf_filename( hinf );
|
|
|
|
WCHAR pnf_path[MAX_PATH];
|
|
|
|
FILE *pnf;
|
|
|
|
|
|
|
|
wcscpy( pnf_path, inf_path );
|
|
|
|
PathRemoveExtensionW( pnf_path );
|
|
|
|
PathAddExtensionW( pnf_path, L".pnf" );
|
|
|
|
if ((pnf = _wfopen( pnf_path, L"r" )))
|
|
|
|
{
|
|
|
|
if (fgetws( path, MAX_PATH, pnf ) && !wcscmp( path, PNF_HEADER ))
|
|
|
|
{
|
|
|
|
fgetws( path, MAX_PATH, pnf );
|
|
|
|
TRACE("using original source path %s\n", debugstr_w(path));
|
|
|
|
fclose( pnf );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fclose( pnf );
|
|
|
|
}
|
|
|
|
wcscpy( path, inf_path );
|
|
|
|
}
|
|
|
|
|
2002-04-02 04:57:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* copy_files_callback
|
|
|
|
*
|
|
|
|
* Called once for each CopyFiles entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL copy_files_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
2020-02-11 09:00:43 +01:00
|
|
|
INFCONTEXT context;
|
2002-04-02 04:57:50 +02:00
|
|
|
struct files_callback_info *info = arg;
|
2019-05-02 01:24:02 +02:00
|
|
|
WCHAR src_root[MAX_PATH], *p;
|
|
|
|
|
|
|
|
if (!info->src_root)
|
|
|
|
{
|
2020-02-11 09:00:43 +01:00
|
|
|
const WCHAR *build_dir = _wgetenv( L"WINEBUILDDIR" );
|
|
|
|
const WCHAR *data_dir = _wgetenv( L"WINEDATADIR" );
|
|
|
|
|
|
|
|
if ((build_dir || data_dir) && SetupFindFirstLineW( hinf, L"WineSourceDirs", field, &context ))
|
|
|
|
{
|
|
|
|
lstrcpyW( src_root, build_dir ? build_dir : data_dir );
|
|
|
|
src_root[1] = '\\'; /* change \??\ to \\?\ */
|
|
|
|
p = src_root + lstrlenW(src_root);
|
|
|
|
*p++ = '\\';
|
|
|
|
if (!build_dir || !SetupGetStringFieldW( &context, 2, p, MAX_PATH - (p - src_root), NULL ))
|
|
|
|
{
|
|
|
|
if (!SetupGetStringFieldW( &context, 1, p, MAX_PATH - (p - src_root), NULL )) p[-1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-11 18:16:32 +02:00
|
|
|
get_inf_src_path( hinf, src_root );
|
2020-02-11 09:00:43 +01:00
|
|
|
if ((p = wcsrchr( src_root, '\\' ))) *p = 0;
|
|
|
|
}
|
2019-05-02 01:24:02 +02:00
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
|
|
|
|
if (field[0] == '@') /* special case: copy single file */
|
2019-05-02 01:24:02 +02:00
|
|
|
SetupQueueDefaultCopyW( info->queue, info->layout ? info->layout : hinf,
|
2019-05-08 01:04:10 +02:00
|
|
|
info->src_root ? info->src_root : src_root, field+1, field+1, info->copy_flags );
|
2002-04-02 04:57:50 +02:00
|
|
|
else
|
2019-05-02 01:24:02 +02:00
|
|
|
SetupQueueCopySectionW( info->queue, info->src_root ? info->src_root : src_root,
|
|
|
|
info->layout ? info->layout : hinf, hinf, field, info->copy_flags );
|
2002-04-02 04:57:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* delete_files_callback
|
|
|
|
*
|
|
|
|
* Called once for each DelFiles entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL delete_files_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
struct files_callback_info *info = arg;
|
|
|
|
SetupQueueDeleteSectionW( info->queue, hinf, 0, field );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* rename_files_callback
|
|
|
|
*
|
|
|
|
* Called once for each RenFiles entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL rename_files_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
struct files_callback_info *info = arg;
|
|
|
|
SetupQueueRenameSectionW( info->queue, hinf, 0, field );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* get_root_key
|
|
|
|
*
|
|
|
|
* Retrieve the registry root key from its name.
|
|
|
|
*/
|
|
|
|
static HKEY get_root_key( const WCHAR *name, HKEY def_root )
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!wcsicmp( name, L"HKCR" )) return HKEY_CLASSES_ROOT;
|
|
|
|
if (!wcsicmp( name, L"HKCU" )) return HKEY_CURRENT_USER;
|
|
|
|
if (!wcsicmp( name, L"HKLM" )) return HKEY_LOCAL_MACHINE;
|
|
|
|
if (!wcsicmp( name, L"HKU" )) return HKEY_USERS;
|
|
|
|
if (!wcsicmp( name, L"HKR" )) return def_root;
|
2002-04-02 04:57:50 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* append_multi_sz_value
|
|
|
|
*
|
|
|
|
* Append a multisz string to a multisz registry value.
|
|
|
|
*/
|
|
|
|
static void append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *strings,
|
|
|
|
DWORD str_size )
|
|
|
|
{
|
|
|
|
DWORD size, type, total;
|
|
|
|
WCHAR *buffer, *p;
|
|
|
|
|
|
|
|
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
|
|
|
|
if (type != REG_MULTI_SZ) return;
|
|
|
|
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return;
|
|
|
|
if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
|
|
|
|
|
|
|
|
/* compare each string against all the existing ones */
|
|
|
|
total = size;
|
|
|
|
while (*strings)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
int len = lstrlenW(strings) + 1;
|
2002-04-02 04:57:50 +02:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
for (p = buffer; *p; p += lstrlenW(p) + 1)
|
|
|
|
if (!wcsicmp( p, strings )) break;
|
2002-04-02 04:57:50 +02:00
|
|
|
|
|
|
|
if (!*p) /* not found, need to append it */
|
|
|
|
{
|
|
|
|
memcpy( p, strings, len * sizeof(WCHAR) );
|
|
|
|
p[len] = 0;
|
2012-11-26 12:31:59 +01:00
|
|
|
total += len * sizeof(WCHAR);
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
|
|
|
strings += len;
|
|
|
|
}
|
|
|
|
if (total != size)
|
|
|
|
{
|
|
|
|
TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(buffer) );
|
|
|
|
RegSetValueExW( hkey, value, 0, REG_MULTI_SZ, (BYTE *)buffer, total );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* delete_multi_sz_value
|
|
|
|
*
|
|
|
|
* Remove a string from a multisz registry value.
|
|
|
|
*/
|
|
|
|
static void delete_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *string )
|
|
|
|
{
|
|
|
|
DWORD size, type;
|
|
|
|
WCHAR *buffer, *src, *dst;
|
|
|
|
|
|
|
|
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
|
|
|
|
if (type != REG_MULTI_SZ) return;
|
|
|
|
/* allocate double the size, one for value before and one for after */
|
|
|
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * 2 * sizeof(WCHAR) ))) return;
|
|
|
|
if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
|
|
|
|
src = buffer;
|
|
|
|
dst = buffer + size;
|
|
|
|
while (*src)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
int len = lstrlenW(src) + 1;
|
|
|
|
if (wcsicmp( src, string ))
|
2002-04-02 04:57:50 +02:00
|
|
|
{
|
|
|
|
memcpy( dst, src, len * sizeof(WCHAR) );
|
|
|
|
dst += len;
|
|
|
|
}
|
|
|
|
src += len;
|
|
|
|
}
|
|
|
|
*dst++ = 0;
|
|
|
|
if (dst != buffer + 2*size) /* did we remove something? */
|
|
|
|
{
|
|
|
|
TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(buffer + size) );
|
|
|
|
RegSetValueExW( hkey, value, 0, REG_MULTI_SZ,
|
|
|
|
(BYTE *)(buffer + size), dst - (buffer + size) );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* do_reg_operation
|
|
|
|
*
|
|
|
|
* Perform an add/delete registry operation depending on the flags.
|
|
|
|
*/
|
|
|
|
static BOOL do_reg_operation( HKEY hkey, const WCHAR *value, INFCONTEXT *context, INT flags )
|
|
|
|
{
|
|
|
|
DWORD type, size;
|
|
|
|
|
|
|
|
if (flags & (FLG_ADDREG_DELREG_BIT | FLG_ADDREG_DELVAL)) /* deletion */
|
|
|
|
{
|
|
|
|
if (*value && !(flags & FLG_DELREG_KEYONLY_COMMON))
|
|
|
|
{
|
|
|
|
if ((flags & FLG_DELREG_MULTI_SZ_DELSTRING) == FLG_DELREG_MULTI_SZ_DELSTRING)
|
|
|
|
{
|
|
|
|
WCHAR *str;
|
|
|
|
|
|
|
|
if (!SetupGetStringFieldW( context, 5, NULL, 0, &size ) || !size) return TRUE;
|
|
|
|
if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
SetupGetStringFieldW( context, 5, str, size, NULL );
|
|
|
|
delete_multi_sz_value( hkey, value, str );
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
}
|
|
|
|
else RegDeleteValueW( hkey, value );
|
|
|
|
}
|
2017-09-12 08:08:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RegDeleteTreeW( hkey, NULL );
|
|
|
|
NtDeleteKey( hkey );
|
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & (FLG_ADDREG_KEYONLY|FLG_ADDREG_KEYONLY_COMMON)) return TRUE;
|
|
|
|
|
|
|
|
if (flags & (FLG_ADDREG_NOCLOBBER|FLG_ADDREG_OVERWRITEONLY))
|
|
|
|
{
|
|
|
|
BOOL exists = !RegQueryValueExW( hkey, value, NULL, NULL, NULL, NULL );
|
|
|
|
if (exists && (flags & FLG_ADDREG_NOCLOBBER)) return TRUE;
|
2006-10-16 13:21:28 +02:00
|
|
|
if (!exists && (flags & FLG_ADDREG_OVERWRITEONLY)) return TRUE;
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(flags & FLG_ADDREG_TYPE_MASK)
|
|
|
|
{
|
|
|
|
case FLG_ADDREG_TYPE_SZ: type = REG_SZ; break;
|
|
|
|
case FLG_ADDREG_TYPE_MULTI_SZ: type = REG_MULTI_SZ; break;
|
|
|
|
case FLG_ADDREG_TYPE_EXPAND_SZ: type = REG_EXPAND_SZ; break;
|
|
|
|
case FLG_ADDREG_TYPE_BINARY: type = REG_BINARY; break;
|
|
|
|
case FLG_ADDREG_TYPE_DWORD: type = REG_DWORD; break;
|
|
|
|
case FLG_ADDREG_TYPE_NONE: type = REG_NONE; break;
|
|
|
|
default: type = flags >> 16; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & FLG_ADDREG_BINVALUETYPE) ||
|
|
|
|
(type == REG_DWORD && SetupGetFieldCount(context) == 5))
|
|
|
|
{
|
|
|
|
WCHAR *str = NULL;
|
|
|
|
|
|
|
|
if (type == REG_MULTI_SZ)
|
|
|
|
{
|
|
|
|
if (!SetupGetMultiSzFieldW( context, 5, NULL, 0, &size )) size = 0;
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
SetupGetMultiSzFieldW( context, 5, str, size, NULL );
|
|
|
|
}
|
|
|
|
if (flags & FLG_ADDREG_APPEND)
|
|
|
|
{
|
|
|
|
if (!str) return TRUE;
|
|
|
|
append_multi_sz_value( hkey, value, str, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* else fall through to normal string handling */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!SetupGetStringFieldW( context, 5, NULL, 0, &size )) size = 0;
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
SetupGetStringFieldW( context, 5, str, size, NULL );
|
2010-02-16 12:18:02 +01:00
|
|
|
if (type == REG_LINK) size--; /* no terminating null for symlinks */
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == REG_DWORD)
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
DWORD dw = str ? wcstoul( str, NULL, 0 ) : 0;
|
2006-10-13 23:32:50 +02:00
|
|
|
TRACE( "setting dword %s to %x\n", debugstr_w(value), dw );
|
2002-04-02 04:57:50 +02:00
|
|
|
RegSetValueExW( hkey, value, 0, type, (BYTE *)&dw, sizeof(dw) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(str) );
|
|
|
|
if (str) RegSetValueExW( hkey, value, 0, type, (BYTE *)str, size * sizeof(WCHAR) );
|
2020-02-11 09:00:21 +01:00
|
|
|
else RegSetValueExW( hkey, value, 0, type, (const BYTE *)L"", sizeof(WCHAR) );
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else /* get the binary data */
|
|
|
|
{
|
|
|
|
BYTE *data = NULL;
|
|
|
|
|
|
|
|
if (!SetupGetBinaryField( context, 5, NULL, 0, &size )) size = 0;
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
|
2006-10-13 23:32:50 +02:00
|
|
|
TRACE( "setting binary data %s len %d\n", debugstr_w(value), size );
|
2002-04-02 04:57:50 +02:00
|
|
|
SetupGetBinaryField( context, 5, data, size, NULL );
|
|
|
|
}
|
|
|
|
RegSetValueExW( hkey, value, 0, type, data, size );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* registry_callback
|
|
|
|
*
|
|
|
|
* Called once for each AddReg and DelReg entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL registry_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
struct registry_callback_info *info = arg;
|
|
|
|
INFCONTEXT context;
|
|
|
|
HKEY root_key, hkey;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine( &context, &context ))
|
|
|
|
{
|
2010-02-16 12:18:02 +01:00
|
|
|
DWORD options = 0;
|
2002-04-02 04:57:50 +02:00
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
INT flags;
|
|
|
|
|
|
|
|
/* get root */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 1, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2002-04-02 04:57:50 +02:00
|
|
|
continue;
|
|
|
|
if (!(root_key = get_root_key( buffer, info->default_root )))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* get key */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 2, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2002-04-02 04:57:50 +02:00
|
|
|
*buffer = 0;
|
|
|
|
|
|
|
|
/* get flags */
|
|
|
|
if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
|
|
|
|
|
|
|
|
if (!info->delete)
|
|
|
|
{
|
|
|
|
if (flags & FLG_ADDREG_DELREG_BIT) continue; /* ignore this entry */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!flags) flags = FLG_ADDREG_DELREG_BIT;
|
|
|
|
else if (!(flags & FLG_ADDREG_DELREG_BIT)) continue; /* ignore this entry */
|
|
|
|
}
|
2010-02-16 12:18:02 +01:00
|
|
|
/* Wine extension: magic support for symlinks */
|
|
|
|
if (flags >> 16 == REG_LINK) options = REG_OPTION_OPEN_LINK | REG_OPTION_CREATE_LINK;
|
2002-04-02 04:57:50 +02:00
|
|
|
|
|
|
|
if (info->delete || (flags & FLG_ADDREG_OVERWRITEONLY))
|
|
|
|
{
|
2010-02-16 12:18:02 +01:00
|
|
|
if (RegOpenKeyExW( root_key, buffer, options, MAXIMUM_ALLOWED, &hkey ))
|
|
|
|
continue; /* ignore if it doesn't exist */
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
2010-02-16 12:18:02 +01:00
|
|
|
else
|
2002-04-02 04:57:50 +02:00
|
|
|
{
|
2010-02-16 12:18:02 +01:00
|
|
|
DWORD res = RegCreateKeyExW( root_key, buffer, 0, NULL, options,
|
|
|
|
MAXIMUM_ALLOWED, NULL, &hkey, NULL );
|
|
|
|
if (res == ERROR_ALREADY_EXISTS && (options & REG_OPTION_CREATE_LINK))
|
|
|
|
res = RegCreateKeyExW( root_key, buffer, 0, NULL, REG_OPTION_OPEN_LINK,
|
|
|
|
MAXIMUM_ALLOWED, NULL, &hkey, NULL );
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
ERR( "could not create key %p %s\n", root_key, debugstr_w(buffer) );
|
|
|
|
continue;
|
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE( "key %p %s\n", root_key, debugstr_w(buffer) );
|
2002-04-02 04:57:50 +02:00
|
|
|
|
|
|
|
/* get value name */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2002-04-02 04:57:50 +02:00
|
|
|
*buffer = 0;
|
|
|
|
|
|
|
|
/* and now do it */
|
|
|
|
if (!do_reg_operation( hkey, buffer, &context, flags ))
|
|
|
|
{
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-27 01:47:10 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* do_register_dll
|
|
|
|
*
|
|
|
|
* Register or unregister a dll.
|
|
|
|
*/
|
2011-08-26 13:12:26 +02:00
|
|
|
static BOOL do_register_dll( struct register_dll_info *info, const WCHAR *path,
|
2004-02-27 01:47:10 +01:00
|
|
|
INT flags, INT timeout, const WCHAR *args )
|
|
|
|
{
|
|
|
|
HMODULE module;
|
|
|
|
HRESULT res;
|
|
|
|
SP_REGISTER_CONTROL_STATUSW status;
|
2006-03-17 23:08:27 +01:00
|
|
|
IMAGE_NT_HEADERS *nt;
|
2004-02-27 01:47:10 +01:00
|
|
|
|
|
|
|
status.cbSize = sizeof(status);
|
|
|
|
status.FileName = path;
|
|
|
|
status.FailureCode = SPREG_SUCCESS;
|
|
|
|
status.Win32Error = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
if (info->callback)
|
|
|
|
{
|
|
|
|
switch(info->callback( info->callback_context, SPFILENOTIFY_STARTREGISTRATION,
|
|
|
|
(UINT_PTR)&status, !info->unregister ))
|
|
|
|
{
|
|
|
|
case FILEOP_ABORT:
|
|
|
|
SetLastError( ERROR_OPERATION_ABORTED );
|
|
|
|
return FALSE;
|
|
|
|
case FILEOP_SKIP:
|
|
|
|
return TRUE;
|
|
|
|
case FILEOP_DOIT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(module = LoadLibraryExW( path, 0, LOAD_WITH_ALTERED_SEARCH_PATH )))
|
|
|
|
{
|
|
|
|
WARN( "could not load %s\n", debugstr_w(path) );
|
|
|
|
status.FailureCode = SPREG_LOADLIBRARY;
|
|
|
|
status.Win32Error = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-03-17 23:08:27 +01:00
|
|
|
if ((nt = RtlImageNtHeader( module )) && !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL))
|
|
|
|
{
|
|
|
|
/* file is an executable, not a dll */
|
|
|
|
STARTUPINFOW startup;
|
2011-03-09 10:08:16 +01:00
|
|
|
PROCESS_INFORMATION process_info;
|
2006-03-17 23:08:27 +01:00
|
|
|
WCHAR *cmd_line;
|
|
|
|
BOOL res;
|
2019-07-04 15:41:03 +02:00
|
|
|
DWORD len;
|
2006-03-17 23:08:27 +01:00
|
|
|
|
|
|
|
FreeLibrary( module );
|
|
|
|
module = NULL;
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!args) args = L"/RegServer";
|
2019-07-04 15:41:03 +02:00
|
|
|
len = lstrlenW(path) + lstrlenW(args) + 4;
|
|
|
|
cmd_line = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2020-02-11 09:00:21 +01:00
|
|
|
swprintf( cmd_line, len, L"\"%s\" %s", path, args );
|
2006-03-17 23:08:27 +01:00
|
|
|
memset( &startup, 0, sizeof(startup) );
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
TRACE( "executing %s\n", debugstr_w(cmd_line) );
|
2011-12-14 18:09:18 +01:00
|
|
|
res = CreateProcessW( path, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &process_info );
|
2006-03-17 23:08:27 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, cmd_line );
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
status.FailureCode = SPREG_LOADLIBRARY;
|
|
|
|
status.Win32Error = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
2011-03-09 10:08:16 +01:00
|
|
|
CloseHandle( process_info.hThread );
|
2006-03-17 23:08:27 +01:00
|
|
|
|
2011-03-09 10:08:16 +01:00
|
|
|
if (WaitForSingleObject( process_info.hProcess, timeout*1000 ) == WAIT_TIMEOUT)
|
2006-03-17 23:08:27 +01:00
|
|
|
{
|
|
|
|
/* timed out, kill the process */
|
2011-03-09 10:08:16 +01:00
|
|
|
TerminateProcess( process_info.hProcess, 1 );
|
2006-03-17 23:08:27 +01:00
|
|
|
status.FailureCode = SPREG_TIMEOUT;
|
|
|
|
status.Win32Error = ERROR_TIMEOUT;
|
|
|
|
}
|
2011-03-09 10:08:16 +01:00
|
|
|
CloseHandle( process_info.hProcess );
|
2006-03-17 23:08:27 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-02-27 01:47:10 +01:00
|
|
|
if (flags & FLG_REGSVR_DLLREGISTER)
|
|
|
|
{
|
|
|
|
const char *entry_point = info->unregister ? "DllUnregisterServer" : "DllRegisterServer";
|
|
|
|
HRESULT (WINAPI *func)(void) = (void *)GetProcAddress( module, entry_point );
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
status.FailureCode = SPREG_GETPROCADDR;
|
|
|
|
status.Win32Error = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "calling %s in %s\n", entry_point, debugstr_w(path) );
|
|
|
|
res = func();
|
|
|
|
|
|
|
|
if (FAILED(res))
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
WARN( "calling %s in %s returned error %x\n", entry_point, debugstr_w(path), res );
|
2004-02-27 01:47:10 +01:00
|
|
|
status.FailureCode = SPREG_REGSVR;
|
|
|
|
status.Win32Error = res;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FLG_REGSVR_DLLINSTALL)
|
|
|
|
{
|
|
|
|
HRESULT (WINAPI *func)(BOOL,LPCWSTR) = (void *)GetProcAddress( module, "DllInstall" );
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
status.FailureCode = SPREG_GETPROCADDR;
|
|
|
|
status.Win32Error = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "calling DllInstall(%d,%s) in %s\n",
|
|
|
|
!info->unregister, debugstr_w(args), debugstr_w(path) );
|
|
|
|
res = func( !info->unregister, args );
|
|
|
|
|
|
|
|
if (FAILED(res))
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
WARN( "calling DllInstall in %s returned error %x\n", debugstr_w(path), res );
|
2004-02-27 01:47:10 +01:00
|
|
|
status.FailureCode = SPREG_REGSVR;
|
|
|
|
status.Win32Error = res;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2011-08-26 13:12:26 +02:00
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
if (info->modules_count >= info->modules_size)
|
|
|
|
{
|
|
|
|
int new_size = max( 32, info->modules_size * 2 );
|
|
|
|
HMODULE *new = info->modules ?
|
|
|
|
HeapReAlloc( GetProcessHeap(), 0, info->modules, new_size * sizeof(*new) ) :
|
|
|
|
HeapAlloc( GetProcessHeap(), 0, new_size * sizeof(*new) );
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
info->modules_size = new_size;
|
|
|
|
info->modules = new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info->modules_count < info->modules_size) info->modules[info->modules_count++] = module;
|
|
|
|
else FreeLibrary( module );
|
|
|
|
}
|
2004-02-27 01:47:10 +01:00
|
|
|
if (info->callback) info->callback( info->callback_context, SPFILENOTIFY_ENDREGISTRATION,
|
|
|
|
(UINT_PTR)&status, !info->unregister );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* register_dlls_callback
|
|
|
|
*
|
|
|
|
* Called once for each RegisterDlls entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL register_dlls_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
struct register_dll_info *info = arg;
|
|
|
|
INFCONTEXT context;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine( &context, &context ))
|
|
|
|
{
|
|
|
|
WCHAR *path, *args, *p;
|
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
INT flags, timeout;
|
|
|
|
|
|
|
|
/* get directory */
|
|
|
|
if (!(path = PARSER_get_dest_dir( &context ))) continue;
|
|
|
|
|
|
|
|
/* get dll name */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2004-02-27 01:47:10 +01:00
|
|
|
goto done;
|
|
|
|
if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
|
2019-07-04 15:41:03 +02:00
|
|
|
(lstrlenW(path) + lstrlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
|
2004-02-27 01:47:10 +01:00
|
|
|
path = p;
|
2019-07-04 15:41:03 +02:00
|
|
|
p += lstrlenW(p);
|
2004-02-27 01:47:10 +01:00
|
|
|
if (p == path || p[-1] != '\\') *p++ = '\\';
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( p, buffer );
|
2004-02-27 01:47:10 +01:00
|
|
|
|
|
|
|
/* get flags */
|
|
|
|
if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
|
|
|
|
|
|
|
|
/* get timeout */
|
|
|
|
if (!SetupGetIntField( &context, 5, &timeout )) timeout = 60;
|
|
|
|
|
|
|
|
/* get command line */
|
|
|
|
args = NULL;
|
2018-09-15 00:10:28 +02:00
|
|
|
if (SetupGetStringFieldW( &context, 6, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2004-02-27 01:47:10 +01:00
|
|
|
args = buffer;
|
|
|
|
|
|
|
|
ret = do_register_dll( info, path, flags, timeout, args );
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, path );
|
|
|
|
if (!ret) break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-21 11:30:48 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fake_dlls_callback
|
|
|
|
*
|
|
|
|
* Called once for each WineFakeDlls entry in a given section.
|
|
|
|
*/
|
|
|
|
static BOOL fake_dlls_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
INFCONTEXT context;
|
|
|
|
BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine( &context, &context ))
|
|
|
|
{
|
|
|
|
WCHAR *path, *p;
|
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
|
|
|
|
/* get directory */
|
|
|
|
if (!(path = PARSER_get_dest_dir( &context ))) continue;
|
|
|
|
|
|
|
|
/* get dll name */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2006-03-21 11:30:48 +01:00
|
|
|
goto done;
|
|
|
|
if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
|
2019-07-04 15:41:03 +02:00
|
|
|
(lstrlenW(path) + lstrlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
|
2006-03-21 11:30:48 +01:00
|
|
|
path = p;
|
2019-07-04 15:41:03 +02:00
|
|
|
p += lstrlenW(p);
|
2006-03-21 11:30:48 +01:00
|
|
|
if (p == path || p[-1] != '\\') *p++ = '\\';
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( p, buffer );
|
2006-03-21 11:30:48 +01:00
|
|
|
|
|
|
|
/* get source dll */
|
2018-09-15 00:10:28 +02:00
|
|
|
if (SetupGetStringFieldW( &context, 4, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2006-03-21 11:30:48 +01:00
|
|
|
p = buffer; /* otherwise use target base name as default source */
|
|
|
|
|
|
|
|
create_fake_dll( path, p ); /* ignore errors */
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree( GetProcessHeap(), 0, path );
|
|
|
|
}
|
2012-01-19 17:14:21 +01:00
|
|
|
return TRUE;
|
2006-03-21 11:30:48 +01:00
|
|
|
}
|
|
|
|
|
2004-02-27 05:43:32 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* update_ini_callback
|
|
|
|
*
|
|
|
|
* Called once for each UpdateInis entry in a given section.
|
|
|
|
*/
|
2002-04-02 04:57:50 +02:00
|
|
|
static BOOL update_ini_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
2002-06-13 23:51:45 +02:00
|
|
|
INFCONTEXT context;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW( hinf, field, NULL, &context );
|
|
|
|
|
|
|
|
for (; ok; ok = SetupFindNextLine( &context, &context ))
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_INF_STRING_LENGTH];
|
|
|
|
WCHAR filename[MAX_INF_STRING_LENGTH];
|
|
|
|
WCHAR section[MAX_INF_STRING_LENGTH];
|
|
|
|
WCHAR entry[MAX_INF_STRING_LENGTH];
|
|
|
|
WCHAR string[MAX_INF_STRING_LENGTH];
|
|
|
|
LPWSTR divider;
|
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 1, filename, ARRAY_SIZE( filename ), NULL ))
|
2002-06-13 23:51:45 +02:00
|
|
|
continue;
|
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 2, section, ARRAY_SIZE( section ), NULL ))
|
2002-06-13 23:51:45 +02:00
|
|
|
continue;
|
|
|
|
|
2018-09-15 00:10:28 +02:00
|
|
|
if (!SetupGetStringFieldW( &context, 4, buffer, ARRAY_SIZE( buffer ), NULL ))
|
2002-06-13 23:51:45 +02:00
|
|
|
continue;
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
divider = wcschr(buffer,'=');
|
2002-06-13 23:51:45 +02:00
|
|
|
if (divider)
|
|
|
|
{
|
|
|
|
*divider = 0;
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(entry,buffer);
|
2002-06-13 23:51:45 +02:00
|
|
|
divider++;
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(string,divider);
|
2002-06-13 23:51:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW(entry,buffer);
|
2002-06-13 23:51:45 +02:00
|
|
|
string[0]=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Writing %s = %s in %s of file %s\n",debugstr_w(entry),
|
|
|
|
debugstr_w(string),debugstr_w(section),debugstr_w(filename));
|
|
|
|
WritePrivateProfileStringW(section,entry,string,filename);
|
|
|
|
|
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL update_ini_fields_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
FIXME( "should update ini fields %s\n", debugstr_w(field) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ini2reg_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
FIXME( "should do ini2reg %s\n", debugstr_w(field) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL logconf_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
FIXME( "should do logconf %s\n", debugstr_w(field) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-02-27 05:43:32 +01:00
|
|
|
static BOOL bitreg_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
FIXME( "should do bitreg %s\n", debugstr_w(field) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL profile_items_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
2008-10-31 16:34:16 +01:00
|
|
|
WCHAR lnkpath[MAX_PATH];
|
|
|
|
LPWSTR cmdline=NULL, lnkpath_end;
|
|
|
|
unsigned int name_size;
|
|
|
|
INFCONTEXT name_context, context;
|
|
|
|
int attrs=0;
|
|
|
|
|
|
|
|
TRACE( "(%s)\n", debugstr_w(field) );
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
if (SetupFindFirstLineW( hinf, field, L"Name", &name_context ))
|
2008-10-31 16:34:16 +01:00
|
|
|
{
|
|
|
|
SetupGetIntField( &name_context, 2, &attrs );
|
2008-11-13 17:33:09 +01:00
|
|
|
if (attrs & ~FLG_PROFITEM_GROUP) FIXME( "unhandled attributes: %x\n", attrs );
|
2008-10-31 16:34:16 +01:00
|
|
|
}
|
|
|
|
else return TRUE;
|
|
|
|
|
|
|
|
/* calculate filename */
|
|
|
|
SHGetFolderPathW( NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, lnkpath );
|
2019-07-04 15:41:03 +02:00
|
|
|
lnkpath_end = lnkpath + lstrlenW(lnkpath);
|
2008-10-31 16:34:16 +01:00
|
|
|
if (lnkpath_end[-1] != '\\') *lnkpath_end++ = '\\';
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!(attrs & FLG_PROFITEM_GROUP) && SetupFindFirstLineW( hinf, field, L"SubDir", &context ))
|
2008-10-31 16:34:16 +01:00
|
|
|
{
|
|
|
|
unsigned int subdir_size;
|
|
|
|
|
|
|
|
if (!SetupGetStringFieldW( &context, 1, lnkpath_end, (lnkpath+MAX_PATH)-lnkpath_end, &subdir_size ))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
lnkpath_end += subdir_size - 1;
|
|
|
|
if (lnkpath_end[-1] != '\\') *lnkpath_end++ = '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetupGetStringFieldW( &name_context, 1, lnkpath_end, (lnkpath+MAX_PATH)-lnkpath_end, &name_size ))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
lnkpath_end += name_size - 1;
|
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
if (attrs & FLG_PROFITEM_GROUP)
|
2008-10-31 16:34:16 +01:00
|
|
|
{
|
2008-11-13 17:33:09 +01:00
|
|
|
SHPathPrepareForWriteW( NULL, NULL, lnkpath, SHPPFW_DIRCREATE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IShellLinkW* shelllink=NULL;
|
|
|
|
IPersistFile* persistfile=NULL;
|
|
|
|
HRESULT initresult=E_FAIL;
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
if (lnkpath+MAX_PATH < lnkpath_end + 5) return TRUE;
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcpyW( lnkpath_end, L".lnk" );
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
TRACE( "link path: %s\n", debugstr_w(lnkpath) );
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
/* calculate command line */
|
2020-02-11 09:00:21 +01:00
|
|
|
if (SetupFindFirstLineW( hinf, field, L"CmdLine", &context ))
|
2008-10-31 16:34:16 +01:00
|
|
|
{
|
2008-11-13 17:33:09 +01:00
|
|
|
unsigned int dir_len=0, subdir_size=0, filename_size=0;
|
|
|
|
int dirid=0;
|
|
|
|
LPCWSTR dir;
|
|
|
|
LPWSTR cmdline_end;
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
SetupGetIntField( &context, 1, &dirid );
|
|
|
|
dir = DIRID_get_string( dirid );
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (dir) dir_len = lstrlenW(dir);
|
2008-11-13 17:33:09 +01:00
|
|
|
|
|
|
|
SetupGetStringFieldW( &context, 2, NULL, 0, &subdir_size );
|
|
|
|
SetupGetStringFieldW( &context, 3, NULL, 0, &filename_size );
|
|
|
|
|
|
|
|
if (dir_len && filename_size)
|
2008-10-31 16:34:16 +01:00
|
|
|
{
|
2008-11-13 17:33:09 +01:00
|
|
|
cmdline = cmdline_end = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * (dir_len+subdir_size+filename_size+1) );
|
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( cmdline_end, dir );
|
2008-11-13 17:33:09 +01:00
|
|
|
cmdline_end += dir_len;
|
2008-10-31 16:34:16 +01:00
|
|
|
if (cmdline_end[-1] != '\\') *cmdline_end++ = '\\';
|
2008-11-13 17:33:09 +01:00
|
|
|
|
|
|
|
if (subdir_size)
|
|
|
|
{
|
|
|
|
SetupGetStringFieldW( &context, 2, cmdline_end, subdir_size, NULL );
|
|
|
|
cmdline_end += subdir_size-1;
|
|
|
|
if (cmdline_end[-1] != '\\') *cmdline_end++ = '\\';
|
|
|
|
}
|
|
|
|
SetupGetStringFieldW( &context, 3, cmdline_end, filename_size, NULL );
|
|
|
|
TRACE( "cmdline: %s\n", debugstr_w(cmdline));
|
2008-10-31 16:34:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
if (!cmdline) return TRUE;
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
initresult = CoInitialize(NULL);
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2009-09-10 00:28:47 +02:00
|
|
|
if (FAILED(CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkW, (LPVOID*)&shelllink )))
|
2008-11-13 17:33:09 +01:00
|
|
|
goto done;
|
2008-10-31 16:34:16 +01:00
|
|
|
|
2008-11-13 17:33:09 +01:00
|
|
|
IShellLinkW_SetPath( shelllink, cmdline );
|
|
|
|
SHPathPrepareForWriteW( NULL, NULL, lnkpath, SHPPFW_DIRCREATE|SHPPFW_IGNOREFILENAME );
|
|
|
|
if (SUCCEEDED(IShellLinkW_QueryInterface( shelllink, &IID_IPersistFile, (LPVOID*)&persistfile)))
|
|
|
|
{
|
|
|
|
TRACE( "writing link: %s\n", debugstr_w(lnkpath) );
|
|
|
|
IPersistFile_Save( persistfile, lnkpath, FALSE );
|
|
|
|
IPersistFile_Release( persistfile );
|
|
|
|
}
|
|
|
|
IShellLinkW_Release( shelllink );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (SUCCEEDED(initresult)) CoUninitialize();
|
|
|
|
HeapFree( GetProcessHeap(), 0, cmdline );
|
2008-10-31 16:34:16 +01:00
|
|
|
}
|
|
|
|
|
2004-02-27 05:43:32 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL copy_inf_callback( HINF hinf, PCWSTR field, void *arg )
|
|
|
|
{
|
|
|
|
FIXME( "should do copy inf %s\n", debugstr_w(field) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-04-02 04:57:50 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* iterate_section_fields
|
|
|
|
*
|
|
|
|
* Iterate over all fields of a certain key of a certain section
|
|
|
|
*/
|
|
|
|
static BOOL iterate_section_fields( HINF hinf, PCWSTR section, PCWSTR key,
|
|
|
|
iterate_fields_func callback, void *arg )
|
|
|
|
{
|
|
|
|
WCHAR static_buffer[200];
|
|
|
|
WCHAR *buffer = static_buffer;
|
2018-09-15 00:10:28 +02:00
|
|
|
DWORD size = ARRAY_SIZE( static_buffer );
|
2002-04-02 04:57:50 +02:00
|
|
|
INFCONTEXT context;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
BOOL ok = SetupFindFirstLineW( hinf, section, key, &context );
|
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
UINT i, count = SetupGetFieldCount( &context );
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
if (!(buffer = get_field_string( &context, i, buffer, static_buffer, &size )))
|
|
|
|
goto done;
|
|
|
|
if (!callback( hinf, buffer, arg ))
|
|
|
|
{
|
2006-10-13 23:32:50 +02:00
|
|
|
WARN("callback failed for %s %s err %d\n",
|
2004-02-27 01:47:10 +01:00
|
|
|
debugstr_w(section), debugstr_w(buffer), GetLastError() );
|
2002-04-02 04:57:50 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok = SetupFindNextMatchLineW( &context, key, &context );
|
|
|
|
}
|
|
|
|
ret = TRUE;
|
|
|
|
done:
|
2006-06-07 10:55:33 +02:00
|
|
|
if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
|
2002-04-02 04:57:50 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallFilesFromInfSectionA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupInstallFilesFromInfSectionA( HINF hinf, HINF hlayout, HSPFILEQ queue,
|
|
|
|
PCSTR section, PCSTR src_root, UINT flags )
|
|
|
|
{
|
|
|
|
UNICODE_STRING sectionW;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz( §ionW, section ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!src_root)
|
|
|
|
ret = SetupInstallFilesFromInfSectionW( hinf, hlayout, queue, sectionW.Buffer,
|
|
|
|
NULL, flags );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UNICODE_STRING srcW;
|
|
|
|
if (RtlCreateUnicodeStringFromAsciiz( &srcW, src_root ))
|
|
|
|
{
|
|
|
|
ret = SetupInstallFilesFromInfSectionW( hinf, hlayout, queue, sectionW.Buffer,
|
|
|
|
srcW.Buffer, flags );
|
|
|
|
RtlFreeUnicodeString( &srcW );
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
}
|
|
|
|
RtlFreeUnicodeString( §ionW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallFilesFromInfSectionW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupInstallFilesFromInfSectionW( HINF hinf, HINF hlayout, HSPFILEQ queue,
|
|
|
|
PCWSTR section, PCWSTR src_root, UINT flags )
|
|
|
|
{
|
|
|
|
struct files_callback_info info;
|
|
|
|
|
|
|
|
info.queue = queue;
|
|
|
|
info.src_root = src_root;
|
|
|
|
info.copy_flags = flags;
|
|
|
|
info.layout = hlayout;
|
2020-02-11 09:00:21 +01:00
|
|
|
return iterate_section_fields( hinf, section, L"CopyFiles", copy_files_callback, &info );
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallFromInfSectionA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupInstallFromInfSectionA( HWND owner, HINF hinf, PCSTR section, UINT flags,
|
|
|
|
HKEY key_root, PCSTR src_root, UINT copy_flags,
|
|
|
|
PSP_FILE_CALLBACK_A callback, PVOID context,
|
|
|
|
HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data )
|
|
|
|
{
|
|
|
|
UNICODE_STRING sectionW, src_rootW;
|
|
|
|
struct callback_WtoA_context ctx;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
src_rootW.Buffer = NULL;
|
|
|
|
if (src_root && !RtlCreateUnicodeStringFromAsciiz( &src_rootW, src_root ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RtlCreateUnicodeStringFromAsciiz( §ionW, section ))
|
|
|
|
{
|
|
|
|
ctx.orig_context = context;
|
|
|
|
ctx.orig_handler = callback;
|
|
|
|
ret = SetupInstallFromInfSectionW( owner, hinf, sectionW.Buffer, flags, key_root,
|
|
|
|
src_rootW.Buffer, copy_flags, QUEUE_callback_WtoA,
|
|
|
|
&ctx, devinfo, devinfo_data );
|
|
|
|
RtlFreeUnicodeString( §ionW );
|
|
|
|
}
|
|
|
|
else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &src_rootW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallFromInfSectionW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupInstallFromInfSectionW( HWND owner, HINF hinf, PCWSTR section, UINT flags,
|
|
|
|
HKEY key_root, PCWSTR src_root, UINT copy_flags,
|
|
|
|
PSP_FILE_CALLBACK_W callback, PVOID context,
|
|
|
|
HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data )
|
|
|
|
{
|
2011-08-26 13:12:26 +02:00
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
2012-05-30 20:25:37 +02:00
|
|
|
if (flags & SPINST_REGISTRY)
|
|
|
|
{
|
|
|
|
struct registry_callback_info info;
|
|
|
|
|
|
|
|
info.default_root = key_root;
|
|
|
|
info.delete = FALSE;
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"WinePreInstall", registry_callback, &info ))
|
2012-05-30 20:25:37 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-03-18 11:40:13 +01:00
|
|
|
if (flags & SPINST_REGSVR)
|
|
|
|
{
|
|
|
|
if (iterate_section_fields( hinf, section, L"WineFakeDlls", fake_dlls_callback, NULL ))
|
|
|
|
cleanup_fake_dlls();
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
if (flags & SPINST_FILES)
|
|
|
|
{
|
|
|
|
struct files_callback_info info;
|
|
|
|
HSPFILEQ queue;
|
|
|
|
|
|
|
|
if (!(queue = SetupOpenFileQueue())) return FALSE;
|
|
|
|
info.queue = queue;
|
|
|
|
info.src_root = src_root;
|
|
|
|
info.copy_flags = copy_flags;
|
|
|
|
info.layout = hinf;
|
2020-02-11 09:00:21 +01:00
|
|
|
ret = (iterate_section_fields( hinf, section, L"CopyFiles", copy_files_callback, &info ) &&
|
|
|
|
iterate_section_fields( hinf, section, L"DelFiles", delete_files_callback, &info ) &&
|
|
|
|
iterate_section_fields( hinf, section, L"RenFiles", rename_files_callback, &info ) &&
|
2002-04-02 04:57:50 +02:00
|
|
|
SetupCommitFileQueueW( owner, queue, callback, context ));
|
|
|
|
SetupCloseFileQueue( queue );
|
|
|
|
if (!ret) return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPINST_INIFILES)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"UpdateInis", update_ini_callback, NULL ) ||
|
|
|
|
!iterate_section_fields( hinf, section, L"UpdateIniFields",
|
2002-04-02 04:57:50 +02:00
|
|
|
update_ini_fields_callback, NULL ))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPINST_INI2REG)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"Ini2Reg", ini2reg_callback, NULL ))
|
2002-04-02 04:57:50 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPINST_LOGCONFIG)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"LogConf", logconf_callback, NULL ))
|
2002-04-02 04:57:50 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-02-27 01:47:10 +01:00
|
|
|
if (flags & SPINST_REGSVR)
|
|
|
|
{
|
2021-03-18 11:40:13 +01:00
|
|
|
struct register_dll_info info = { .unregister = FALSE };
|
2020-02-10 21:41:31 +01:00
|
|
|
HRESULT hr;
|
2004-02-27 01:47:10 +01:00
|
|
|
|
|
|
|
if (flags & SPINST_REGISTERCALLBACKAWARE)
|
|
|
|
{
|
|
|
|
info.callback = callback;
|
|
|
|
info.callback_context = context;
|
|
|
|
}
|
2006-03-21 11:30:48 +01:00
|
|
|
|
2020-02-10 21:41:31 +01:00
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
ret = iterate_section_fields( hinf, section, L"RegisterDlls", register_dlls_callback, &info );
|
2011-08-26 13:12:26 +02:00
|
|
|
for (i = 0; i < info.modules_count; i++) FreeLibrary( info.modules[i] );
|
2020-02-10 21:41:31 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
CoUninitialize();
|
|
|
|
|
2011-08-26 13:12:26 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, info.modules );
|
|
|
|
if (!ret) return FALSE;
|
2004-02-27 01:47:10 +01:00
|
|
|
}
|
|
|
|
if (flags & SPINST_UNREGSVR)
|
|
|
|
{
|
2021-03-18 11:40:13 +01:00
|
|
|
struct register_dll_info info = { .unregister = TRUE };
|
2020-02-10 21:41:31 +01:00
|
|
|
HRESULT hr;
|
2004-02-27 01:47:10 +01:00
|
|
|
|
|
|
|
if (flags & SPINST_REGISTERCALLBACKAWARE)
|
|
|
|
{
|
|
|
|
info.callback = callback;
|
|
|
|
info.callback_context = context;
|
|
|
|
}
|
|
|
|
|
2020-02-10 21:41:31 +01:00
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
ret = iterate_section_fields( hinf, section, L"UnregisterDlls", register_dlls_callback, &info );
|
2011-08-26 13:12:26 +02:00
|
|
|
for (i = 0; i < info.modules_count; i++) FreeLibrary( info.modules[i] );
|
2020-02-10 21:41:31 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
CoUninitialize();
|
|
|
|
|
2011-08-26 13:12:26 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, info.modules );
|
|
|
|
if (!ret) return FALSE;
|
2004-02-27 01:47:10 +01:00
|
|
|
}
|
2002-04-02 04:57:50 +02:00
|
|
|
if (flags & SPINST_REGISTRY)
|
|
|
|
{
|
|
|
|
struct registry_callback_info info;
|
|
|
|
|
|
|
|
info.default_root = key_root;
|
|
|
|
info.delete = TRUE;
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"DelReg", registry_callback, &info ))
|
2002-04-02 04:57:50 +02:00
|
|
|
return FALSE;
|
2002-06-13 23:51:45 +02:00
|
|
|
info.delete = FALSE;
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"AddReg", registry_callback, &info ))
|
2002-06-13 23:51:45 +02:00
|
|
|
return FALSE;
|
2002-04-02 04:57:50 +02:00
|
|
|
}
|
2004-02-27 05:43:32 +01:00
|
|
|
if (flags & SPINST_BITREG)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"BitReg", bitreg_callback, NULL ))
|
2004-02-27 05:43:32 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPINST_PROFILEITEMS)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"ProfileItems", profile_items_callback, NULL ))
|
2004-02-27 05:43:32 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPINST_COPYINF)
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!iterate_section_fields( hinf, section, L"CopyINF", copy_inf_callback, NULL ))
|
2004-02-27 05:43:32 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-02-27 01:47:10 +01:00
|
|
|
|
2018-08-03 22:13:22 +02:00
|
|
|
SetLastError(ERROR_SUCCESS);
|
2002-04-02 04:57:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-02-27 05:43:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InstallHinfSectionW (SETUPAPI.@)
|
|
|
|
*
|
|
|
|
* NOTE: 'cmdline' is <section> <mode> <path> from
|
|
|
|
* RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>
|
|
|
|
*/
|
|
|
|
void WINAPI InstallHinfSectionW( HWND hwnd, HINSTANCE handle, LPCWSTR cmdline, INT show )
|
|
|
|
{
|
2005-11-03 20:34:03 +01:00
|
|
|
#ifdef __i386__
|
2020-02-11 09:00:21 +01:00
|
|
|
static const WCHAR nt_platformW[] = L".ntx86";
|
2018-09-20 11:16:05 +02:00
|
|
|
#elif defined(__x86_64__)
|
2020-02-11 09:00:21 +01:00
|
|
|
static const WCHAR nt_platformW[] = L".ntamd64";
|
2019-10-30 20:19:50 +01:00
|
|
|
#elif defined(__arm__)
|
2020-02-11 09:00:21 +01:00
|
|
|
static const WCHAR nt_platformW[] = L".ntarm";
|
2019-10-30 20:19:50 +01:00
|
|
|
#elif defined(__aarch64__)
|
2020-02-11 09:00:21 +01:00
|
|
|
static const WCHAR nt_platformW[] = L".ntarm64";
|
2005-11-03 20:34:03 +01:00
|
|
|
#else /* FIXME: other platforms */
|
2020-02-11 09:00:21 +01:00
|
|
|
static const WCHAR nt_platformW[] = L".nt";
|
2005-11-03 20:34:03 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
WCHAR *s, *path, section[MAX_PATH + ARRAY_SIZE( nt_platformW ) + ARRAY_SIZE( L".Services" )];
|
2004-02-27 05:43:32 +01:00
|
|
|
void *callback_context;
|
2007-06-23 00:32:56 +02:00
|
|
|
UINT mode;
|
2004-02-27 05:43:32 +01:00
|
|
|
HINF hinf;
|
|
|
|
|
|
|
|
TRACE("hwnd %p, handle %p, cmdline %s\n", hwnd, handle, debugstr_w(cmdline));
|
|
|
|
|
2005-11-03 20:34:03 +01:00
|
|
|
lstrcpynW( section, cmdline, MAX_PATH );
|
2004-02-27 05:43:32 +01:00
|
|
|
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!(s = wcschr( section, ' ' ))) return;
|
2006-08-09 19:20:48 +02:00
|
|
|
*s++ = 0;
|
|
|
|
while (*s == ' ') s++;
|
2019-07-04 15:41:03 +02:00
|
|
|
mode = wcstol( s, NULL, 10 );
|
2004-02-27 05:43:32 +01:00
|
|
|
|
2007-06-23 00:32:56 +02:00
|
|
|
/* quoted paths are not allowed on native, the rest of the command line is taken as the path */
|
2019-07-04 15:41:03 +02:00
|
|
|
if (!(s = wcschr( s, ' ' ))) return;
|
2006-08-09 19:20:48 +02:00
|
|
|
while (*s == ' ') s++;
|
2007-06-23 00:32:56 +02:00
|
|
|
path = s;
|
2004-02-27 05:43:32 +01:00
|
|
|
|
|
|
|
hinf = SetupOpenInfFileW( path, NULL, INF_STYLE_WIN4, NULL );
|
|
|
|
if (hinf == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
2005-11-03 20:34:03 +01:00
|
|
|
if (!(GetVersion() & 0x80000000))
|
|
|
|
{
|
|
|
|
INFCONTEXT context;
|
|
|
|
|
|
|
|
/* check for <section>.ntx86 (or corresponding name for the current platform)
|
|
|
|
* and then <section>.nt */
|
2019-07-04 15:41:03 +02:00
|
|
|
s = section + lstrlenW(section);
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcpyW( s, nt_platformW );
|
2005-11-03 20:34:03 +01:00
|
|
|
if (!(SetupFindFirstLineW( hinf, section, NULL, &context )))
|
|
|
|
{
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcpyW( s, L".nt" );
|
2006-08-09 19:20:48 +02:00
|
|
|
if (!(SetupFindFirstLineW( hinf, section, NULL, &context ))) *s = 0;
|
2005-11-03 20:34:03 +01:00
|
|
|
}
|
2006-08-09 19:20:48 +02:00
|
|
|
if (*s) TRACE( "using section %s instead\n", debugstr_w(section) );
|
2005-11-03 20:34:03 +01:00
|
|
|
}
|
|
|
|
|
2004-02-27 05:43:32 +01:00
|
|
|
callback_context = SetupInitDefaultQueueCallback( hwnd );
|
|
|
|
SetupInstallFromInfSectionW( hwnd, hinf, section, SPINST_ALL, NULL, NULL, SP_COPY_NEWER,
|
|
|
|
SetupDefaultQueueCallbackW, callback_context,
|
|
|
|
NULL, NULL );
|
|
|
|
SetupTermDefaultQueueCallback( callback_context );
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcatW( section, L".Services" );
|
2008-04-16 12:36:18 +02:00
|
|
|
SetupInstallServicesFromInfSectionW( hinf, section, 0 );
|
2004-02-27 05:43:32 +01:00
|
|
|
SetupCloseInfFile( hinf );
|
|
|
|
|
|
|
|
/* FIXME: should check the mode and maybe reboot */
|
|
|
|
/* there isn't much point in doing that since we */
|
|
|
|
/* don't yet handle deferred file copies anyway. */
|
2011-11-08 09:51:31 +01:00
|
|
|
if (mode & 7) TRACE( "should consider reboot, mode %u\n", mode );
|
2004-02-27 05:43:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InstallHinfSectionA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
void WINAPI InstallHinfSectionA( HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show )
|
|
|
|
{
|
|
|
|
UNICODE_STRING cmdlineW;
|
|
|
|
|
|
|
|
if (RtlCreateUnicodeStringFromAsciiz( &cmdlineW, cmdline ))
|
|
|
|
{
|
|
|
|
InstallHinfSectionW( hwnd, handle, cmdlineW.Buffer, show );
|
|
|
|
RtlFreeUnicodeString( &cmdlineW );
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 16:23:01 +02:00
|
|
|
|
2008-04-16 12:36:08 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* add_service
|
|
|
|
*
|
|
|
|
* Create a new service. Helper for SetupInstallServicesFromInfSectionW.
|
|
|
|
*/
|
|
|
|
static BOOL add_service( SC_HANDLE scm, HINF hinf, const WCHAR *name, const WCHAR *section, DWORD flags )
|
|
|
|
{
|
|
|
|
struct registry_callback_info info;
|
|
|
|
SC_HANDLE service;
|
|
|
|
INFCONTEXT context;
|
|
|
|
SERVICE_DESCRIPTIONW descr;
|
|
|
|
WCHAR *display_name, *start_name, *load_order, *binary_path;
|
|
|
|
INT service_type = 0, start_type = 0, error_control = 0;
|
|
|
|
DWORD size;
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
/* first the mandatory fields */
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!SetupFindFirstLineW( hinf, section, L"ServiceType", &context ) ||
|
2008-04-16 12:36:08 +02:00
|
|
|
!SetupGetIntField( &context, 1, &service_type ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!SetupFindFirstLineW( hinf, section, L"StartType", &context ) ||
|
2008-04-16 12:36:08 +02:00
|
|
|
!SetupGetIntField( &context, 1, &start_type ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!SetupFindFirstLineW( hinf, section, L"ErrorControl", &context ) ||
|
2008-04-16 12:36:08 +02:00
|
|
|
!SetupGetIntField( &context, 1, &error_control ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!(binary_path = dup_section_line_field( hinf, section, L"ServiceBinary", 1 )))
|
2008-04-16 12:36:08 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_BAD_SERVICE_INSTALLSECT );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now the optional fields */
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
display_name = dup_section_line_field( hinf, section, L"DisplayName", 1 );
|
|
|
|
start_name = dup_section_line_field( hinf, section, L"StartName", 1 );
|
|
|
|
load_order = dup_section_line_field( hinf, section, L"LoadOrderGroup", 1 );
|
|
|
|
descr.lpDescription = dup_section_line_field( hinf, section, L"Description", 1 );
|
2008-04-16 12:36:08 +02:00
|
|
|
|
|
|
|
/* FIXME: Dependencies field */
|
|
|
|
/* FIXME: Security field */
|
|
|
|
|
|
|
|
TRACE( "service %s display %s type %x start %x error %x binary %s order %s startname %s flags %x\n",
|
|
|
|
debugstr_w(name), debugstr_w(display_name), service_type, start_type, error_control,
|
|
|
|
debugstr_w(binary_path), debugstr_w(load_order), debugstr_w(start_name), flags );
|
|
|
|
|
|
|
|
service = CreateServiceW( scm, name, display_name, SERVICE_ALL_ACCESS,
|
|
|
|
service_type, start_type, error_control, binary_path,
|
|
|
|
load_order, NULL, NULL, start_name, NULL );
|
|
|
|
if (service)
|
|
|
|
{
|
|
|
|
if (descr.lpDescription) ChangeServiceConfig2W( service, SERVICE_CONFIG_DESCRIPTION, &descr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GetLastError() != ERROR_SERVICE_EXISTS) goto done;
|
|
|
|
service = OpenServiceW( scm, name, SERVICE_QUERY_CONFIG|SERVICE_CHANGE_CONFIG|SERVICE_START );
|
|
|
|
if (!service) goto done;
|
|
|
|
|
|
|
|
if (flags & (SPSVCINST_NOCLOBBER_DISPLAYNAME | SPSVCINST_NOCLOBBER_STARTTYPE |
|
|
|
|
SPSVCINST_NOCLOBBER_ERRORCONTROL | SPSVCINST_NOCLOBBER_LOADORDERGROUP))
|
|
|
|
{
|
|
|
|
QUERY_SERVICE_CONFIGW *config = NULL;
|
|
|
|
|
|
|
|
if (!QueryServiceConfigW( service, NULL, 0, &size ) &&
|
|
|
|
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
config = HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
if (config && QueryServiceConfigW( service, config, size, &size ))
|
|
|
|
{
|
|
|
|
if (flags & SPSVCINST_NOCLOBBER_STARTTYPE) start_type = config->dwStartType;
|
|
|
|
if (flags & SPSVCINST_NOCLOBBER_ERRORCONTROL) error_control = config->dwErrorControl;
|
|
|
|
if (flags & SPSVCINST_NOCLOBBER_DISPLAYNAME)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, display_name );
|
|
|
|
display_name = strdupW( config->lpDisplayName );
|
|
|
|
}
|
|
|
|
if (flags & SPSVCINST_NOCLOBBER_LOADORDERGROUP)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, load_order );
|
|
|
|
load_order = strdupW( config->lpLoadOrderGroup );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, config );
|
|
|
|
}
|
|
|
|
TRACE( "changing %s display %s type %x start %x error %x binary %s loadorder %s startname %s\n",
|
|
|
|
debugstr_w(name), debugstr_w(display_name), service_type, start_type, error_control,
|
|
|
|
debugstr_w(binary_path), debugstr_w(load_order), debugstr_w(start_name) );
|
|
|
|
|
|
|
|
ChangeServiceConfigW( service, service_type, start_type, error_control, binary_path,
|
|
|
|
load_order, NULL, NULL, start_name, NULL, display_name );
|
|
|
|
|
|
|
|
if (!(flags & SPSVCINST_NOCLOBBER_DESCRIPTION))
|
|
|
|
ChangeServiceConfig2W( service, SERVICE_CONFIG_DESCRIPTION, &descr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* execute the AddReg, DelReg and BitReg entries */
|
|
|
|
|
|
|
|
info.default_root = 0;
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services", &hkey ))
|
2008-04-16 12:36:08 +02:00
|
|
|
{
|
|
|
|
RegOpenKeyW( hkey, name, &info.default_root );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
if (info.default_root)
|
|
|
|
{
|
|
|
|
info.delete = TRUE;
|
2020-02-11 09:00:21 +01:00
|
|
|
iterate_section_fields( hinf, section, L"DelReg", registry_callback, &info );
|
2008-04-16 12:36:08 +02:00
|
|
|
info.delete = FALSE;
|
2020-02-11 09:00:21 +01:00
|
|
|
iterate_section_fields( hinf, section, L"AddReg", registry_callback, &info );
|
2008-04-16 12:36:08 +02:00
|
|
|
RegCloseKey( info.default_root );
|
|
|
|
}
|
2020-02-11 09:00:21 +01:00
|
|
|
iterate_section_fields( hinf, section, L"BitReg", bitreg_callback, NULL );
|
2008-04-16 12:36:08 +02:00
|
|
|
|
|
|
|
if (flags & SPSVCINST_STARTSERVICE) StartServiceW( service, 0, NULL );
|
|
|
|
CloseServiceHandle( service );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!service) WARN( "failed err %u\n", GetLastError() );
|
|
|
|
HeapFree( GetProcessHeap(), 0, binary_path );
|
|
|
|
HeapFree( GetProcessHeap(), 0, display_name );
|
|
|
|
HeapFree( GetProcessHeap(), 0, start_name );
|
|
|
|
HeapFree( GetProcessHeap(), 0, load_order );
|
|
|
|
HeapFree( GetProcessHeap(), 0, descr.lpDescription );
|
|
|
|
return service != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* del_service
|
|
|
|
*
|
|
|
|
* Delete service. Helper for SetupInstallServicesFromInfSectionW.
|
|
|
|
*/
|
|
|
|
static BOOL del_service( SC_HANDLE scm, HINF hinf, const WCHAR *name, DWORD flags )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SC_HANDLE service;
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
|
|
|
|
if (!(service = OpenServiceW( scm, name, SERVICE_STOP | DELETE )))
|
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) return TRUE;
|
|
|
|
WARN( "cannot open %s err %u\n", debugstr_w(name), GetLastError() );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (flags & SPSVCINST_STOPSERVICE) ControlService( service, SERVICE_CONTROL_STOP, &status );
|
|
|
|
TRACE( "deleting %s\n", debugstr_w(name) );
|
|
|
|
ret = DeleteService( service );
|
|
|
|
CloseServiceHandle( service );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-02 10:27:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallServicesFromInfSectionW (SETUPAPI.@)
|
|
|
|
*/
|
2008-04-16 12:36:08 +02:00
|
|
|
BOOL WINAPI SetupInstallServicesFromInfSectionW( HINF hinf, PCWSTR section, DWORD flags )
|
2007-11-02 10:27:40 +01:00
|
|
|
{
|
2008-04-16 12:36:08 +02:00
|
|
|
WCHAR service_name[MAX_INF_STRING_LENGTH];
|
|
|
|
WCHAR service_section[MAX_INF_STRING_LENGTH];
|
|
|
|
SC_HANDLE scm;
|
|
|
|
INFCONTEXT context;
|
|
|
|
INT section_flags;
|
2019-05-24 01:00:48 +02:00
|
|
|
BOOL ret = TRUE;
|
2008-04-16 12:36:08 +02:00
|
|
|
|
2019-05-24 01:00:48 +02:00
|
|
|
if (!SetupFindFirstLineW( hinf, section, NULL, &context ))
|
2012-07-09 11:07:37 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_SECTION_NOT_FOUND );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-16 12:36:08 +02:00
|
|
|
if (!(scm = OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS ))) return FALSE;
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
if (SetupFindFirstLineW( hinf, section, L"AddService", &context ))
|
2008-04-16 12:36:08 +02:00
|
|
|
{
|
2019-05-24 01:00:48 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL ))
|
|
|
|
continue;
|
|
|
|
if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0;
|
|
|
|
if (!SetupGetStringFieldW( &context, 3, service_section, MAX_INF_STRING_LENGTH, NULL ))
|
|
|
|
continue;
|
|
|
|
if (!(ret = add_service( scm, hinf, service_name, service_section, section_flags | flags )))
|
|
|
|
goto done;
|
2020-02-11 09:00:21 +01:00
|
|
|
} while (SetupFindNextMatchLineW( &context, L"AddService", &context ));
|
2008-04-16 12:36:08 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 09:00:21 +01:00
|
|
|
if (SetupFindFirstLineW( hinf, section, L"DelService", &context ))
|
2008-04-16 12:36:08 +02:00
|
|
|
{
|
2019-05-24 01:00:48 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL ))
|
|
|
|
continue;
|
|
|
|
if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0;
|
|
|
|
if (!(ret = del_service( scm, hinf, service_name, section_flags | flags ))) goto done;
|
2020-02-11 09:00:21 +01:00
|
|
|
} while (SetupFindNextMatchLineW( &context, L"AddService", &context ));
|
2008-04-16 12:36:08 +02:00
|
|
|
}
|
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
|
|
|
done:
|
|
|
|
CloseServiceHandle( scm );
|
|
|
|
return ret;
|
2007-11-02 10:27:40 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 12:36:08 +02:00
|
|
|
|
2007-10-20 16:23:01 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupInstallServicesFromInfSectionA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupInstallServicesFromInfSectionA( HINF Inf, PCSTR SectionName, DWORD Flags)
|
|
|
|
{
|
2008-03-26 13:17:31 +01:00
|
|
|
UNICODE_STRING SectionNameW;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (RtlCreateUnicodeStringFromAsciiz( &SectionNameW, SectionName ))
|
|
|
|
{
|
|
|
|
ret = SetupInstallServicesFromInfSectionW( Inf, SectionNameW.Buffer, Flags );
|
|
|
|
RtlFreeUnicodeString( &SectionNameW );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
|
|
|
|
return ret;
|
2007-10-20 16:23:01 +02:00
|
|
|
}
|
2009-11-09 22:44:06 +01:00
|
|
|
|
|
|
|
|
2010-04-05 19:37:58 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupGetInfFileListA (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupGetInfFileListA(PCSTR dir, DWORD style, PSTR buffer,
|
|
|
|
DWORD insize, PDWORD outsize)
|
|
|
|
{
|
|
|
|
UNICODE_STRING dirW;
|
|
|
|
PWSTR bufferW = NULL;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
DWORD outsizeA, outsizeW;
|
|
|
|
|
|
|
|
if ( dir )
|
|
|
|
RtlCreateUnicodeStringFromAsciiz( &dirW, dir );
|
|
|
|
else
|
|
|
|
dirW.Buffer = NULL;
|
|
|
|
|
|
|
|
if ( buffer )
|
|
|
|
bufferW = HeapAlloc( GetProcessHeap(), 0, insize * sizeof( WCHAR ));
|
|
|
|
|
|
|
|
ret = SetupGetInfFileListW( dirW.Buffer, style, bufferW, insize, &outsizeW);
|
|
|
|
|
|
|
|
if ( ret )
|
|
|
|
{
|
|
|
|
outsizeA = WideCharToMultiByte( CP_ACP, 0, bufferW, outsizeW,
|
|
|
|
buffer, insize, NULL, NULL);
|
|
|
|
if ( outsize ) *outsize = outsizeA;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, bufferW );
|
|
|
|
RtlFreeUnicodeString( &dirW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-09 22:44:06 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetupGetInfFileListW (SETUPAPI.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetupGetInfFileListW(PCWSTR dir, DWORD style, PWSTR buffer,
|
|
|
|
DWORD insize, PDWORD outsize)
|
|
|
|
{
|
2009-12-10 20:55:09 +01:00
|
|
|
WCHAR *filter, *fullname = NULL, *ptr = buffer;
|
|
|
|
DWORD dir_len, name_len = 20, size ;
|
|
|
|
WIN32_FIND_DATAW finddata;
|
|
|
|
HANDLE hdl;
|
|
|
|
if (style & ~( INF_STYLE_OLDNT | INF_STYLE_WIN4 |
|
|
|
|
INF_STYLE_CACHE_ENABLE | INF_STYLE_CACHE_DISABLE ))
|
|
|
|
{
|
|
|
|
FIXME( "unknown inf_style(s) 0x%x\n",
|
|
|
|
style & ~( INF_STYLE_OLDNT | INF_STYLE_WIN4 |
|
|
|
|
INF_STYLE_CACHE_ENABLE | INF_STYLE_CACHE_DISABLE ));
|
|
|
|
if( outsize ) *outsize = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if ((style & ( INF_STYLE_OLDNT | INF_STYLE_WIN4 )) == INF_STYLE_NONE)
|
|
|
|
{
|
|
|
|
FIXME( "inf_style INF_STYLE_NONE not handled\n" );
|
|
|
|
if( outsize ) *outsize = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (style & ( INF_STYLE_CACHE_ENABLE | INF_STYLE_CACHE_DISABLE ))
|
|
|
|
FIXME("ignored inf_style(s) %s %s\n",
|
|
|
|
( style & INF_STYLE_CACHE_ENABLE ) ? "INF_STYLE_CACHE_ENABLE" : "",
|
|
|
|
( style & INF_STYLE_CACHE_DISABLE ) ? "INF_STYLE_CACHE_DISABLE" : "");
|
|
|
|
if( dir )
|
|
|
|
{
|
|
|
|
DWORD att;
|
|
|
|
DWORD msize;
|
2019-07-04 15:41:03 +02:00
|
|
|
dir_len = lstrlenW( dir );
|
2009-12-10 20:55:09 +01:00
|
|
|
if ( !dir_len ) return FALSE;
|
|
|
|
msize = ( 7 + dir_len ) * sizeof( WCHAR ); /* \\*.inf\0 */
|
|
|
|
filter = HeapAlloc( GetProcessHeap(), 0, msize );
|
|
|
|
if( !filter )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( filter, dir );
|
2009-12-10 20:55:09 +01:00
|
|
|
if ( '\\' == filter[dir_len - 1] )
|
|
|
|
filter[--dir_len] = 0;
|
|
|
|
|
|
|
|
att = GetFileAttributesW( filter );
|
|
|
|
if (att != INVALID_FILE_ATTRIBUTES && !(att & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, filter );
|
|
|
|
SetLastError( ERROR_DIRECTORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD msize;
|
|
|
|
dir_len = GetWindowsDirectoryW( NULL, 0 );
|
|
|
|
msize = ( 7 + 4 + dir_len ) * sizeof( WCHAR );
|
|
|
|
filter = HeapAlloc( GetProcessHeap(), 0, msize );
|
|
|
|
if( !filter )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
GetWindowsDirectoryW( filter, msize );
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcatW( filter, L"\\inf" );
|
2009-12-10 20:55:09 +01:00
|
|
|
}
|
2020-02-11 09:00:21 +01:00
|
|
|
lstrcatW( filter, L"\\*.inf" );
|
2009-12-10 20:55:09 +01:00
|
|
|
|
|
|
|
hdl = FindFirstFileW( filter , &finddata );
|
|
|
|
if ( hdl == INVALID_HANDLE_VALUE )
|
|
|
|
{
|
|
|
|
if( outsize ) *outsize = 1;
|
|
|
|
HeapFree( GetProcessHeap(), 0, filter );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
size = 1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
WCHAR signature[ MAX_PATH ];
|
|
|
|
BOOL valid = FALSE;
|
2019-07-04 15:41:03 +02:00
|
|
|
DWORD len = lstrlenW( finddata.cFileName );
|
2009-12-10 20:55:09 +01:00
|
|
|
if (!fullname || ( name_len < len ))
|
|
|
|
{
|
|
|
|
name_len = ( name_len < len ) ? len : name_len;
|
|
|
|
HeapFree( GetProcessHeap(), 0, fullname );
|
|
|
|
fullname = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
( 2 + dir_len + name_len) * sizeof( WCHAR ));
|
|
|
|
if( !fullname )
|
|
|
|
{
|
2012-10-28 16:16:58 +01:00
|
|
|
FindClose( hdl );
|
2009-12-10 20:55:09 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, filter );
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( fullname, filter );
|
2009-12-10 20:55:09 +01:00
|
|
|
}
|
|
|
|
fullname[ dir_len + 1] = 0; /* keep '\\' */
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcatW( fullname, finddata.cFileName );
|
2020-02-11 09:00:21 +01:00
|
|
|
if (!GetPrivateProfileStringW( L"Version", L"Signature", NULL, signature, MAX_PATH, fullname ))
|
2009-12-10 20:55:09 +01:00
|
|
|
signature[0] = 0;
|
|
|
|
if( INF_STYLE_OLDNT & style )
|
2020-02-11 09:00:21 +01:00
|
|
|
valid = wcsicmp( L"$Chicago$", signature ) && wcsicmp( L"$WINDOWS NT$", signature );
|
2009-12-10 20:55:09 +01:00
|
|
|
if( INF_STYLE_WIN4 & style )
|
2020-02-11 09:00:21 +01:00
|
|
|
valid = valid || !wcsicmp( L"$Chicago$", signature ) ||
|
|
|
|
!wcsicmp( L"$WINDOWS NT$", signature );
|
2009-12-10 20:55:09 +01:00
|
|
|
if( valid )
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
size += 1 + lstrlenW( finddata.cFileName );
|
2009-12-10 20:55:09 +01:00
|
|
|
if( ptr && insize >= size )
|
|
|
|
{
|
2019-07-04 15:41:03 +02:00
|
|
|
lstrcpyW( ptr, finddata.cFileName );
|
|
|
|
ptr += 1 + lstrlenW( finddata.cFileName );
|
2009-12-10 20:55:09 +01:00
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while( FindNextFileW( hdl, &finddata ));
|
|
|
|
FindClose( hdl );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, fullname );
|
|
|
|
HeapFree( GetProcessHeap(), 0, filter );
|
|
|
|
if( outsize ) *outsize = size;
|
2009-11-09 22:44:06 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|