CUPS_LoadPrinters: Skip already known printers

Stefan Becker (NMP/Salo) Stefan.Becker at nokia.com
Fri Feb 7 11:59:53 CST 2003


Hi all!

Every time a program which uses the Windows Spooler (e.g. notepad) is 
started, CUPS_LoadPrinters requests a list of printers and for each one 
of the tries to fetch the PPD file. If the PPD file fetch was succesfull 
the printer is added to the Registry, which fails if the printer is 
already known. My box uses a CUPS server with 123 printer queues. 
Therefore every time CUPS_LoadPrinters is executed lots of data is 
transferred through the network. So starting "notepad" takes about 1-2 
minute!

The attached patch against Wine snapshot 20030115 changes the code so 
that it checks if the printer is already in the registry. Only if it 
doesn't exist yet it will continue by requesting the PPD. Now only the 
first Wine startup takes 1-2 minutes.

Changelog:
  If a CUPS printer is already in the registry don't try to add it again

Regards,

	Stefan

---
Stefan Becker
E-Mail: Stefan.Becker at nokia.com
-------------- next part --------------
--- dlls/winspool/info.c~	Wed Jan 15 02:51:16 2003
+++ dlls/winspool/info.c	Fri Feb  7 19:21:01 2003
@@ -157,9 +157,30 @@
 
     nrofdests = pcupsGetPrinters(&printers);
     for (i=0;i<nrofdests;i++) {
-	const char *ppd = pcupsGetPPD(printers[i]);
+	const char *ppd;
 	char	*port,*devline;
+        WCHAR   *pNameW;
+        HKEY     hkeyPrinters, hkeyPrinter;
 
+        /* First check that the printer doesn't exist already */
+        pNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, printers[i]);
+        if (RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) ==
+            ERROR_SUCCESS) {
+             if (RegOpenKeyW(hkeyPrinters, pNameW, &hkeyPrinter) ==
+                 ERROR_SUCCESS) {
+                  /* We know this printer already */
+                  RegCloseKey(hkeyPrinter);
+                  RegCloseKey(hkeyPrinters);
+                  HeapFree(GetProcessHeap(),0,pNameW);
+                  TRACE("Printer %s already known. Skipping detection\n", printers[i]);
+                  continue;
+             }
+             RegCloseKey(hkeyPrinters);
+        }
+        HeapFree(GetProcessHeap(),0,pNameW);
+
+        /* OK, we haven't seen this one yet. Request PPD for it */
+	ppd = pcupsGetPPD(printers[i]);
 	if (!ppd) {
 	    WARN("No ppd file for %s.\n",printers[i]);
 	    /* If this was going to be the default printer,


More information about the wine-patches mailing list