winspool: Update the ppd for LPR printers too.

This commit is contained in:
Huw Davies 2012-06-13 15:41:38 +01:00 committed by Alexandre Julliard
parent 0a0fe20988
commit f15f359cbf
2 changed files with 34 additions and 15 deletions

View File

@ -888,23 +888,34 @@ static BOOL CUPS_LoadPrinters(void)
return TRUE; return TRUE;
} }
static char *get_cups_name( HANDLE printer ) #endif
static char *get_queue_name( HANDLE printer, BOOL *cups )
{ {
WCHAR *port; WCHAR *port, *name = NULL;
DWORD err, needed, type; DWORD err, needed, type;
char *ret = NULL; char *ret = NULL;
HKEY key; HKEY key;
*cups = FALSE;
err = WINSPOOL_GetOpenedPrinterRegKey( printer, &key ); err = WINSPOOL_GetOpenedPrinterRegKey( printer, &key );
if (err) return NULL; if (err) return NULL;
err = RegQueryValueExW( key, PortW, 0, &type, NULL, &needed ); err = RegQueryValueExW( key, PortW, 0, &type, NULL, &needed );
if (err || needed <= sizeof( CUPS_Port )) goto end; if (err) goto end;
port = HeapAlloc( GetProcessHeap(), 0, needed ); port = HeapAlloc( GetProcessHeap(), 0, needed );
if (!port) goto end; if (!port) goto end;
RegQueryValueExW( key, PortW, 0, &type, (BYTE*)port, &needed ); RegQueryValueExW( key, PortW, 0, &type, (BYTE*)port, &needed );
if (!memcmp( port, CUPS_Port, sizeof(CUPS_Port) - sizeof(WCHAR) ))
if (!strncmpW( port, CUPS_Port, sizeof(CUPS_Port) / sizeof(WCHAR) -1 ))
{
name = port + sizeof(CUPS_Port) / sizeof(WCHAR) - 1;
*cups = TRUE;
}
else if (!strncmpW( port, LPR_Port, sizeof(LPR_Port) / sizeof(WCHAR) -1 ))
name = port + sizeof(LPR_Port) / sizeof(WCHAR) - 1;
if (name)
{ {
WCHAR *name = port + sizeof(CUPS_Port) / sizeof(WCHAR) - 1;
needed = WideCharToMultiByte( CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL ); needed = WideCharToMultiByte( CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL );
ret = HeapAlloc( GetProcessHeap(), 0, needed ); ret = HeapAlloc( GetProcessHeap(), 0, needed );
if(ret) WideCharToMultiByte( CP_UNIXCP, 0, name, -1, ret, needed, NULL, NULL ); if(ret) WideCharToMultiByte( CP_UNIXCP, 0, name, -1, ret, needed, NULL, NULL );
@ -914,23 +925,30 @@ end:
RegCloseKey( key ); RegCloseKey( key );
return ret; return ret;
} }
#endif
static BOOL update_driver( HANDLE printer ) static BOOL update_driver( HANDLE printer )
{ {
BOOL ret = FALSE; BOOL ret, is_cups;
#ifdef SONAME_LIBCUPS
const WCHAR *name = get_opened_printer_name( printer ); const WCHAR *name = get_opened_printer_name( printer );
WCHAR *ppd_dir, *ppd; WCHAR *ppd_dir, *ppd;
char *cups_name; char *queue_name;
if (!name) return FALSE; if (!name) return FALSE;
cups_name = get_cups_name( printer ); queue_name = get_queue_name( printer, &is_cups );
if (!cups_name) return FALSE; if (!queue_name) return FALSE;
ppd_dir = get_ppd_dir(); ppd_dir = get_ppd_dir();
ppd = get_ppd_filename( ppd_dir, name ); ppd = get_ppd_filename( ppd_dir, name );
if (get_cups_ppd( cups_name, ppd ))
#ifdef SONAME_LIBCUPS
if (is_cups)
ret = get_cups_ppd( queue_name, ppd );
else
#endif
ret = get_fallback_ppd( queue_name, ppd );
if (ret)
{ {
TRACE( "updating driver %s\n", debugstr_w( name ) ); TRACE( "updating driver %s\n", debugstr_w( name ) );
ret = add_printer_driver( name, ppd ); ret = add_printer_driver( name, ppd );
@ -938,8 +956,7 @@ static BOOL update_driver( HANDLE printer )
} }
HeapFree( GetProcessHeap(), 0, ppd_dir ); HeapFree( GetProcessHeap(), 0, ppd_dir );
HeapFree( GetProcessHeap(), 0, ppd ); HeapFree( GetProcessHeap(), 0, ppd );
HeapFree( GetProcessHeap(), 0, cups_name ); HeapFree( GetProcessHeap(), 0, queue_name );
#endif
return ret; return ret;
} }
@ -1024,10 +1041,13 @@ static BOOL PRINTCAP_ParseEntry( const char *pent, BOOL isfirst )
MultiByteToWideChar(CP_ACP, 0, devname, -1, devnameW, sizeof(devnameW) / sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, devname, -1, devnameW, sizeof(devnameW) / sizeof(WCHAR));
if(RegOpenKeyA(hkeyPrinters, devname, &hkeyPrinter) == ERROR_SUCCESS) { if(RegOpenKeyA(hkeyPrinters, devname, &hkeyPrinter) == ERROR_SUCCESS) {
DWORD status = get_dword_from_reg( hkeyPrinter, StatusW );
/* Printer already in registry, delete the tag added in WINSPOOL_LoadSystemPrinters /* Printer already in registry, delete the tag added in WINSPOOL_LoadSystemPrinters
and continue */ and continue */
TRACE("Printer already exists\n"); TRACE("Printer already exists\n");
RegDeleteValueW(hkeyPrinter, May_Delete_Value); RegDeleteValueW(hkeyPrinter, May_Delete_Value);
/* flag that the PPD file should be checked for an update */
set_reg_DWORD( hkeyPrinter, StatusW, status | PRINTER_STATUS_DRIVER_UPDATE_NEEDED );
RegCloseKey(hkeyPrinter); RegCloseKey(hkeyPrinter);
} else { } else {
static CHAR data_type[] = "RAW", static CHAR data_type[] = "RAW",

View File

@ -2596,7 +2596,6 @@ static void test_GetPrinterDriver(void)
hf = CreateFileA(di_2->pDataFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); hf = CreateFileA(di_2->pDataFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hf != INVALID_HANDLE_VALUE) if(hf != INVALID_HANDLE_VALUE)
CloseHandle(hf); CloseHandle(hf);
todo_wine
ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDataFile); ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDataFile);
hf = CreateFileA(di_2->pConfigFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); hf = CreateFileA(di_2->pConfigFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);