Add support for environment variables in the printer settings.
Remove the fixed-size buffers.
This commit is contained in:
parent
a45907c4c0
commit
f101e2760b
|
@ -432,7 +432,8 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
|
||||||
const AFM *afm;
|
const AFM *afm;
|
||||||
HANDLE hPrinter;
|
HANDLE hPrinter;
|
||||||
const char *ppd = NULL;
|
const char *ppd = NULL;
|
||||||
char ppdFileName[256];
|
DWORD ppdType;
|
||||||
|
char* ppdFileName = NULL;
|
||||||
HKEY hkey;
|
HKEY hkey;
|
||||||
|
|
||||||
TRACE("'%s'\n", name);
|
TRACE("'%s'\n", name);
|
||||||
|
@ -479,14 +480,15 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ppdFileName[0]='\0';
|
|
||||||
|
|
||||||
#ifdef HAVE_CUPS
|
#ifdef HAVE_CUPS
|
||||||
{
|
{
|
||||||
ppd = cupsGetPPD(name);
|
ppd = cupsGetPPD(name);
|
||||||
|
|
||||||
if (ppd) {
|
if (ppd) {
|
||||||
strncpy(ppdFileName, ppd, sizeof(ppdFileName));
|
needed=strlen(ppd)+1;
|
||||||
|
ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
|
||||||
|
memcpy(ppdFileName, ppd, needed);
|
||||||
|
ppdType=REG_SZ;
|
||||||
res = ERROR_SUCCESS;
|
res = ERROR_SUCCESS;
|
||||||
/* we should unlink() that file later */
|
/* we should unlink() that file later */
|
||||||
} else {
|
} else {
|
||||||
|
@ -496,34 +498,52 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ppdFileName[0]) {
|
if (!ppdFileName) {
|
||||||
res = GetPrinterDataA (hPrinter, "PPD File", NULL, ppdFileName,
|
res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed);
|
||||||
sizeof(ppdFileName), &needed);
|
if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) {
|
||||||
|
ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
|
||||||
|
res = GetPrinterDataA(hPrinter, "PPD File", &ppdType, ppdFileName, needed, &needed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Look for a ppd file for this printer in the config file.
|
/* Look for a ppd file for this printer in the config file.
|
||||||
* First look for the names of the printer, then for 'generic'
|
* First look under that printer's name, and then under 'generic'
|
||||||
*/
|
*/
|
||||||
if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
|
if((res != ERROR_SUCCESS) && !RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\ppd", &hkey))
|
||||||
{
|
{
|
||||||
DWORD count = sizeof(ppdFileName);
|
const char* value_name;
|
||||||
ppdFileName[0] = 0;
|
|
||||||
if(RegQueryValueExA(hkey, name, 0, &type, ppdFileName, &count) != ERROR_SUCCESS)
|
if (RegQueryValueExA(hkey, name, 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
|
||||||
RegQueryValueExA(hkey, "generic", 0, &type, ppdFileName, &count);
|
value_name=name;
|
||||||
RegCloseKey(hkey);
|
} else if (RegQueryValueExA(hkey, "generic", 0, NULL, NULL, &needed) == ERROR_SUCCESS) {
|
||||||
|
value_name="generic";
|
||||||
|
} else {
|
||||||
|
value_name=NULL;
|
||||||
|
}
|
||||||
|
if (value_name) {
|
||||||
|
ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed);
|
||||||
|
RegQueryValueExA(hkey, value_name, 0, &ppdType, ppdFileName, &needed);
|
||||||
|
}
|
||||||
|
RegCloseKey(hkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ppdFileName[0])
|
if (!ppdFileName) {
|
||||||
res = ERROR_FILE_NOT_FOUND;
|
res = ERROR_FILE_NOT_FOUND;
|
||||||
else
|
ERR ("Error %li getting PPD file name for printer '%s'\n", res, name);
|
||||||
res = ERROR_SUCCESS;
|
goto closeprinter;
|
||||||
|
} else {
|
||||||
|
res = ERROR_SUCCESS;
|
||||||
|
if (ppdType==REG_EXPAND_SZ) {
|
||||||
|
char* tmp;
|
||||||
|
|
||||||
if (res != ERROR_SUCCESS) {
|
/* Expand environment variable references */
|
||||||
ERR ("Error %li getting PPD file name for printer '%s'\n", res, name);
|
needed=ExpandEnvironmentStringsA(ppdFileName,NULL,0);
|
||||||
goto closeprinter;
|
tmp=HeapAlloc(PSDRV_Heap, 0, needed);
|
||||||
|
ExpandEnvironmentStringsA(ppdFileName,tmp,needed);
|
||||||
|
HeapFree(PSDRV_Heap, 0, ppdFileName);
|
||||||
|
ppdFileName=tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ppdFileName[sizeof(ppdFileName) - 1] = '\0';
|
|
||||||
|
|
||||||
pi->ppd = PSDRV_ParsePPD(ppdFileName);
|
pi->ppd = PSDRV_ParsePPD(ppdFileName);
|
||||||
if(!pi->ppd) {
|
if(!pi->ppd) {
|
||||||
MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
|
MESSAGE("Couldn't find PPD file '%s', expect a crash now!\n",
|
||||||
|
@ -601,6 +621,8 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name)
|
||||||
closeprinter:
|
closeprinter:
|
||||||
ClosePrinter(hPrinter);
|
ClosePrinter(hPrinter);
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (ppdFileName)
|
||||||
|
HeapFree(PSDRV_Heap, 0, ppdFileName);
|
||||||
if (pi->FontSubTable)
|
if (pi->FontSubTable)
|
||||||
HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
|
HeapFree(PSDRV_Heap, 0, pi->FontSubTable);
|
||||||
if (pi->FriendlyName)
|
if (pi->FriendlyName)
|
||||||
|
|
Loading…
Reference in New Issue