Commit 9d8bf3bf authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

winspool: Call the ppd retrieval function from add_printer_driver().

parent e432c1cd
...@@ -750,43 +750,6 @@ static DWORD WINSPOOL_GetOpenedPrinterRegKey(HANDLE hPrinter, HKEY *phkey) ...@@ -750,43 +750,6 @@ static DWORD WINSPOOL_GetOpenedPrinterRegKey(HANDLE hPrinter, HKEY *phkey)
return open_printer_reg_key( name, phkey ); return open_printer_reg_key( name, phkey );
} }
static BOOL add_printer_driver(const WCHAR *name, WCHAR *ppd)
{
DRIVER_INFO_3W di3;
unsigned int i;
BOOL res;
ZeroMemory(&di3, sizeof(DRIVER_INFO_3W));
di3.cVersion = 3;
di3.pName = (WCHAR*)name;
di3.pDriverPath = driver_nt;
di3.pDataFile = ppd;
di3.pConfigFile = driver_nt;
di3.pDefaultDataType = rawW;
for (i = 0; i < ARRAY_SIZE(all_printenv); i++)
{
di3.pEnvironment = (WCHAR *) all_printenv[i]->envname;
if (all_printenv[i]->envname == envname_win40W)
{
/* We use wineps16.drv as driver for 16 bit */
di3.pDriverPath = driver_9x;
di3.pConfigFile = driver_9x;
}
res = AddPrinterDriverExW( NULL, 3, (LPBYTE)&di3, APD_COPY_NEW_FILES | APD_COPY_FROM_DIRECTORY );
TRACE("got %d and %d for %s (%s)\n", res, GetLastError(), debugstr_w(name), debugstr_w(di3.pEnvironment));
if (!res && (GetLastError() != ERROR_PRINTER_DRIVER_ALREADY_INSTALLED))
{
ERR("failed with %u for %s (%s) %s\n", GetLastError(), debugstr_w(name),
debugstr_w(di3.pEnvironment), debugstr_w(di3.pDriverPath));
return FALSE;
}
}
return TRUE;
}
static BOOL copy_file( const char *src, const char *dst ) static BOOL copy_file( const char *src, const char *dst )
{ {
int fds[2] = {-1, -1}, num; int fds[2] = {-1, -1}, num;
...@@ -852,6 +815,69 @@ static WCHAR *get_ppd_filename( const WCHAR *dir, const WCHAR *file_name ) ...@@ -852,6 +815,69 @@ static WCHAR *get_ppd_filename( const WCHAR *dir, const WCHAR *file_name )
return ppd; return ppd;
} }
static char *get_dest_name( const WCHAR *printer )
{
int len = WideCharToMultiByte( CP_UNIXCP, 0, printer, -1, NULL, 0, NULL, NULL );
char *dest = heap_alloc( len );
if (dest) WideCharToMultiByte( CP_UNIXCP, 0, printer, -1, dest, len, NULL, NULL );
return dest;
}
static BOOL get_cups_ppd( const char *printer_name, const WCHAR *ppd );
static void unlink_ppd( const WCHAR *ppd );
static BOOL add_printer_driver( const WCHAR *name, const WCHAR *ppd_dir )
{
WCHAR *ppd = get_ppd_filename( ppd_dir, name );
char *dest_name;
DRIVER_INFO_3W di3;
unsigned int i;
BOOL res = FALSE;
if (!ppd) return FALSE;
dest_name = get_dest_name( name );
if (!dest_name) goto end;
res = get_cups_ppd( dest_name, ppd ) || get_internal_fallback_ppd( ppd );
if (!res) goto end;
memset( &di3, 0, sizeof(DRIVER_INFO_3W) );
di3.cVersion = 3;
di3.pName = (WCHAR *)name;
di3.pDriverPath = driver_nt;
di3.pDataFile = ppd;
di3.pConfigFile = driver_nt;
di3.pDefaultDataType = rawW;
for (i = 0; i < ARRAY_SIZE(all_printenv); i++)
{
di3.pEnvironment = (WCHAR *)all_printenv[i]->envname;
if (all_printenv[i]->envname == envname_win40W)
{
/* We use wineps16.drv as driver for 16 bit */
di3.pDriverPath = driver_9x;
di3.pConfigFile = driver_9x;
}
res = AddPrinterDriverExW( NULL, 3, (BYTE *)&di3, APD_COPY_NEW_FILES | APD_COPY_FROM_DIRECTORY );
TRACE( "got %d and %d for %s (%s)\n", res, GetLastError(), debugstr_w( name ), debugstr_w( di3.pEnvironment ) );
if (!res && (GetLastError() != ERROR_PRINTER_DRIVER_ALREADY_INSTALLED))
{
ERR( "failed with %u for %s (%s) %s\n", GetLastError(), debugstr_w( name ),
debugstr_w( di3.pEnvironment ), debugstr_w( di3.pDriverPath ) );
break;
}
res = TRUE;
}
unlink_ppd( ppd );
end:
heap_free( dest_name );
heap_free( ppd );
return res;
}
static WCHAR *get_ppd_dir( void ) static WCHAR *get_ppd_dir( void )
{ {
static const WCHAR wine_ppds[] = {'w','i','n','e','_','p','p','d','s','\\',0}; static const WCHAR wine_ppds[] = {'w','i','n','e','_','p','p','d','s','\\',0};
...@@ -953,11 +979,7 @@ static BOOL get_cups_ppd( const char *printer_name, const WCHAR *ppd ) ...@@ -953,11 +979,7 @@ static BOOL get_cups_ppd( const char *printer_name, const WCHAR *ppd )
if (http_status != HTTP_OK) unlink( unix_name ); if (http_status != HTTP_OK) unlink( unix_name );
HeapFree( GetProcessHeap(), 0, unix_name ); HeapFree( GetProcessHeap(), 0, unix_name );
if (http_status == HTTP_OK) return TRUE; return http_status == HTTP_OK;
TRACE( "failed to get ppd for printer %s from cups (status %d), calling fallback\n",
debugstr_a(printer_name), http_status );
return get_internal_fallback_ppd( ppd );
} }
static WCHAR *get_cups_option( const char *name, int num_options, cups_option_t *options ) static WCHAR *get_cups_option( const char *name, int num_options, cups_option_t *options )
...@@ -996,7 +1018,7 @@ static BOOL CUPS_LoadPrinters(void) ...@@ -996,7 +1018,7 @@ static BOOL CUPS_LoadPrinters(void)
BOOL hadprinter = FALSE, haddefault = FALSE; BOOL hadprinter = FALSE, haddefault = FALSE;
cups_dest_t *dests; cups_dest_t *dests;
PRINTER_INFO_2W pi2; PRINTER_INFO_2W pi2;
WCHAR *port, *ppd_dir = NULL, *ppd; WCHAR *port, *ppd_dir = NULL;
HKEY hkeyPrinter, hkeyPrinters; HKEY hkeyPrinter, hkeyPrinters;
WCHAR nameW[MAX_PATH]; WCHAR nameW[MAX_PATH];
HANDLE added_printer; HANDLE added_printer;
...@@ -1024,7 +1046,8 @@ static BOOL CUPS_LoadPrinters(void) ...@@ -1024,7 +1046,8 @@ static BOOL CUPS_LoadPrinters(void)
continue; continue;
} }
if(RegOpenKeyW(hkeyPrinters, nameW, &hkeyPrinter) == ERROR_SUCCESS) { if (RegOpenKeyW( hkeyPrinters, nameW, &hkeyPrinter ) == ERROR_SUCCESS)
{
DWORD status = get_dword_from_reg( hkeyPrinter, StatusW ); 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 */
...@@ -1033,19 +1056,11 @@ static BOOL CUPS_LoadPrinters(void) ...@@ -1033,19 +1056,11 @@ static BOOL CUPS_LoadPrinters(void)
/* flag that the PPD file should be checked for an update */ /* flag that the PPD file should be checked for an update */
set_reg_DWORD( hkeyPrinter, StatusW, status | PRINTER_STATUS_DRIVER_UPDATE_NEEDED ); set_reg_DWORD( hkeyPrinter, StatusW, status | PRINTER_STATUS_DRIVER_UPDATE_NEEDED );
RegCloseKey(hkeyPrinter); RegCloseKey(hkeyPrinter);
} else {
BOOL added_driver = FALSE;
if (!ppd_dir && !(ppd_dir = get_ppd_dir())) break;
ppd = get_ppd_filename( ppd_dir, nameW );
if (get_cups_ppd( dests[i].name, ppd ))
{
added_driver = add_printer_driver( nameW, ppd );
unlink_ppd( ppd );
} }
HeapFree( GetProcessHeap(), 0, ppd ); else
if (!added_driver) continue; {
if (!ppd_dir && !(ppd_dir = get_ppd_dir())) break;
if (!add_printer_driver( nameW, ppd_dir )) continue;
port = heap_alloc( sizeof(CUPS_Port) + lstrlenW( nameW ) * sizeof(WCHAR) ); port = heap_alloc( sizeof(CUPS_Port) + lstrlenW( nameW ) * sizeof(WCHAR) );
lstrcpyW( port, CUPS_Port ); lstrcpyW( port, CUPS_Port );
...@@ -1097,43 +1112,6 @@ static BOOL CUPS_LoadPrinters(void) ...@@ -1097,43 +1112,6 @@ static BOOL CUPS_LoadPrinters(void)
#endif #endif
static char *get_queue_name( HANDLE printer, BOOL *cups )
{
WCHAR *port, *name = NULL;
DWORD err, needed, type;
char *ret = NULL;
HKEY key;
*cups = FALSE;
err = WINSPOOL_GetOpenedPrinterRegKey( printer, &key );
if (err) return NULL;
err = RegQueryValueExW( key, PortW, 0, &type, NULL, &needed );
if (err) goto end;
port = HeapAlloc( GetProcessHeap(), 0, needed );
if (!port) goto end;
RegQueryValueExW( key, PortW, 0, &type, (BYTE*)port, &needed );
if (!strncmpW( port, CUPS_Port, ARRAY_SIZE( CUPS_Port ) -1 ))
{
name = port + ARRAY_SIZE( CUPS_Port ) - 1;
*cups = TRUE;
}
else if (!strncmpW( port, LPR_Port, ARRAY_SIZE( LPR_Port ) -1 ))
name = port + ARRAY_SIZE( LPR_Port ) - 1;
if (name)
{
needed = WideCharToMultiByte( CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL );
ret = HeapAlloc( GetProcessHeap(), 0, needed );
if(ret) WideCharToMultiByte( CP_UNIXCP, 0, name, -1, ret, needed, NULL, NULL );
}
HeapFree( GetProcessHeap(), 0, port );
end:
RegCloseKey( key );
return ret;
}
static void set_ppd_overrides( HANDLE printer ) static void set_ppd_overrides( HANDLE printer )
{ {
WCHAR *wstr = NULL; WCHAR *wstr = NULL;
...@@ -1180,38 +1158,17 @@ end: ...@@ -1180,38 +1158,17 @@ end:
static BOOL update_driver( HANDLE printer ) static BOOL update_driver( HANDLE printer )
{ {
BOOL ret, is_cups; BOOL ret;
const WCHAR *name = get_opened_printer_name( printer ); const WCHAR *name = get_opened_printer_name( printer );
WCHAR *ppd_dir, *ppd; WCHAR *ppd_dir;
char *queue_name;
if (!name) return FALSE; if (!name) return FALSE;
queue_name = get_queue_name( printer, &is_cups ); if (!(ppd_dir = get_ppd_dir())) return FALSE;
if (!queue_name) return FALSE;
if (!(ppd_dir = get_ppd_dir()))
{
HeapFree( GetProcessHeap(), 0, queue_name );
return FALSE;
}
ppd = get_ppd_filename( ppd_dir, name );
#ifdef SONAME_LIBCUPS
if (is_cups)
ret = get_cups_ppd( queue_name, ppd );
else
#endif
ret = get_internal_fallback_ppd( 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_dir );
unlink_ppd( ppd );
} heap_free( ppd_dir );
HeapFree( GetProcessHeap(), 0, ppd_dir );
HeapFree( GetProcessHeap(), 0, ppd );
HeapFree( GetProcessHeap(), 0, queue_name );
set_ppd_overrides( printer ); set_ppd_overrides( printer );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment