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.

232 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. FileQ.c
  6. Abstract:
  7. File queue routines for upgrade
  8. Author:
  9. Muhunthan Sivapragasam (MuhuntS) 22-Jan-1996
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. typedef struct _FILE_QUEUE_CONTEXT {
  14. PVOID QueueContext;
  15. } FILE_QUEUE_CONTEXT, *PFILE_QUEUE_CONTEXT;
  16. UINT
  17. MyQueueCallback(
  18. IN PVOID QueueContext,
  19. IN UINT Notification,
  20. IN UINT_PTR Param1,
  21. IN UINT_PTR Param2
  22. )
  23. /*++
  24. Routine Description:
  25. File queue callback routine for the upgrade. We will not prompt the user
  26. for missing file. But we will retry few times before failing
  27. Arguments:
  28. QueueContext : Points to FILE_QUEUE_CONTEXT
  29. Notification : The event which is being notified
  30. Param1 : Depends on the notification
  31. Param2 : Depends on the notification
  32. Return Value:
  33. None
  34. --*/
  35. {
  36. PFILE_QUEUE_CONTEXT pFileQContext=(PFILE_QUEUE_CONTEXT)QueueContext;
  37. PSOURCE_MEDIA_W pSource;
  38. PFILEPATHS_W pFilePaths;
  39. switch (Notification) {
  40. case SPFILENOTIFY_COPYERROR:
  41. //
  42. // We know atleast pjlmon will be missing since it is copied
  43. // during textmode setup
  44. //
  45. pFilePaths = (PFILEPATHS_W) Param1;
  46. DebugMsg("Error %d copying %ws to %ws.",
  47. pFilePaths->Win32Error, pFilePaths->Source,
  48. pFilePaths->Target);
  49. return FILEOP_SKIP;
  50. case SPFILENOTIFY_NEEDMEDIA:
  51. pSource = (PSOURCE_MEDIA_W)Param1;
  52. //
  53. // Setup is going to add \i386 to the end. Tell it to look
  54. // right in the directory we give. Particularly needed for the
  55. // upgrade over the network case
  56. //
  57. if ( wcscmp(pSource->SourcePath, UpgradeData.pszSourceW) ) {
  58. if(SUCCEEDED(StringCchCopyW((LPWSTR)Param2, MAX_PATH, UpgradeData.pszSourceW)))
  59. {
  60. return FILEOP_NEWPATH;
  61. }
  62. }
  63. DebugMsg("Error copying %ws from %ws.",
  64. pSource->SourceFile, pSource->SourcePath);
  65. return FILEOP_SKIP;
  66. }
  67. return SetupDefaultQueueCallbackW(pFileQContext->QueueContext,
  68. Notification,
  69. Param1,
  70. Param2);
  71. }
  72. BOOL
  73. InitFileCopyOnNT(
  74. IN HDEVINFO hDevInfo
  75. )
  76. /*++
  77. Routine Description:
  78. On NT we will call ntprint.dll via SetupDiCallClassInstaller api with the
  79. DI_NOVCP flag so that all the necessary printer driver files are queued
  80. and copied at the end.
  81. This sets the necessary queue etc before calling the class installer
  82. Arguments:
  83. hDevInfo : Handle to printer device info list.
  84. Return Value:
  85. TRUE on success. FALSE on error
  86. --*/
  87. {
  88. BOOL bRet = FALSE;
  89. HSPFILEQ CopyQueue;
  90. PFILE_QUEUE_CONTEXT pFileQContext;
  91. SP_DEVINSTALL_PARAMS_W DevInstallParams;
  92. //
  93. // Call the current device installation parameters
  94. //
  95. DevInstallParams.cbSize = sizeof(DevInstallParams);
  96. if ( !SetupDiGetDeviceInstallParamsW(hDevInfo,
  97. NULL,
  98. &DevInstallParams) )
  99. return FALSE;
  100. //
  101. // Set the parameters so that ntprint will just queue files and not commit
  102. // the file copy operations
  103. //
  104. if ( !(pFileQContext = AllocMem(sizeof(FILE_QUEUE_CONTEXT))) )
  105. goto Cleanup;
  106. pFileQContext->QueueContext = SetupInitDefaultQueueCallbackEx(
  107. INVALID_HANDLE_VALUE,
  108. INVALID_HANDLE_VALUE,
  109. 0,
  110. 0,
  111. NULL);
  112. DevInstallParams.FileQueue = SetupOpenFileQueue();
  113. DevInstallParams.InstallMsgHandlerContext = pFileQContext;
  114. DevInstallParams.InstallMsgHandler = MyQueueCallback;
  115. DevInstallParams.Flags |= DI_NOVCP;
  116. DevInstallParams.hwndParent = INVALID_HANDLE_VALUE;
  117. //
  118. // The files should be from the source dir
  119. //
  120. StringCchCopyW(DevInstallParams.DriverPath, SIZECHARS(DevInstallParams.DriverPath), UpgradeData.pszSourceW);
  121. if ( DevInstallParams.FileQueue == INVALID_HANDLE_VALUE ||
  122. pFileQContext->QueueContext == NULL ||
  123. !SetupDiSetDeviceInstallParamsW(hDevInfo,
  124. NULL,
  125. &DevInstallParams) ) {
  126. if ( DevInstallParams.FileQueue != INVALID_HANDLE_VALUE )
  127. SetupCloseFileQueue(DevInstallParams.FileQueue);
  128. if ( pFileQContext->QueueContext )
  129. SetupTermDefaultQueueCallback(pFileQContext->QueueContext);
  130. } else {
  131. bRet = TRUE;
  132. }
  133. Cleanup:
  134. if ( !bRet )
  135. FreeMem(pFileQContext);
  136. return bRet;
  137. }
  138. BOOL
  139. CommitFileQueueToCopyFiles(
  140. IN HDEVINFO hDevInfo
  141. )
  142. /*++
  143. Routine Description:
  144. After calling ntprint for each printer driver to queue up the files this
  145. routine is called to commit the file queue and do the actual file copy
  146. operations
  147. Arguments:
  148. hDevInfo : Handle to printer device info list.
  149. Return Value:
  150. TRUE on success. FALSE on error
  151. --*/
  152. {
  153. BOOL bRet = FALSE;
  154. SP_DEVINSTALL_PARAMS_W DevInstallParams;
  155. PFILE_QUEUE_CONTEXT pFileQContext;
  156. DevInstallParams.cbSize = sizeof(DevInstallParams);
  157. if ( !SetupDiGetDeviceInstallParamsW(hDevInfo,
  158. NULL,
  159. &DevInstallParams) )
  160. return FALSE;
  161. pFileQContext = DevInstallParams.InstallMsgHandlerContext;
  162. bRet = SetupCommitFileQueueW(DevInstallParams.hwndParent,
  163. DevInstallParams.FileQueue,
  164. DevInstallParams.InstallMsgHandler,
  165. pFileQContext);
  166. SetupCloseFileQueue(DevInstallParams.FileQueue);
  167. SetupTermDefaultQueueCallback(pFileQContext->QueueContext);
  168. FreeMem(pFileQContext);
  169. return bRet;
  170. }