winspool: Remove unvarying unicode parameter from WINSPOOL_GetDriverInfoFromReg.

This commit is contained in:
Jeremy White 2009-12-01 10:46:13 -06:00 committed by Alexandre Julliard
parent 10e70fbd18
commit 108230c19e
1 changed files with 45 additions and 83 deletions

View File

@ -3145,7 +3145,7 @@ static DWORD WINSPOOL_GetDWORDFromReg(HKEY hkey, LPCSTR ValueName)
*/ */
static BOOL get_filename_from_reg(HKEY hkey, LPCWSTR driverdir, DWORD dirlen, LPCWSTR ValueName, static BOOL get_filename_from_reg(HKEY hkey, LPCWSTR driverdir, DWORD dirlen, LPCWSTR ValueName,
LPBYTE out, DWORD outlen, LPDWORD needed, BOOL unicode) LPBYTE out, DWORD outlen, LPDWORD needed)
{ {
WCHAR filename[MAX_PATH]; WCHAR filename[MAX_PATH];
DWORD size; DWORD size;
@ -3184,13 +3184,7 @@ static BOOL get_filename_from_reg(HKEY hkey, LPCWSTR driverdir, DWORD dirlen, LP
/* we must build the full Path */ /* we must build the full Path */
*needed += dirlen; *needed += dirlen;
if ((out) && (outlen > dirlen)) { if ((out) && (outlen > dirlen)) {
if (unicode) { lstrcpyW((LPWSTR)out, driverdir);
lstrcpyW((LPWSTR)out, driverdir);
}
else
{
WideCharToMultiByte(CP_ACP, 0, driverdir, -1, (LPSTR)out, outlen, NULL, NULL);
}
out += dirlen; out += dirlen;
outlen -= dirlen; outlen -= dirlen;
} }
@ -3199,27 +3193,14 @@ static BOOL get_filename_from_reg(HKEY hkey, LPCWSTR driverdir, DWORD dirlen, LP
} }
/* write the filename */ /* write the filename */
if (unicode) { size = (lstrlenW(ptr) + 1) * sizeof(WCHAR);
size = (lstrlenW(ptr) + 1) * sizeof(WCHAR); if ((out) && (outlen >= size)) {
if ((out) && (outlen >= size)) { lstrcpyW((LPWSTR)out, ptr);
lstrcpyW((LPWSTR)out, ptr); out += size;
out += size; outlen -= size;
outlen -= size;
}
else
out = NULL;
} }
else else
{ out = NULL;
size = WideCharToMultiByte(CP_ACP, 0, ptr, -1, NULL, 0, NULL, NULL);
if ((out) && (outlen >= size)) {
WideCharToMultiByte(CP_ACP, 0, ptr, -1, (LPSTR)out, outlen, NULL, NULL);
out += size;
outlen -= size;
}
else
out = NULL;
}
*needed += size; *needed += size;
ptr += lstrlenW(ptr)+1; ptr += lstrlenW(ptr)+1;
if ((type != REG_MULTI_SZ) || (!ptr[0])) ptr = NULL; if ((type != REG_MULTI_SZ) || (!ptr[0])) ptr = NULL;
@ -3229,7 +3210,7 @@ static BOOL get_filename_from_reg(HKEY hkey, LPCWSTR driverdir, DWORD dirlen, LP
/* write the multisz-termination */ /* write the multisz-termination */
if (type == REG_MULTI_SZ) { if (type == REG_MULTI_SZ) {
size = (unicode) ? sizeof(WCHAR) : 1; size = sizeof(WCHAR);
*needed += size; *needed += size;
if (out && (outlen >= size)) { if (out && (outlen >= size)) {
@ -4211,8 +4192,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
LPBYTE ptr, /* DRIVER_INFO */ LPBYTE ptr, /* DRIVER_INFO */
LPBYTE pDriverStrings, /* strings buffer */ LPBYTE pDriverStrings, /* strings buffer */
DWORD cbBuf, /* size of string buffer */ DWORD cbBuf, /* size of string buffer */
LPDWORD pcbNeeded, /* space needed for str. */ LPDWORD pcbNeeded) /* space needed for str. */
BOOL unicode) /* type of strings */
{ {
DWORD size, tmp; DWORD size, tmp;
HKEY hkeyDriver; HKEY hkeyDriver;
@ -4221,23 +4201,15 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
LPBYTE strPtr = pDriverStrings; LPBYTE strPtr = pDriverStrings;
LPDRIVER_INFO_8W di = (LPDRIVER_INFO_8W) ptr; LPDRIVER_INFO_8W di = (LPDRIVER_INFO_8W) ptr;
TRACE("(%p, %s, %p, %d, %p, %p, %d, %d)\n", hkeyDrivers, TRACE("(%p, %s, %p, %d, %p, %p, %d)\n", hkeyDrivers,
debugstr_w(DriverName), env, debugstr_w(DriverName), env,
Level, di, pDriverStrings, cbBuf, unicode); Level, di, pDriverStrings, cbBuf);
if (di) ZeroMemory(di, di_sizeof[Level]); if (di) ZeroMemory(di, di_sizeof[Level]);
if (unicode) { *pcbNeeded = (lstrlenW(DriverName) + 1) * sizeof(WCHAR);
*pcbNeeded = (lstrlenW(DriverName) + 1) * sizeof(WCHAR); if (*pcbNeeded <= cbBuf)
if (*pcbNeeded <= cbBuf) strcpyW((LPWSTR)strPtr, DriverName);
strcpyW((LPWSTR)strPtr, DriverName);
}
else
{
*pcbNeeded = WideCharToMultiByte(CP_ACP, 0, DriverName, -1, NULL, 0, NULL, NULL);
if (*pcbNeeded <= cbBuf)
WideCharToMultiByte(CP_ACP, 0, DriverName, -1, (LPSTR)strPtr, *pcbNeeded, NULL, NULL);
}
/* pName for level 1 has a different offset! */ /* pName for level 1 has a different offset! */
if (Level == 1) { if (Level == 1) {
@ -4262,8 +4234,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
lstrcatW(driverdir, backslashW); lstrcatW(driverdir, backslashW);
/* dirlen must not include the terminating zero */ /* dirlen must not include the terminating zero */
dirlen = (unicode) ? lstrlenW(driverdir) * sizeof(WCHAR) : dirlen = lstrlenW(driverdir) * sizeof(WCHAR);
WideCharToMultiByte(CP_ACP, 0, driverdir, -1, NULL, 0, NULL, NULL) -1;
if (!DriverName[0] || RegOpenKeyW(hkeyDrivers, DriverName, &hkeyDriver) != ERROR_SUCCESS) { if (!DriverName[0] || RegOpenKeyW(hkeyDrivers, DriverName, &hkeyDriver) != ERROR_SUCCESS) {
ERR("Can't find driver %s in registry\n", debugstr_w(DriverName)); ERR("Can't find driver %s in registry\n", debugstr_w(DriverName));
@ -4272,50 +4243,41 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
} }
/* pEnvironment */ /* pEnvironment */
if (unicode) size = (lstrlenW(env->envname) + 1) * sizeof(WCHAR);
size = (lstrlenW(env->envname) + 1) * sizeof(WCHAR);
else
size = WideCharToMultiByte(CP_ACP, 0, env->envname, -1, NULL, 0, NULL, NULL);
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) { if (*pcbNeeded <= cbBuf) {
if (unicode) { lstrcpyW((LPWSTR)strPtr, env->envname);
lstrcpyW((LPWSTR)strPtr, env->envname);
}
else
{
WideCharToMultiByte(CP_ACP, 0, env->envname, -1, (LPSTR)strPtr, size, NULL, NULL);
}
if (di) di->pEnvironment = (LPWSTR)strPtr; if (di) di->pEnvironment = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL; strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
} }
/* .pDriverPath is the Graphics rendering engine. /* .pDriverPath is the Graphics rendering engine.
The full Path is required to avoid a crash in some apps */ The full Path is required to avoid a crash in some apps */
if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, DriverW, strPtr, 0, &size, unicode)) { if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, DriverW, strPtr, 0, &size)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
get_filename_from_reg(hkeyDriver, driverdir, dirlen, DriverW, strPtr, size, &tmp, unicode); get_filename_from_reg(hkeyDriver, driverdir, dirlen, DriverW, strPtr, size, &tmp);
if (di) di->pDriverPath = (LPWSTR)strPtr; if (di) di->pDriverPath = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL; strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
} }
/* .pDataFile: For postscript-drivers, this is the ppd-file */ /* .pDataFile: For postscript-drivers, this is the ppd-file */
if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Data_FileW, strPtr, 0, &size, unicode)) { if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Data_FileW, strPtr, 0, &size)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
get_filename_from_reg(hkeyDriver, driverdir, dirlen, Data_FileW, strPtr, size, &size, unicode); get_filename_from_reg(hkeyDriver, driverdir, dirlen, Data_FileW, strPtr, size, &size);
if (di) di->pDataFile = (LPWSTR)strPtr; if (di) di->pDataFile = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pConfigFile is the Driver user Interface */ /* .pConfigFile is the Driver user Interface */
if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Configuration_FileW, strPtr, 0, &size, unicode)) { if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Configuration_FileW, strPtr, 0, &size)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
get_filename_from_reg(hkeyDriver, driverdir, dirlen, Configuration_FileW, strPtr, size, &size, unicode); get_filename_from_reg(hkeyDriver, driverdir, dirlen, Configuration_FileW, strPtr, size, &size);
if (di) di->pConfigFile = (LPWSTR)strPtr; if (di) di->pConfigFile = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
@ -4334,27 +4296,27 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
} }
/* .pHelpFile */ /* .pHelpFile */
if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Help_FileW, strPtr, 0, &size, unicode)) { if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Help_FileW, strPtr, 0, &size)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
get_filename_from_reg(hkeyDriver, driverdir, dirlen, Help_FileW, strPtr, size, &size, unicode); get_filename_from_reg(hkeyDriver, driverdir, dirlen, Help_FileW, strPtr, size, &size);
if (di) di->pHelpFile = (LPWSTR)strPtr; if (di) di->pHelpFile = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pDependentFiles */ /* .pDependentFiles */
if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Dependent_FilesW, strPtr, 0, &size, unicode)) { if (get_filename_from_reg(hkeyDriver, driverdir, dirlen, Dependent_FilesW, strPtr, 0, &size)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
get_filename_from_reg(hkeyDriver, driverdir, dirlen, Dependent_FilesW, strPtr, size, &size, unicode); get_filename_from_reg(hkeyDriver, driverdir, dirlen, Dependent_FilesW, strPtr, size, &size);
if (di) di->pDependentFiles = (LPWSTR)strPtr; if (di) di->pDependentFiles = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
else if (GetVersion() & 0x80000000) { else if (GetVersion() & 0x80000000) {
/* PowerPoint XP expects that pDependentFiles is always valid on win9x */ /* PowerPoint XP expects that pDependentFiles is always valid on win9x */
size = 2 * ((unicode) ? sizeof(WCHAR) : 1); size = 2 * sizeof(WCHAR);
*pcbNeeded += size; *pcbNeeded += size;
if ((*pcbNeeded <= cbBuf) && strPtr) ZeroMemory(strPtr, size); if ((*pcbNeeded <= cbBuf) && strPtr) ZeroMemory(strPtr, size);
@ -4363,20 +4325,20 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
} }
/* .pMonitorName is the optional Language Monitor */ /* .pMonitorName is the optional Language Monitor */
if (WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if (*pcbNeeded <= cbBuf) if (*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, size, &size, TRUE);
if (di) di->pMonitorName = (LPWSTR)strPtr; if (di) di->pMonitorName = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pDefaultDataType */ /* .pDefaultDataType */
if (WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, size, &size, TRUE);
if (di) di->pDefaultDataType = (LPWSTR)strPtr; if (di) di->pDefaultDataType = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
@ -4389,10 +4351,10 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
} }
/* .pszzPreviousNames */ /* .pszzPreviousNames */
if (WINSPOOL_GetStringFromReg(hkeyDriver, Previous_NamesW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, Previous_NamesW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, Previous_NamesW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, Previous_NamesW, strPtr, size, &size, TRUE);
if (di) di->pszzPreviousNames = (LPWSTR)strPtr; if (di) di->pszzPreviousNames = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
@ -4408,40 +4370,40 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
TRACE("%s: DriverDate + DriverVersion not supported\n", debugstr_w(DriverName)); TRACE("%s: DriverDate + DriverVersion not supported\n", debugstr_w(DriverName));
/* .pszMfgName */ /* .pszMfgName */
if (WINSPOOL_GetStringFromReg(hkeyDriver, ManufacturerW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, ManufacturerW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, ManufacturerW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, ManufacturerW, strPtr, size, &size, TRUE);
if (di) di->pszMfgName = (LPWSTR)strPtr; if (di) di->pszMfgName = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pszOEMUrl */ /* .pszOEMUrl */
if (WINSPOOL_GetStringFromReg(hkeyDriver, OEM_UrlW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, OEM_UrlW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, OEM_UrlW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, OEM_UrlW, strPtr, size, &size, TRUE);
if (di) di->pszOEMUrl = (LPWSTR)strPtr; if (di) di->pszOEMUrl = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pszHardwareID */ /* .pszHardwareID */
if (WINSPOOL_GetStringFromReg(hkeyDriver, HardwareIDW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, HardwareIDW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, HardwareIDW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, HardwareIDW, strPtr, size, &size, TRUE);
if (di) di->pszHardwareID = (LPWSTR)strPtr; if (di) di->pszHardwareID = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
/* .pszProvider */ /* .pszProvider */
if (WINSPOOL_GetStringFromReg(hkeyDriver, ProviderW, strPtr, 0, &size, unicode)) { if (WINSPOOL_GetStringFromReg(hkeyDriver, ProviderW, strPtr, 0, &size, TRUE)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
WINSPOOL_GetStringFromReg(hkeyDriver, ProviderW, strPtr, size, &size, unicode); WINSPOOL_GetStringFromReg(hkeyDriver, ProviderW, strPtr, size, &size, TRUE);
if (di) di->pszProvider = (LPWSTR)strPtr; if (di) di->pszProvider = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
@ -4527,7 +4489,7 @@ BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment,
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverName, if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverName,
env, Level, pDriverInfo, ptr, env, Level, pDriverInfo, ptr,
(cbBuf < size) ? 0 : cbBuf - size, (cbBuf < size) ? 0 : cbBuf - size,
&needed, TRUE)) { &needed)) {
RegCloseKey(hkeyDrivers); RegCloseKey(hkeyDrivers);
return FALSE; return FALSE;
} }
@ -4899,7 +4861,7 @@ static BOOL WINSPOOL_EnumPrinterDrivers(LPWSTR pName, LPCWSTR pEnvironment,
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverNameW, if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverNameW,
env, Level, table_ptr, data_ptr, env, Level, table_ptr, data_ptr,
(cbBuf < *pcbNeeded) ? 0 : cbBuf - *pcbNeeded, (cbBuf < *pcbNeeded) ? 0 : cbBuf - *pcbNeeded,
&needed, TRUE)) { &needed)) {
RegCloseKey(hkeyDrivers); RegCloseKey(hkeyDrivers);
return FALSE; return FALSE;
} }