winspool: Use printenv_t for GetDriverInfoFromReg
Detlef Riekenberg
wine.dev at web.de
Sun Jul 22 22:39:49 CDT 2007
This is the first step for Bug 5734
The Adobe Postscript-Driver expect a full Path for .pDriverPath
(DRIVER_INFO_*).
We need to Prefix the Filename with the Path from
GetPrinterDriverDirectory and a version-dependent subdirectory
I hardcode the Version and the subdir, because wine support only
version 0 for Win9x and version 3 for NT.
Changelog:
- winspool: Use printenv_t for GetDriverInfoFromReg
While working on the code, I found this bugs, but these are for
later patches
- we use "wineps16" for NT (expected: "wineps.drv") (constify by Andrew)
- the test crash in wine, when we set the emulated windows version
to win9x (test from Dimitry)
--
By by ... Detlef
-------------- next part --------------
>From 3f380957ef9a0409e93e24288dc46938ffdc6721 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Sun, 22 Jul 2007 17:21:25 +0200
Subject: [PATCH] winspool: Use printenv_t for GetDriverInfoFromReg
---
dlls/winspool.drv/info.c | 93 ++++++++++++++++++++++++++--------------------
1 files changed, 53 insertions(+), 40 deletions(-)
diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index bc0f400..f5ed7ef 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -4242,7 +4242,7 @@ BOOL WINAPI EnumPrintersA(DWORD dwType,
static BOOL WINSPOOL_GetDriverInfoFromReg(
HKEY hkeyDrivers,
LPWSTR DriverName,
- LPCWSTR pEnvironment,
+ const printenv_t * env,
DWORD Level,
LPBYTE ptr, /* DRIVER_INFO */
LPBYTE pDriverStrings, /* strings buffer */
@@ -4253,60 +4253,63 @@ static BOOL WINSPOOL_GetDriverInfoFromRe
DWORD size, tmp;
HKEY hkeyDriver;
LPBYTE strPtr = pDriverStrings;
+ LPDRIVER_INFO_8W di = (LPDRIVER_INFO_8W) ptr;
- TRACE("%s,%s,%d,%p,%p,%d,%d\n",
- debugstr_w(DriverName), debugstr_w(pEnvironment),
- Level, ptr, pDriverStrings, cbBuf, unicode);
+ TRACE("(%p, %s, %p, %d, %p, %p, %d, %d)\n", hkeyDrivers,
+ debugstr_w(DriverName), env,
+ Level, di, pDriverStrings, cbBuf, unicode);
- if(unicode) {
+ if (unicode) {
*pcbNeeded = (lstrlenW(DriverName) + 1) * sizeof(WCHAR);
- if (*pcbNeeded <= cbBuf)
- 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);
+ if (*pcbNeeded <= cbBuf)
+ 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);
}
- if(Level == 1) {
- if(ptr)
- ((PDRIVER_INFO_1W) ptr)->pName = (LPWSTR) strPtr;
+
+ /* pName for level 1 has a different offset! */
+ if (Level == 1) {
+ if (di) ((LPDRIVER_INFO_1W) di)->pName = (LPWSTR) strPtr;
return TRUE;
- } else {
- if(ptr)
- ((PDRIVER_INFO_2W) ptr)->pName = (LPWSTR) strPtr;
- strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
}
- if(!DriverName[0] || RegOpenKeyW(hkeyDrivers, DriverName, &hkeyDriver) != ERROR_SUCCESS) {
+ /* .cVersion and .pName for level > 1 */
+ if (di) {
+ di->cVersion = env->driverversion;
+ di->pName = (LPWSTR) strPtr;
+ strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
+ }
+
+ if (!DriverName[0] || RegOpenKeyW(hkeyDrivers, DriverName, &hkeyDriver) != ERROR_SUCCESS) {
ERR("Can't find driver %s in registry\n", debugstr_w(DriverName));
SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER); /* ? */
return FALSE;
}
- if(ptr)
- ((PDRIVER_INFO_2A) ptr)->cVersion = (GetVersion() & 0x80000000) ? 0 : 3; /* FIXME: add 1, 2 */
-
- if(!pEnvironment)
- pEnvironment = DefaultEnvironmentW;
- if(unicode)
- size = (lstrlenW(pEnvironment) + 1) * sizeof(WCHAR);
+ /* pEnvironment */
+ if (unicode)
+ size = (lstrlenW(env->envname) + 1) * sizeof(WCHAR);
else
- size = WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1, NULL, 0,
- NULL, NULL);
+ size = WideCharToMultiByte(CP_ACP, 0, env->envname, -1, NULL, 0, NULL, NULL);
+
*pcbNeeded += size;
- if(*pcbNeeded <= cbBuf) {
- if(unicode)
- strcpyW((LPWSTR)strPtr, pEnvironment);
+ if (*pcbNeeded <= cbBuf) {
+ if (unicode) {
+ lstrcpyW((LPWSTR)strPtr, env->envname);
+ }
else
- WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1,
- (LPSTR)strPtr, size, NULL, NULL);
- if(ptr)
- ((PDRIVER_INFO_2W) ptr)->pEnvironment = (LPWSTR)strPtr;
+ {
+ WideCharToMultiByte(CP_ACP, 0, env->envname, -1, (LPSTR)strPtr, size, NULL, NULL);
+ }
+ if (di) di->pEnvironment = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
}
+
if(WINSPOOL_GetStringFromReg(hkeyDriver, DriverW, strPtr, 0, &size,
unicode)) {
*pcbNeeded += size;
@@ -4408,6 +4411,7 @@ static BOOL WINSPOOL_GetPrinterDriver(HA
DWORD ret, type, size, needed = 0;
LPBYTE ptr = NULL;
HKEY hkeyPrinter, hkeyPrinters, hkeyDrivers;
+ const printenv_t * env;
TRACE("(%p,%s,%d,%p,%d,%p)\n",hPrinter,debugstr_w(pEnvironment),
Level,pDriverInfo,cbBuf, pcbNeeded);
@@ -4418,10 +4422,15 @@ static BOOL WINSPOOL_GetPrinterDriver(HA
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
+
if(Level < 1 || Level > 6) {
SetLastError(ERROR_INVALID_LEVEL);
- return FALSE;
+ return FALSE;
}
+
+ env = validate_envW(pEnvironment);
+ if (!env) return FALSE; /* SetLastError() is in validate_envW */
+
if(RegCreateKeyW(HKEY_LOCAL_MACHINE, PrintersW, &hkeyPrinters) !=
ERROR_SUCCESS) {
ERR("Can't create Printers key\n");
@@ -4479,7 +4488,7 @@ static BOOL WINSPOOL_GetPrinterDriver(HA
ptr = pDriverInfo + size;
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverName,
- pEnvironment, Level, pDriverInfo,
+ env, Level, pDriverInfo,
(cbBuf < size) ? NULL : ptr,
(cbBuf < size) ? 0 : cbBuf - size,
&needed, unicode)) {
@@ -4894,6 +4903,7 @@ static BOOL WINSPOOL_EnumPrinterDrivers(
DWORD i, needed, number = 0, size = 0;
WCHAR DriverNameW[255];
PBYTE ptr;
+ const printenv_t * env;
TRACE("%s,%s,%d,%p,%d,%d\n",
debugstr_w(pName), debugstr_w(pEnvironment),
@@ -4906,6 +4916,9 @@ static BOOL WINSPOOL_EnumPrinterDrivers(
return FALSE;
}
+ env = validate_envW(pEnvironment);
+ if (!env) return FALSE; /* SetLastError() is in validate_envW */
+
/* check input parameter */
if((Level < 1) || (Level > 3)) {
ERR("unsupported level %d\n", Level);
@@ -4961,7 +4974,7 @@ static BOOL WINSPOOL_EnumPrinterDrivers(
return FALSE;
}
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverNameW,
- pEnvironment, Level, ptr,
+ env, Level, ptr,
(cbBuf < *pcbNeeded) ? NULL : pDriverInfo + *pcbNeeded,
(cbBuf < *pcbNeeded) ? 0 : cbBuf - *pcbNeeded,
&needed, unicode)) {
--
1.4.1
More information about the wine-patches
mailing list