Source code of Windows XP (NT5)
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.

381 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. fileq.c
  5. Abstract:
  6. This file implements the file copy code.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include "faxocm.h"
  13. #pragma hdrstop
  14. FILE_QUEUE_INFO MinimalServerFileQueue[] =
  15. {
  16. { L"CoverPageFiles", DIRID_COVERPAGE, L"%s\\%s" , FILEQ_FLAG_SHELL, CSIDL_COMMON_DOCUMENTS }
  17. };
  18. #define CountMinimalServerFileQueue (sizeof(MinimalServerFileQueue)/sizeof(FILE_QUEUE_INFO))
  19. FILE_QUEUE_INFO ServerFileQueue[] =
  20. {
  21. { L"ClientFiles", DIRID_CLIENTS, L"%s\\" FAX_CLIENT_DIR, FILEQ_FLAG_SHELL, CSIDL_COMMON_APPDATA },
  22. { L"CoverPageFiles", DIRID_COVERPAGE, L"%s\\%s" , FILEQ_FLAG_SHELL, CSIDL_COMMON_DOCUMENTS }
  23. };
  24. #define CountServerFileQueue (sizeof(ServerFileQueue)/sizeof(FILE_QUEUE_INFO))
  25. FILE_QUEUE_INFO ClientFileQueue[] =
  26. {
  27. { L"ClientSystemFiles", DIRID_SYSTEM, NULL, 0, 0 },
  28. { L"HelpFilesClient", DIRID_HELP, NULL, 0, 0 },
  29. { L"OutlookConfigFile", DIRID_OUTLOOK_ECF, L"%windir%\\addins", FILEQ_FLAG_ENV, 0 },
  30. { L"CoverPageFiles", DIRID_COVERPAGE, L"%s\\Fax\\Personal Coverpages", FILEQ_FLAG_SHELL, CSIDL_PERSONAL}
  31. };
  32. #define CountClientFileQueue (sizeof(ClientFileQueue)/sizeof(FILE_QUEUE_INFO))
  33. DWORD
  34. SetupQueueXXXSection(
  35. HSPFILEQ QueueHandle,
  36. LPWSTR SourceRootPath,
  37. HINF InfHandle,
  38. HINF ListInfHandle,
  39. LPWSTR Section,
  40. DWORD CopyStyle,
  41. DWORD Action
  42. )
  43. {
  44. if (Action == SETUP_ACTION_NONE) {
  45. return 0;
  46. }
  47. if (Action == SETUP_ACTION_COPY) {
  48. return SetupQueueCopySection(
  49. QueueHandle,
  50. SourceRootPath,
  51. InfHandle,
  52. ListInfHandle,
  53. Section,
  54. CopyStyle
  55. );
  56. }
  57. if (Action == SETUP_ACTION_DELETE) {
  58. return SetupQueueDeleteSection(
  59. QueueHandle,
  60. InfHandle,
  61. ListInfHandle,
  62. Section
  63. );
  64. }
  65. return 0;
  66. }
  67. BOOL
  68. SetDestinationDir(
  69. HINF SetupInf,
  70. PFILE_QUEUE_INFO FileQueueInfo
  71. )
  72. {
  73. WCHAR DestDir[MAX_PATH*2];
  74. BOOL Rval;
  75. if (FileQueueInfo->InfDirId < DIRID_USER) {
  76. return TRUE;
  77. }
  78. if (FileQueueInfo->Flags & FILEQ_FLAG_SHELL) {
  79. WCHAR ShellPath[MAX_PATH];
  80. if (!MyGetSpecialPath(FileQueueInfo->ShellId, ShellPath) ) {
  81. DebugPrint(( L"MyGetSpecialPath(%d) failed, ec = %d\n", FileQueueInfo->ShellId, GetLastError() ));
  82. return FALSE;
  83. }
  84. if (FileQueueInfo->InfDirId == DIRID_COVERPAGE) {
  85. wsprintf( DestDir, FileQueueInfo->DirName, ShellPath, GetString( IDS_COVERPAGE_DIR ) );
  86. } else {
  87. wsprintf( DestDir, FileQueueInfo->DirName, ShellPath );
  88. }
  89. }
  90. if (FileQueueInfo->Flags & FILEQ_FLAG_ENV) {
  91. ExpandEnvironmentStrings( FileQueueInfo->DirName, DestDir, sizeof(DestDir)/sizeof(WCHAR) );
  92. }
  93. DebugPrint(( L"Setting destination dir: [%d] [%s]", FileQueueInfo->InfDirId, DestDir ));
  94. MakeDirectory( DestDir );
  95. Rval = SetupSetDirectoryId(
  96. SetupInf,
  97. FileQueueInfo->InfDirId,
  98. DestDir
  99. );
  100. if (!Rval) {
  101. DebugPrint(( L"SetupSetDirectoryId() failed, ec=%d", GetLastError() ));
  102. return FALSE;
  103. }
  104. return TRUE;
  105. }
  106. BOOL
  107. ProcessFileQueueEntry(
  108. HINF SetupInf,
  109. HSPFILEQ FileQueue,
  110. LPWSTR SourceRoot,
  111. PFILE_QUEUE_INFO FileQueueInfo,
  112. DWORD ActionId
  113. )
  114. {
  115. BOOL Rval;
  116. //
  117. // set the destination directory
  118. //
  119. if (!SetDestinationDir( SetupInf, FileQueueInfo ) ) {
  120. return FALSE;
  121. }
  122. //
  123. // queue the operation
  124. //
  125. Rval = SetupQueueXXXSection(
  126. FileQueue,
  127. SourceRoot,
  128. SetupInf,
  129. SetupInf,
  130. FileQueueInfo->SectionName,
  131. SP_COPY_FORCE_NEWER,
  132. ActionId
  133. );
  134. return Rval;
  135. }
  136. BOOL
  137. ProcessFileQueueEntryForDiskSpace(
  138. HINF SetupInf,
  139. HDSKSPC DiskSpace,
  140. LPWSTR SourceRoot,
  141. PFILE_QUEUE_INFO FileQueueInfo,
  142. DWORD Operation,
  143. BOOL AddToQueue
  144. )
  145. {
  146. BOOL Rval;
  147. //
  148. // set the destination directory
  149. //
  150. if (!SetDestinationDir( SetupInf, FileQueueInfo )) {
  151. return FALSE;
  152. }
  153. //
  154. // add the files to the disk space queue
  155. //
  156. if (AddToQueue) {
  157. Rval = SetupAddSectionToDiskSpaceList(
  158. DiskSpace,
  159. SetupInf,
  160. NULL,
  161. FileQueueInfo->SectionName,
  162. Operation,
  163. NULL,
  164. 0
  165. );
  166. } else {
  167. Rval = SetupRemoveSectionFromDiskSpaceList(
  168. DiskSpace,
  169. SetupInf,
  170. NULL,
  171. FileQueueInfo->SectionName,
  172. Operation,
  173. NULL,
  174. 0
  175. );
  176. }
  177. return Rval;
  178. }
  179. BOOL
  180. AddServerFilesToQueue(
  181. HINF SetupInf,
  182. HSPFILEQ FileQueue,
  183. LPWSTR SourceRoot
  184. )
  185. {
  186. PFILE_QUEUE_INFO pfqi = &MinimalServerFileQueue[0];
  187. DWORD CountMax = CountMinimalServerFileQueue;
  188. //
  189. // BugBug: might want to enable this block for product suites, so that client files are also copied over.
  190. //
  191. #if 0
  192. if (IsProductSuite()) {
  193. pfqi = &ServerFileQueue[0];
  194. CountMax = CountServerFileQueue;
  195. }
  196. #endif
  197. for (DWORD i=0; i<CountMax; i++) {
  198. ProcessFileQueueEntry(
  199. SetupInf,
  200. FileQueue,
  201. SourceRoot,
  202. &pfqi[i],
  203. SETUP_ACTION_COPY
  204. );
  205. }
  206. return TRUE;
  207. }
  208. BOOL
  209. CalcServerDiskSpace(
  210. HINF SetupInf,
  211. HDSKSPC DiskSpace,
  212. LPWSTR SourceRoot,
  213. BOOL AddToQueue
  214. )
  215. {
  216. BOOL Rval = TRUE;
  217. DWORD ec;
  218. PFILE_QUEUE_INFO pfqi = &MinimalServerFileQueue[0];
  219. DWORD CountMax = CountMinimalServerFileQueue;
  220. //
  221. // BugBug: might want to enable this block for product suites, so that client files are also copied over.
  222. //
  223. #if 0
  224. if (IsProductSuite()) {
  225. pfqi = &ServerFileQueue[0];
  226. CountMax = CountServerFileQueue;
  227. }
  228. #endif
  229. for (DWORD i=0; i<CountMax; i++) {
  230. if (!ProcessFileQueueEntryForDiskSpace(
  231. SetupInf,
  232. DiskSpace,
  233. SourceRoot,
  234. &pfqi[i],
  235. FILEOP_COPY,
  236. AddToQueue
  237. ))
  238. {
  239. ec = GetLastError();
  240. Rval = FALSE;
  241. }
  242. }
  243. return Rval;
  244. }
  245. BOOL
  246. CopyClientFiles(
  247. LPWSTR SourceRoot
  248. )
  249. {
  250. BOOL Rval = FALSE;
  251. HINF SetupInf = INVALID_HANDLE_VALUE;
  252. HSPFILEQ FileQueue = INVALID_HANDLE_VALUE;
  253. WCHAR Buffer[MAX_PATH];
  254. DWORD i;
  255. LPVOID Context = NULL;
  256. wcscpy( Buffer, SourceRoot );
  257. wcscat( Buffer, L"faxclnt.inf" );
  258. SetupInf = SetupOpenInfFile(
  259. Buffer,
  260. NULL,
  261. INF_STYLE_WIN4,
  262. NULL
  263. );
  264. if (SetupInf == INVALID_HANDLE_VALUE) {
  265. DebugPrint(( TEXT("SetupOpenInfFile() failed, [%s], ec=0x%08x"), Buffer, GetLastError() ));
  266. goto exit;
  267. }
  268. FileQueue = SetupOpenFileQueue();
  269. if (FileQueue == INVALID_HANDLE_VALUE) {
  270. DebugPrint(( TEXT("SetupOpenFileQueue() failed, ec=0x%08x"), GetLastError() ));
  271. goto exit;
  272. }
  273. for (i=0; i<CountClientFileQueue; i++) {
  274. ProcessFileQueueEntry(
  275. SetupInf,
  276. FileQueue,
  277. SourceRoot,
  278. &ClientFileQueue[i],
  279. SETUP_ACTION_COPY
  280. );
  281. }
  282. Context = SetupInitDefaultQueueCallbackEx( NULL, (HWND)INVALID_HANDLE_VALUE, 0, 0, 0 );
  283. if (!Context) {
  284. goto exit;
  285. }
  286. if (!SetupCommitFileQueue( NULL, FileQueue, SetupDefaultQueueCallback, Context )) {
  287. DebugPrint(( TEXT("SetupCommitFileQueue() failed, ec=0x%08x"), GetLastError() ));
  288. goto exit;
  289. }
  290. Rval = TRUE;
  291. exit:
  292. if (Context) {
  293. SetupTermDefaultQueueCallback( Context );
  294. }
  295. if (FileQueue != INVALID_HANDLE_VALUE) {
  296. SetupCloseFileQueue( FileQueue );
  297. }
  298. if (SetupInf != INVALID_HANDLE_VALUE) {
  299. SetupCloseInfFile( SetupInf );
  300. }
  301. return Rval;
  302. }