1999-04-18 14:09:21 +02:00
|
|
|
/*
|
|
|
|
* Module/Library loadorder
|
|
|
|
*
|
|
|
|
* Copyright 1999 Bertho Stultiens
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2001-03-20 03:11:08 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winerror.h"
|
2000-12-03 04:14:29 +01:00
|
|
|
#include "file.h"
|
1999-04-22 11:13:38 +02:00
|
|
|
#include "module.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(module);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
#define LOADORDER_ALLOC_CLUSTER 32 /* Allocate with 32 entries at a time */
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
typedef struct module_loadorder
|
|
|
|
{
|
|
|
|
const char *modulename;
|
|
|
|
enum loadorder_type loadorder[LOADORDER_NTYPES];
|
|
|
|
} module_loadorder_t;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
struct loadorder_list
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int alloc;
|
|
|
|
module_loadorder_t *order;
|
|
|
|
};
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/* default load-order if nothing specified */
|
|
|
|
/* the list must remain sorted by dll name */
|
|
|
|
static module_loadorder_t default_order_list[] =
|
|
|
|
{
|
|
|
|
{ "display", { LOADORDER_BI, 0, 0, 0 } },
|
2002-03-28 23:06:56 +01:00
|
|
|
{ "gdi.exe", { LOADORDER_BI, 0, 0, 0 } },
|
2001-03-20 03:11:08 +01:00
|
|
|
{ "gdi32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "glide2x", { LOADORDER_SO, LOADORDER_DLL, 0, 0 } },
|
|
|
|
{ "glide3x", { LOADORDER_SO, LOADORDER_DLL, 0, 0 } },
|
|
|
|
{ "icmp", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "kernel", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "kernel32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "keyboard", { LOADORDER_BI, 0, 0, 0 } },
|
2002-03-28 23:06:56 +01:00
|
|
|
{ "krnl386.exe", { LOADORDER_BI, 0, 0, 0 } },
|
2001-03-20 03:11:08 +01:00
|
|
|
{ "mmsystem", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "mouse", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "ntdll", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "odbc32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "system", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "toolhelp", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "ttydrv", { LOADORDER_BI, 0, 0, 0 } },
|
2002-03-28 23:06:56 +01:00
|
|
|
{ "user.exe", { LOADORDER_BI, 0, 0, 0 } },
|
2001-03-20 03:11:08 +01:00
|
|
|
{ "user32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "w32skrnl", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "winaspi", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "windebug", { LOADORDER_DLL, LOADORDER_BI, 0, 0 } },
|
|
|
|
{ "winedos", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wineps", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wing", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "winmm", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "winsock", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wnaspi32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wow32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wprocs", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "ws2_32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "wsock32", { LOADORDER_BI, 0, 0, 0 } },
|
|
|
|
{ "x11drv", { LOADORDER_BI, 0, 0, 0 } }
|
1999-04-25 11:15:25 +02:00
|
|
|
};
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
static const struct loadorder_list default_list =
|
|
|
|
{
|
|
|
|
sizeof(default_order_list)/sizeof(default_order_list[0]),
|
|
|
|
sizeof(default_order_list)/sizeof(default_order_list[0]),
|
|
|
|
default_order_list
|
2000-02-19 21:51:01 +01:00
|
|
|
};
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
static struct loadorder_list cmdline_list;
|
|
|
|
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* cmp_sort_func (internal, static)
|
|
|
|
*
|
|
|
|
* Sorting and comparing function used in sort and search of loadorder
|
|
|
|
* entries.
|
|
|
|
*/
|
|
|
|
static int cmp_sort_func(const void *s1, const void *s2)
|
|
|
|
{
|
2000-12-03 04:14:29 +01:00
|
|
|
return FILE_strcasecmp(((module_loadorder_t *)s1)->modulename,
|
|
|
|
((module_loadorder_t *)s2)->modulename);
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* get_tok (internal, static)
|
|
|
|
*
|
|
|
|
* strtok wrapper for non-destructive buffer writing.
|
|
|
|
* NOTE: strtok is not reentrant and therefore this code is neither.
|
|
|
|
*/
|
|
|
|
static char *get_tok(const char *str, const char *delim)
|
|
|
|
{
|
|
|
|
static char *buf = NULL;
|
|
|
|
char *cptr;
|
|
|
|
|
1999-04-19 18:44:22 +02:00
|
|
|
if(!str && !buf)
|
1999-04-18 14:09:21 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(str && buf)
|
|
|
|
{
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
1999-04-18 14:09:21 +02:00
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(str && !buf)
|
|
|
|
{
|
2001-07-24 23:45:22 +02:00
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
|
|
|
|
strcpy( buf, str );
|
1999-04-18 14:09:21 +02:00
|
|
|
cptr = strtok(buf, delim);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cptr = strtok(NULL, delim);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cptr)
|
|
|
|
{
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
1999-04-18 14:09:21 +02:00
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
return cptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* ParseLoadOrder (internal, static)
|
|
|
|
*
|
|
|
|
* Parses the loadorder options from the configuration and puts it into
|
|
|
|
* a structure.
|
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
static BOOL ParseLoadOrder(char *order, enum loadorder_type lo[])
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2000-11-30 02:15:30 +01:00
|
|
|
static int warn;
|
1999-04-18 14:09:21 +02:00
|
|
|
char *cptr;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
cptr = get_tok(order, ", \t");
|
|
|
|
while(cptr)
|
|
|
|
{
|
2001-03-20 03:11:08 +01:00
|
|
|
enum loadorder_type type = LOADORDER_INVALID;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if(n >= LOADORDER_NTYPES-1)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2001-03-20 03:11:08 +01:00
|
|
|
ERR("More than existing %d module-types specified, rest ignored\n", LOADORDER_NTYPES-1);
|
1999-04-18 14:09:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(*cptr)
|
|
|
|
{
|
|
|
|
case 'N': /* Native */
|
2001-03-20 03:11:08 +01:00
|
|
|
case 'n': type = LOADORDER_DLL; break;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
case 'E': /* Elfdll */
|
2000-11-30 02:15:30 +01:00
|
|
|
case 'e':
|
2000-12-09 04:25:34 +01:00
|
|
|
if (!warn++) MESSAGE("Load order 'elfdll' no longer supported, ignored\n");
|
2000-11-30 02:15:30 +01:00
|
|
|
break;
|
1999-04-18 14:09:21 +02:00
|
|
|
case 'S': /* So */
|
2001-03-20 03:11:08 +01:00
|
|
|
case 's': type = LOADORDER_SO; break;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
case 'B': /* Builtin */
|
2001-03-20 03:11:08 +01:00
|
|
|
case 'b': type = LOADORDER_BI; break;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
default:
|
1999-06-12 17:45:58 +02:00
|
|
|
ERR("Invalid load order module-type '%s', ignored\n", cptr);
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if(type != LOADORDER_INVALID) lo[n++] = type;
|
1999-04-18 14:09:21 +02:00
|
|
|
cptr = get_tok(NULL, ", \t");
|
|
|
|
}
|
2001-03-20 03:11:08 +01:00
|
|
|
lo[n] = LOADORDER_INVALID;
|
1999-04-18 14:09:21 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* AddLoadOrder (internal, static)
|
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* Adds an entry in the list of command-line overrides.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
static BOOL AddLoadOrder(module_loadorder_t *plo)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* TRACE(module, "'%s' -> %08lx\n", plo->modulename, *(DWORD *)(plo->loadorder)); */
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
for(i = 0; i < cmdline_list.count; i++)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2001-03-20 03:11:08 +01:00
|
|
|
if(!cmp_sort_func(plo, &cmdline_list.order[i] ))
|
|
|
|
{
|
|
|
|
/* replace existing option */
|
|
|
|
memcpy( cmdline_list.order[i].loadorder, plo->loadorder, sizeof(plo->loadorder));
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if (i >= cmdline_list.alloc)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
|
|
|
/* No space in current array, make it larger */
|
2001-03-20 03:11:08 +01:00
|
|
|
cmdline_list.alloc += LOADORDER_ALLOC_CLUSTER;
|
|
|
|
cmdline_list.order = HeapReAlloc(GetProcessHeap(), 0, cmdline_list.order,
|
|
|
|
cmdline_list.alloc * sizeof(module_loadorder_t));
|
|
|
|
if(!cmdline_list.order)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
1999-06-12 17:45:58 +02:00
|
|
|
MESSAGE("Virtual memory exhausted\n");
|
1999-04-18 14:09:21 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2001-03-20 03:11:08 +01:00
|
|
|
memcpy(cmdline_list.order[i].loadorder, plo->loadorder, sizeof(plo->loadorder));
|
2001-07-24 23:45:22 +02:00
|
|
|
cmdline_list.order[i].modulename = HeapAlloc(GetProcessHeap(), 0, strlen(plo->modulename)+1);
|
|
|
|
strcpy( (char *)cmdline_list.order[i].modulename, plo->modulename );
|
2001-03-20 03:11:08 +01:00
|
|
|
cmdline_list.count++;
|
1999-04-18 14:09:21 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* AddLoadOrderSet (internal, static)
|
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* Adds a set of entries in the list of command-line overrides from the key parameter.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
static BOOL AddLoadOrderSet(char *key, char *order)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
|
|
|
module_loadorder_t ldo;
|
|
|
|
char *cptr;
|
|
|
|
|
|
|
|
/* Parse the loadorder before the rest because strtok is not reentrant */
|
2001-03-20 03:11:08 +01:00
|
|
|
if(!ParseLoadOrder(order, ldo.loadorder))
|
1999-04-18 14:09:21 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cptr = get_tok(key, ", \t");
|
|
|
|
while(cptr)
|
|
|
|
{
|
1999-04-26 16:55:24 +02:00
|
|
|
char *ext = strrchr(cptr, '.');
|
2002-03-22 02:01:09 +01:00
|
|
|
if(ext && !FILE_strcasecmp( ext, ".dll" )) *ext = 0;
|
1999-04-18 14:09:21 +02:00
|
|
|
ldo.modulename = cptr;
|
2001-03-20 03:11:08 +01:00
|
|
|
if(!AddLoadOrder(&ldo)) return FALSE;
|
1999-04-18 14:09:21 +02:00
|
|
|
cptr = get_tok(NULL, ", \t");
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2001-03-20 03:11:08 +01:00
|
|
|
* MODULE_AddLoadOrderOption
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* The commandline option is in the form:
|
|
|
|
* name[,name,...]=native[,b,...]
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
void MODULE_AddLoadOrderOption( const char *option )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2001-07-24 23:45:22 +02:00
|
|
|
char *value, *key = HeapAlloc(GetProcessHeap(), 0, strlen(option)+1);
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2001-07-24 23:45:22 +02:00
|
|
|
strcpy( key, option );
|
|
|
|
if (!(value = strchr(key, '='))) goto error;
|
2001-03-20 03:11:08 +01:00
|
|
|
*value++ = '\0';
|
|
|
|
|
|
|
|
TRACE("Commandline override '%s' = '%s'\n", key, value);
|
|
|
|
|
|
|
|
if (!AddLoadOrderSet(key, value)) goto error;
|
|
|
|
HeapFree(GetProcessHeap(), 0, key);
|
|
|
|
|
|
|
|
/* sort the array for quick lookup */
|
|
|
|
qsort(cmdline_list.order, cmdline_list.count, sizeof(cmdline_list.order[0]), cmp_sort_func);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
MESSAGE( "Syntax: -dll name[,name[,...]]={native|so|builtin}[,{n|s|b}[,...]]\n"
|
|
|
|
" - 'name' is the name of any dll without extension\n"
|
|
|
|
" - the order of loading (native, so and builtin) can be abbreviated\n"
|
|
|
|
" with the first letter\n"
|
|
|
|
" - the option can be specified multiple times\n"
|
|
|
|
" Example:\n"
|
|
|
|
" -dll comdlg32,commdlg=n -dll shell,shell32=b\n" );
|
|
|
|
ExitProcess(1);
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2001-03-20 03:11:08 +01:00
|
|
|
* set_registry_keys
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* Set individual registry keys for a multiple dll specification
|
|
|
|
* Helper for MODULE_InitLoadOrder().
|
|
|
|
*/
|
|
|
|
inline static void set_registry_keys( HKEY hkey, char *module, const char *buffer )
|
|
|
|
{
|
|
|
|
static int warn;
|
|
|
|
char *p = get_tok( module, ", \t" );
|
|
|
|
|
|
|
|
TRACE( "converting \"%s\" = \"%s\"\n", module, buffer );
|
|
|
|
|
|
|
|
if (!warn)
|
|
|
|
MESSAGE( "Warning: setting multiple modules in a single DllOverrides entry is no longer\n"
|
|
|
|
"recommended. It is suggested that you rewrite the configuration file entry:\n\n"
|
|
|
|
"\"%s\" = \"%s\"\n\n"
|
|
|
|
"into something like:\n\n", module, buffer );
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
if (!warn) MESSAGE( "\"%s\" = \"%s\"\n", p, buffer );
|
|
|
|
/* only set it if not existing already */
|
|
|
|
if (RegQueryValueExA( hkey, p, 0, NULL, NULL, NULL ) == ERROR_FILE_NOT_FOUND)
|
|
|
|
RegSetValueExA( hkey, p, 0, REG_SZ, buffer, strlen(buffer)+1 );
|
|
|
|
p = get_tok( NULL, ", \t" );
|
|
|
|
}
|
|
|
|
if (!warn) MESSAGE( "\n" );
|
|
|
|
warn = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* MODULE_InitLoadOrder
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* Convert entries containing multiple dll names (old syntax) to the
|
|
|
|
* new one dll module per entry syntax
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
void MODULE_InitLoadOrder(void)
|
|
|
|
{
|
|
|
|
char module[80];
|
|
|
|
char buffer[1024];
|
|
|
|
char *p;
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD index = 0;
|
|
|
|
|
|
|
|
if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\DllOverrides", &hkey ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD type, count = sizeof(buffer), name_len = sizeof(module);
|
|
|
|
|
|
|
|
if (RegEnumValueA( hkey, index, module, &name_len, NULL, &type, buffer, &count )) break;
|
|
|
|
p = module;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
p += strcspn( p, ", \t" );
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
RegDeleteValueA( hkey, module );
|
|
|
|
set_registry_keys( hkey, module, buffer );
|
|
|
|
}
|
|
|
|
else index++;
|
|
|
|
}
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_list_load_order
|
|
|
|
*
|
|
|
|
* Get the load order for a given module from the command-line or
|
|
|
|
* default lists.
|
|
|
|
*/
|
|
|
|
static BOOL get_list_load_order( const char *module, const struct loadorder_list *list,
|
|
|
|
enum loadorder_type lo[] )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2001-08-11 00:29:21 +02:00
|
|
|
module_loadorder_t tmp, *res = NULL;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
tmp.modulename = module;
|
2001-08-11 00:29:21 +02:00
|
|
|
/* some bsearch implementations (Solaris) are buggy when the number of items is 0 */
|
|
|
|
if (list->count && (res = bsearch(&tmp, list->order, list->count, sizeof(list->order[0]), cmp_sort_func)))
|
2001-03-20 03:11:08 +01:00
|
|
|
memcpy( lo, res->loadorder, sizeof(res->loadorder) );
|
|
|
|
return (res != NULL);
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_app_load_order
|
|
|
|
*
|
2001-03-21 21:33:11 +01:00
|
|
|
* Get the load order for a given module from the app-specific DllOverrides list.
|
|
|
|
* Also look for default '*' key if no module key found.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2001-03-21 21:33:11 +01:00
|
|
|
static BOOL get_app_load_order( const char *module, enum loadorder_type lo[], BOOL *got_default )
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
|
|
|
HKEY hkey, appkey;
|
|
|
|
DWORD count, type, res;
|
|
|
|
char buffer[MAX_PATH+16], *appname, *p;
|
|
|
|
|
|
|
|
if (!GetModuleFileName16( GetCurrentTask(), buffer, MAX_PATH ) &&
|
|
|
|
!GetModuleFileNameA( 0, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
WARN( "could not get module file name loading %s\n", module );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
appname = buffer;
|
|
|
|
if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
|
|
|
if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
|
|
|
|
|
|
|
TRACE( "searching '%s' in AppDefaults\\%s\\DllOverrides\n", module, appname );
|
|
|
|
|
|
|
|
if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &hkey ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* open AppDefaults\\appname\\DllOverrides key */
|
|
|
|
strcat( appname, "\\DllOverrides" );
|
|
|
|
res = RegOpenKeyA( hkey, appname, &appkey );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
if (res) return FALSE;
|
|
|
|
|
|
|
|
count = sizeof(buffer);
|
2001-03-21 21:33:11 +01:00
|
|
|
if ((res = RegQueryValueExA( appkey, module, NULL, &type, buffer, &count )))
|
|
|
|
{
|
|
|
|
if (!(res = RegQueryValueExA( appkey, "*", NULL, &type, buffer, &count )))
|
|
|
|
*got_default = TRUE;
|
|
|
|
}
|
|
|
|
else TRACE( "got app loadorder '%s' for '%s'\n", buffer, module );
|
2001-03-20 03:11:08 +01:00
|
|
|
RegCloseKey( appkey );
|
|
|
|
if (res) return FALSE;
|
|
|
|
return ParseLoadOrder( buffer, lo );
|
|
|
|
}
|
1999-04-25 11:15:25 +02:00
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_standard_load_order
|
|
|
|
*
|
|
|
|
* Get the load order for a given module from the main DllOverrides list
|
2001-03-21 21:33:11 +01:00
|
|
|
* Also look for default '*' key if no module key found.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2001-03-21 21:33:11 +01:00
|
|
|
static BOOL get_standard_load_order( const char *module, enum loadorder_type lo[],
|
|
|
|
BOOL *got_default )
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD count, type, res;
|
|
|
|
char buffer[80];
|
|
|
|
|
|
|
|
if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\DllOverrides", &hkey ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
count = sizeof(buffer);
|
2001-03-21 21:33:11 +01:00
|
|
|
if ((res = RegQueryValueExA( hkey, module, NULL, &type, buffer, &count )))
|
|
|
|
{
|
|
|
|
if (!(res = RegQueryValueExA( hkey, "*", NULL, &type, buffer, &count )))
|
|
|
|
*got_default = TRUE;
|
|
|
|
}
|
|
|
|
else TRACE( "got standard loadorder '%s' for '%s'\n", buffer, module );
|
2001-03-20 03:11:08 +01:00
|
|
|
RegCloseKey( hkey );
|
|
|
|
if (res) return FALSE;
|
|
|
|
return ParseLoadOrder( buffer, lo );
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_default_load_order
|
|
|
|
*
|
|
|
|
* Get the default load order if nothing specified for a given dll.
|
|
|
|
*/
|
|
|
|
static void get_default_load_order( enum loadorder_type lo[] )
|
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
static enum loadorder_type default_loadorder[LOADORDER_NTYPES];
|
|
|
|
static int loaded;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if (!loaded)
|
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
HKEY hkey;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if (!(res = RegOpenKeyA( HKEY_LOCAL_MACHINE,
|
|
|
|
"Software\\Wine\\Wine\\Config\\DllDefaults", &hkey )))
|
|
|
|
{
|
|
|
|
DWORD type, count = sizeof(buffer);
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
res = RegQueryValueExA( hkey, "DefaultLoadOrder", NULL, &type, buffer, &count );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
if (res) strcpy( buffer, "n,b,s" );
|
|
|
|
ParseLoadOrder( buffer, default_loadorder );
|
|
|
|
loaded = 1;
|
|
|
|
TRACE( "got default loadorder '%s'\n", buffer );
|
|
|
|
}
|
|
|
|
memcpy( lo, default_loadorder, sizeof(default_loadorder) );
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* MODULE_GetLoadOrder (internal)
|
|
|
|
*
|
|
|
|
* Locate the loadorder of a module.
|
|
|
|
* Any path is stripped from the path-argument and so are the extension
|
1999-09-03 14:36:20 +02:00
|
|
|
* '.dll' and '.exe'. A lookup in the table can yield an override for
|
1999-07-30 20:06:35 +02:00
|
|
|
* the specific dll. Otherwise the default load order is returned.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2001-03-20 03:11:08 +01:00
|
|
|
void MODULE_GetLoadOrder( enum loadorder_type loadorder[], const char *path, BOOL win32 )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
|
|
|
char fname[256];
|
2000-08-28 23:33:28 +02:00
|
|
|
char sysdir[MAX_PATH+1];
|
1999-04-18 14:09:21 +02:00
|
|
|
char *cptr;
|
|
|
|
char *name;
|
|
|
|
int len;
|
2001-03-21 21:33:11 +01:00
|
|
|
BOOL got_app_default = FALSE, got_std_default = FALSE;
|
|
|
|
enum loadorder_type lo_default[LOADORDER_NTYPES];
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2000-05-12 22:18:14 +02:00
|
|
|
TRACE("looking for %s\n", path);
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
if ( ! GetSystemDirectoryA ( sysdir, MAX_PATH ) ) goto done;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2000-08-28 23:33:28 +02:00
|
|
|
/* Strip path information for 16 bit modules or if the module
|
|
|
|
resides in the system directory */
|
2000-12-03 04:14:29 +01:00
|
|
|
if ( !win32 || !FILE_strncasecmp ( sysdir, path, strlen (sysdir) ) )
|
2000-08-28 23:33:28 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
cptr = strrchr(path, '\\');
|
|
|
|
if(!cptr)
|
|
|
|
name = strrchr(path, '/');
|
|
|
|
else
|
|
|
|
name = strrchr(cptr, '/');
|
|
|
|
|
|
|
|
if(!name)
|
|
|
|
name = cptr ? cptr+1 : (char *)path;
|
|
|
|
else
|
|
|
|
name++;
|
|
|
|
|
|
|
|
if((cptr = strchr(name, ':')) != NULL) /* Also strip drive if in format 'C:MODULE.DLL' */
|
|
|
|
name = cptr+1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
name = (char *)path;
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
len = strlen(name);
|
|
|
|
if(len >= sizeof(fname) || len <= 0)
|
|
|
|
{
|
2001-03-20 03:11:08 +01:00
|
|
|
WARN("Path '%s' -> '%s' reduces to zilch or just too large...\n", path, name);
|
|
|
|
goto done;
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(fname, name);
|
2002-03-28 23:06:56 +01:00
|
|
|
if(len >= 4 && !FILE_strcasecmp(fname+len-4, ".dll")) fname[len-4] = '\0';
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/* check command-line first */
|
|
|
|
if (get_list_load_order( fname, &cmdline_list, loadorder )) return;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/* then app-specific config */
|
2001-03-21 21:33:11 +01:00
|
|
|
if (get_app_load_order( fname, loadorder, &got_app_default ))
|
|
|
|
{
|
|
|
|
if (!got_app_default) return;
|
|
|
|
/* save the default value for later on */
|
|
|
|
memcpy( lo_default, loadorder, sizeof(lo_default) );
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/* then standard config */
|
2001-03-21 21:33:11 +01:00
|
|
|
if (get_standard_load_order( fname, loadorder, &got_std_default ))
|
|
|
|
{
|
|
|
|
if (!got_std_default) return;
|
|
|
|
/* save the default value for later on */
|
|
|
|
if (!got_app_default) memcpy( lo_default, loadorder, sizeof(lo_default) );
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/* then compiled-in defaults */
|
|
|
|
if (get_list_load_order( fname, &default_list, loadorder )) return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* last, return the default */
|
2001-03-21 21:33:11 +01:00
|
|
|
if (got_app_default || got_std_default)
|
|
|
|
memcpy( loadorder, lo_default, sizeof(lo_default) );
|
|
|
|
else
|
|
|
|
get_default_load_order( loadorder );
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|