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.

152 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. queue.hpp
  5. Abstract:
  6. Abstracts setupapi's file queue
  7. Author:
  8. Vijay Jayaseelan (vijayj) 08 Oct 2000
  9. Revision History:
  10. None
  11. --*/
  12. #pragma once
  13. //
  14. // Disable the compiler warning for long names
  15. //
  16. #pragma warning( disable : 4786 )
  17. #include <setupapi.hpp>
  18. template <class T>
  19. class FileQueue {
  20. public:
  21. FileQueue() {
  22. QueueHandle = SetupOpenFileQueue();
  23. if (QueueHandle == INVALID_HANDLE_VALUE) {
  24. throw new W32Exception();
  25. }
  26. }
  27. void AddForCopy(const std::basic_string<T> &SourceRoot,
  28. const std::basic_string<T> &SourcePath,
  29. const std::basic_string<T> &SourceFileName,
  30. const std::basic_string<T> &DestPath,
  31. const std::basic_string<T> &DestFileName,
  32. DWORD CopyFlags) {
  33. BOOL Result = FALSE;
  34. /*
  35. if (sizeof(T) == sizeof(WCHAR)) {
  36. Result = SetupQueueCopyW(QueueHandle,
  37. (PCWSTR)SourceRoot.c_str(),
  38. (PCWSTR)SourcePath.c_str(),
  39. (PCWSTR) // Left editing here ...
  40. */
  41. }
  42. void AddForCopy(const SectionValues<T> &RecordToCopy,
  43. const std::basic_string<T> &DirSectionName,
  44. const std::basic_string<T> &SourceRoot,
  45. DWORD CopyStyle) {
  46. BOOL Result = FALSE;
  47. InfFile<T> &File = RecordToCopy.GetContainer().GetContainer();
  48. Section<T> *DirSection = File.GetSection(DirSectionName);
  49. if (sizeof(T) == sizeof(WCHAR)) {
  50. Result = SetupQueueCopyW(QueueHandle,
  51. (PCWSTR)SourceRoot.c_str(),
  52. (PCWSTR)RecordToCopy.GetValue(1).c_str(),
  53. (PCWSTR)RecordToCopy.GetName().c_str(),
  54. NULL,
  55. NULL,
  56. (PCWSTR)DirSection->GetValue(RecordToCopy.GetValue(7).c_str()).GetValue(0).c_str(),
  57. (PCWSTR)RecordToCopy.GetValue(10).c_str(),
  58. CopyStyle);
  59. } else {
  60. Result = SetupQueueCopyA(QueueHandle,
  61. (PCSTR)SourceRoot.c_str(),
  62. (PCSTR)RecordToCopy.GetValue(1).c_str(),
  63. (PCSTR)RecordToCopy.GetName().c_str(),
  64. NULL,
  65. NULL,
  66. (PCSTR)DirSection->GetValue(RecordToCopy.GetValue(7).c_str()).GetValue(0).c_str(),
  67. (PCSTR)RecordToCopy.GetValue(10).c_str(),
  68. CopyStyle);
  69. }
  70. if (!Result) {
  71. throw new W32Exception();
  72. }
  73. }
  74. void AddForCopy(const Section<T> &SectionToCopy,
  75. const std::basic_string<T> &DirSectionName,
  76. const std::basic_string<T> &SourceRoot,
  77. DWORD CopyStyle) {
  78. CopyWorkerState State(*this, DirSectionName, SourceRoot, CopyStyle);
  79. SectionToCopy->DoForEach(SectionCopyWorker, &State);
  80. }
  81. void Commit() {
  82. if (!SetupCommitFileQueue(NULL,
  83. QueueHandle,
  84. SetupDefaultQueueCallback,
  85. NULL)) {
  86. throw new W32Exception();
  87. }
  88. }
  89. virtual ~FileQueue() {
  90. if (QueueHandle != INVALID_HANDLE_VALUE) {
  91. SetupCloseFileQueue(QueueHandle);
  92. }
  93. }
  94. protected:
  95. struct CopyWorkerState {
  96. FileQueue<T> &Queue;
  97. const std::basic_string<T> &DirSectionName;
  98. const std::basic_string<T> &SourceRoot;
  99. DWORD CopyState;
  100. CopyWorkerState(FileQueue<T> &Que, const std::basic_string<T> &DirSecName,
  101. const std::basic_string<T> &SrcRoot, DWORD Copy) : Queue(Que),
  102. DirSectionName(DirSecName), SourceRoot(SrcRoot),
  103. CopyState(Copy){}
  104. };
  105. static void SectionCopyWorker(SectionValues<T> &Value, void *ContextData) {
  106. CopyWorkerState *State = (CopyWorkerState *)ContextData;
  107. if (Queue) {
  108. Queue->AddForCopy(State->Queue,
  109. State->DirSectionName,
  110. State->SourceRoot);
  111. }
  112. }
  113. //
  114. // data members
  115. //
  116. HSPFILEQ QueueHandle;
  117. };
  118. typedef FileQueue<CHAR> FileQueueA;
  119. typedef FileQueue<WCHAR> FileQueueW;