Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. upgrade.c
  5. Abstract:
  6. This file handles the DrvUpgradePrinter spooler API
  7. Environment:
  8. Win32 subsystem, DriverUI module, user mode
  9. Revision History:
  10. 02/13/97 -davidx-
  11. Implement OEM plugin support.
  12. 02/06/97 -davidx-
  13. Rewrote it to use common data management functions.
  14. 07/17/96 -amandan-
  15. Created it.
  16. --*/
  17. #include "precomp.h"
  18. //
  19. // Forward and external function declarations
  20. //
  21. BOOL BInitOrUpgradePrinterProperties(PCOMMONINFO);
  22. BOOL BUpgradeFormTrayTable(PCOMMONINFO);
  23. VOID VUpgradeDefaultDevmode(PCOMMONINFO);
  24. #if defined(UNIDRV) && !defined(WINNT_40)
  25. BOOL
  26. BUpgradeSoftFonts(
  27. PCOMMONINFO pci,
  28. PDRIVER_UPGRADE_INFO_2 pUpgradeInfo);
  29. #endif //defined(UNIDRV) && !defined(WINNT_40)
  30. BOOL
  31. DrvUpgradePrinter(
  32. DWORD dwLevel,
  33. LPBYTE pDriverUpgradeInfo
  34. )
  35. /*++
  36. Routine Description:
  37. This function is called by the spooler everytime a new driver
  38. is copied to the system. This function checks for appropriate
  39. registry keys in the registry. If the new registry keys are not
  40. present, it will set the new keys with default values. This function
  41. will handle the upgrading of information in the registry to the new driver format.
  42. Arguments:
  43. dwLevel - version info for DRIVER_UPGRADE_INFO
  44. pDriverUpgradeInfo - pointer to DRIVER_UPGRADE_INFO_1
  45. Return Value:
  46. TRUE for success and FALSE for failure
  47. --*/
  48. {
  49. PDRIVER_UPGRADE_INFO_1 pUpgradeInfo1 = (PDRIVER_UPGRADE_INFO_1) pDriverUpgradeInfo;
  50. PCOMMONINFO pci;
  51. BOOL bResult = TRUE;
  52. DWORD dwSize, dwType = REG_SZ;
  53. PFN_OEMUpgradePrinter pfnOEMUpgradePrinter;
  54. PFN_OEMUpgradeRegistry pfnOEMUpgradeRegistry;
  55. //
  56. // Verify the validity of input parameters
  57. //
  58. if (pDriverUpgradeInfo == NULL)
  59. {
  60. ERR(("Invalid DrvUpgradePrinter parameters.\n"));
  61. SetLastError(ERROR_INVALID_PARAMETER);
  62. return FALSE;
  63. }
  64. #if defined(WINNT_40)
  65. if (dwLevel != 1 )
  66. {
  67. ERR(("DrvUpgradePrinter...dwLevel != 1\n"));
  68. SetLastError(ERROR_INVALID_PARAMETER);
  69. return FALSE;
  70. }
  71. #else // NT 5.0
  72. if (dwLevel != 1 && dwLevel != 2)
  73. {
  74. WARNING(("Level is neither 1 nor 2.\n"));
  75. SetLastError(ERROR_INVALID_PARAMETER);
  76. return FALSE;
  77. }
  78. #endif // defined(WINNT_40)
  79. //
  80. // Open the printer with administrator access
  81. // and load basic printer information
  82. //
  83. pci = PLoadCommonInfo(NULL,
  84. pUpgradeInfo1->pPrinterName,
  85. FLAG_OPENPRINTER_ADMIN |
  86. FLAG_INIT_PRINTER |
  87. FLAG_REFRESH_PARSED_DATA |
  88. FLAG_UPGRADE_PRINTER);
  89. if (pci == NULL)
  90. {
  91. ERR(("DrvUpgradePrinter..pci==NULL.\n"));
  92. return FALSE;
  93. }
  94. //
  95. // Update printer properties information
  96. //
  97. (VOID) BInitOrUpgradePrinterProperties(pci);
  98. (VOID) BUpgradeFormTrayTable(pci);
  99. VUpgradeDefaultDevmode(pci);
  100. #ifndef WINNT_40
  101. VNotifyDSOfUpdate(pci->hPrinter);
  102. #endif // !WINNT_40
  103. #if defined(UNIDRV) && !defined(WINNT_40)
  104. //
  105. // NT 5.0 UniDriver specific upgrade steps
  106. //
  107. //
  108. // Make sure that the DRIVER_UPGRADE_INFO's level is 2.
  109. //
  110. if (dwLevel == 2)
  111. {
  112. BUpgradeSoftFonts(pci, (PDRIVER_UPGRADE_INFO_2)pUpgradeInfo1);
  113. }
  114. #endif //defined(UNIDRV) && !defined(WINNT_40)
  115. //
  116. // call OEMUpgradePrinter entrypoint for each plugin
  117. //
  118. FOREACH_OEMPLUGIN_LOOP(pci)
  119. if (HAS_COM_INTERFACE(pOemEntry))
  120. {
  121. //
  122. // If the OEM does not implement upgradeprinter, then they
  123. // cannot support upgraderegistry since you can only upgrade
  124. // registry if you support upgradeprinter.
  125. //
  126. HRESULT hr;
  127. hr = HComOEMUpgradePrinter(pOemEntry,
  128. dwLevel,
  129. pDriverUpgradeInfo) ;
  130. if (hr == E_NOTIMPL)
  131. continue;
  132. bResult = SUCCEEDED(hr);
  133. }
  134. else
  135. {
  136. if ((pfnOEMUpgradePrinter = GET_OEM_ENTRYPOINT(pOemEntry, OEMUpgradePrinter)) &&
  137. !pfnOEMUpgradePrinter(dwLevel, pDriverUpgradeInfo))
  138. {
  139. ERR(("OEMUpgradePrinter failed for '%ws': %d\n",
  140. CURRENT_OEM_MODULE_NAME(pOemEntry),
  141. GetLastError()));
  142. bResult = FALSE;
  143. }
  144. if ((pfnOEMUpgradeRegistry = GET_OEM_ENTRYPOINT(pOemEntry, OEMUpgradeRegistry)) &&
  145. !pfnOEMUpgradeRegistry(dwLevel, pDriverUpgradeInfo, BUpgradeRegistrySettingForOEM))
  146. {
  147. ERR(("OEMUpgradeRegistry failed for '%ws': %d\n",
  148. CURRENT_OEM_MODULE_NAME(pOemEntry),
  149. GetLastError()));
  150. bResult = FALSE;
  151. }
  152. }
  153. END_OEMPLUGIN_LOOP
  154. VFreeCommonInfo(pci);
  155. return bResult;
  156. }
  157. BOOL
  158. BUpgradeFormTrayTable(
  159. PCOMMONINFO pci
  160. )
  161. /*++
  162. Routine Description:
  163. Upgrade the form-to-tray assignment table in the registry
  164. Arguments:
  165. pci - Points to basic printer information
  166. Return Value:
  167. TRUE if upgrade is successful, FALSE otherwise
  168. --*/
  169. {
  170. PWSTR pFormTrayTable;
  171. DWORD dwSize;
  172. BOOL bResult;
  173. //
  174. // Get a copy of the current form-to-tray assignment table.
  175. // If new format data is not present but old format data is,
  176. // this will call the appropriate library function to convert
  177. // old format data to new format.
  178. //
  179. pFormTrayTable = PGetFormTrayTable(pci->hPrinter, &dwSize);
  180. if (pFormTrayTable == NULL)
  181. return TRUE;
  182. //
  183. // Save the form-to-tray assignment table back to registry
  184. //
  185. bResult = BSaveFormTrayTable(pci->hPrinter, pFormTrayTable, dwSize);
  186. MemFree(pFormTrayTable);
  187. return bResult;
  188. }
  189. VOID
  190. VUpgradeDefaultDevmode(
  191. PCOMMONINFO pci
  192. )
  193. /*++
  194. Routine Description:
  195. Upgrade the default printer devmode, if necessary
  196. Arguments:
  197. pci - Points to basic printer information
  198. Return Value:
  199. NONE
  200. --*/
  201. {
  202. PPRINTER_INFO_2 pPrinterInfo2;
  203. PDEVMODE pdm;
  204. if ((pPrinterInfo2 = MyGetPrinter(pci->hPrinter, 2)) &&
  205. (pdm = pPrinterInfo2->pDevMode) &&
  206. BFillCommonInfoDevmode(pci, pdm, NULL) &&
  207. (pci->pdm->dmSpecVersion != pdm->dmSpecVersion ||
  208. pci->pdm->dmDriverVersion != pdm->dmDriverVersion ||
  209. pci->pdm->dmSize != pdm->dmSize ||
  210. pci->pdm->dmDriverExtra != pdm->dmDriverExtra))
  211. {
  212. pPrinterInfo2->pDevMode = pci->pdm;
  213. SetPrinter(pci->hPrinter, 2, (PBYTE) pPrinterInfo2, 0);
  214. }
  215. MemFree(pPrinterInfo2);
  216. }