From 2ff1df77ddbd269a12201a19204dc1e38a260b9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A2=D0=B0=D1=82=D1=8C=D1=8F=D0=BD=D0=B0=20=D0=A4=D0=BE=D0?=
 =?UTF-8?q?=BA=D0=B8=D0=BD=D0=B0?= <tatyana@builder.office.etersoft.ru>
Date: Mon, 1 Oct 2012 15:07:57 +0400
Subject: [PATCH 2/2] winspool.drv: Get spool directory from registry(bug
 1866)

---
 dlls/winspool.drv/info.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index 38266c9..a17c6bf 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -2847,11 +2847,33 @@ BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPD
     opened_printer_t *printer;
     job_t *job;
     BOOL ret = FALSE;
-    static const WCHAR spool_path[] = {'s','p','o','o','l','\\','P','R','I','N','T','E','R','S','\\',0};
     static const WCHAR fmtW[] = {'%','s','%','0','5','d','.','S','P','L',0};
     WCHAR path[MAX_PATH], filename[MAX_PATH];
-    DWORD len;
+    DWORD len=MAX_PATH;
     ADDJOB_INFO_1W *addjob;
+    static const WCHAR key[] = {'S','y','s','t','e','m',0};
+    static const WCHAR skey[] = {'C','u','r','r','e','n','t',
+				 'C','o','n','t','r','o','l','S','e','t','\\',
+				 'C','o','n','t','r','o','l','\\',
+				 'P','r','i','n','t','\\',
+				 'P','r','i','n','t','e','r','s','\\',0};
+    static const WCHAR lpValueName[] = {'D','e','f','a','u','l','t',
+					'S','p','o','o','l','D','i','r','e','c','t','o','r','y',0};
+    DWORD type = REG_SZ;
+    HKEY rKey,rSubKey;
+
+    RegOpenKeyW(HKEY_LOCAL_MACHINE, key, &rKey);
+    RegOpenKeyExW(rKey, skey, 0, KEY_QUERY_VALUE, &rSubKey);
+    if(RegQueryValueExW(rSubKey, (LPCWSTR)lpValueName, 0, &type,
+       (LPBYTE)path, &len)!=ERROR_SUCCESS)
+    {
+	    RegCloseKey(rSubKey);
+	    RegCloseKey(rKey);
+	    ERR("Do not open key in registry.\n");
+	    return ret;
+    }
+    RegCloseKey(rSubKey);
+    RegCloseKey(rKey);
 
     TRACE("(%p,%d,%p,%d,%p)\n", hPrinter, Level, pData, cbBuf, pcbNeeded);
     
@@ -2875,10 +2897,9 @@ BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPD
 
     job->job_id = InterlockedIncrement(&next_job_id);
 
-    len = GetSystemDirectoryW(path, sizeof(path) / sizeof(WCHAR));
+    len = lstrlenW(path);
     if(path[len - 1] != '\\')
         path[len++] = '\\';
-    memcpy(path + len, spool_path, sizeof(spool_path));    
     sprintfW(filename, fmtW, path, job->job_id);
 
     len = strlenW(filename);
-- 
1.7.10.5
