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.

189 lines
5.8 KiB

  1. #ifndef FILETREE_H
  2. #define FILETREE_H
  3. class FileNode;
  4. class DirectoryNode;
  5. class FileTree;
  6. ///////////////////////////////////////////////////////////////////////////////
  7. //
  8. // MULTI_THREAD_STRUCT, a parameter container, used when passing parameters to
  9. // a thread for file processing
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. typedef struct _MULTI_THREAD_STRUCT
  13. {
  14. FileTree* pThis;
  15. DirectoryNode* pParent;
  16. WCHAR filename[STRING_LENGTH];
  17. WCHAR path[STRING_LENGTH];
  18. DWORD attributes;
  19. FILETIME filetime;
  20. FILETIME creation;
  21. __int64 filesize;
  22. FileTree* pTree;
  23. BOOL blnInUse;
  24. }
  25. MULTI_THREAD_STRUCT;
  26. ///////////////////////////////////////////////////////////////////////////////
  27. //
  28. // FileNode, each file would have its own filenode object to store and
  29. // determine what to do about this file
  30. //
  31. ///////////////////////////////////////////////////////////////////////////////
  32. class FileNode
  33. {
  34. friend class DirectoryNode;
  35. public:
  36. FileNode(IN DirectoryNode* pParent,
  37. IN CONST WCHAR* pwszFileName,
  38. IN FILETIME ftLastModified,
  39. IN __int64 iFileSize);
  40. ~FileNode(VOID);
  41. INT ComputeHash(VOID);
  42. INT Match(IN FileTree* pBaseTree);
  43. INT BuildPatch(IN WCHAR* pwszBaseFileName,
  44. IN WCHAR* pwszLocFileName,
  45. IN OUT WCHAR* pwszTempPatchFileName,
  46. OUT __int64* pcbPatchSize);
  47. public:
  48. WCHAR m_wszLongFileName[STRING_LENGTH];
  49. WCHAR* m_wszFileName; // name of this file, ie, "kernel32.dll"
  50. FileNode* m_pNextNameHash; // next file with same filename hash
  51. private:
  52. FileNode* m_pNextHashHash; // next file with same hash hash
  53. DirectoryNode* m_pParent; // parent directory
  54. FILETIME m_ftLastModified; // last-modified timestamp
  55. __int64 m_iFileSize; // size of file in bytes
  56. INT m_fPostCopySource; // another file plans to postcopy this one
  57. unsigned m_FileNameHash; // hash of m_wszFileName
  58. BYTE m_Hash[16]; // file content's MD5 signature
  59. INT m_cchFileName; // length of m_wszFileName in characters, excl. term.
  60. };
  61. ///////////////////////////////////////////////////////////////////////////////
  62. //
  63. // DirectoryNode, each directory is associated with its own dirctorynode, which
  64. // contains all information about this directory
  65. //
  66. ///////////////////////////////////////////////////////////////////////////////
  67. class DirectoryNode
  68. {
  69. friend class FileNode;
  70. public:
  71. DirectoryNode(IN FileTree* pRoot,
  72. IN DirectoryNode* pParent,
  73. IN CONST WCHAR* pwszDirectoryName);
  74. ~DirectoryNode(VOID);
  75. WCHAR* GetDirectoryName(VOID);
  76. INT Match(IN FileTree* pBaseTree);
  77. public:
  78. WCHAR m_wszLongDirectoryName[STRING_LENGTH];
  79. WCHAR* m_wszDirectoryName; // name of this directory, ie, "system32"
  80. private:
  81. FileTree* m_pRoot; // pointer to FileTree
  82. DirectoryNode* m_pParent; // parent of this node
  83. DirectoryNode* m_pNext; // next sibling of this node
  84. DirectoryNode* m_pFirstChild; // first child directory
  85. DirectoryNode* m_pMatchingDirectory; // ptr to mate in base tree
  86. unsigned m_DirectoryNameHash; // hash of m_wszDirectoryName
  87. INT m_cchDirectoryName; // length of m_wszDirectoryName in characters, excl. term.
  88. };
  89. ///////////////////////////////////////////////////////////////////////////////
  90. //
  91. // FileTree, a tree of directory and file nodes, used to match with another
  92. // filetree using hashing techniques
  93. //
  94. ///////////////////////////////////////////////////////////////////////////////
  95. class FileTree
  96. {
  97. friend class FileNode;
  98. friend class DirectoryNode;
  99. public:
  100. static BOOL CreateMultiThreadStruct(IN ULONG iNumber);
  101. static VOID DeleteMultiThreadStruct(VOID);
  102. static INT Create(IN PPATCH_LANGUAGE pInLanguage,
  103. IN AnswerParser* pInAnsParse,
  104. OUT FileTree** ppTree,
  105. IN BOOL blnBase,
  106. IN DWORD iInBestMethod,
  107. IN BOOL blnInCollectStat,
  108. IN BOOL blnInFullLog);
  109. FileTree(IN CONST WCHAR* pwszPath);
  110. ~FileTree(VOID);
  111. INT Load(IN FileTree* pTree);
  112. BOOL CreateNewDirectory(IN WCHAR* pwszLocal,
  113. IN CONST WCHAR* pwszBuffer);
  114. BOOL CopyFileTo(IN FileTree* pThis,
  115. IN CONST WCHAR* pwszWhat,
  116. IN WCHAR* pwszLocal,
  117. IN CONST WCHAR* pwszFileName,
  118. IN WCHAR* pwszOldFile,
  119. IN DWORD attributes);
  120. VOID ToScriptFile(IN FileTree* pThis,
  121. IN HANDLE hFile,
  122. IN CONST WCHAR* pwszWhat,
  123. IN CONST WCHAR* pwszFirst,
  124. IN WCHAR* pwszSecond,
  125. IN BOOL blnFlush);
  126. public:
  127. WCHAR m_wszLocalRoot[STRING_LENGTH]; // local path to this tree's root, ie, "C:\SRC\"
  128. private:
  129. static FN_DIRECTORY NotifyDirectory;
  130. static FN_FILE NotifyFile;
  131. static FN_DIRECTORY_END NotifyDirectoryEnd;
  132. static DWORD WINAPI StartFileThread(IN LPVOID lpParam);
  133. static INT ProcessFile(
  134. IN FileTree* pThis,
  135. IN DirectoryNode* pParent,
  136. IN CONST WCHAR* filename,
  137. IN CONST WCHAR* path,
  138. IN DWORD attributes,
  139. IN FILETIME filetime,
  140. IN FILETIME creation,
  141. IN __int64 filesize,
  142. IN FileTree* pTree,
  143. IN VOID* pStruct
  144. );
  145. private:
  146. CRITICAL_SECTION CSScriptFile;
  147. PPATCH_LANGUAGE m_pLanguage;
  148. AnswerParser* m_pAnsParse;
  149. BOOL m_blnBase;
  150. WCHAR m_strWriteBuffer[SUPER_LENGTH];
  151. ULONG m_iSize;
  152. DirectoryNode m_Root;
  153. __int64 m_cDirectories;
  154. __int64 m_cFiles;
  155. __int64 m_cFilesDetermined;
  156. __int64 m_cbTotalFileSize;
  157. __int64 m_cFilesExisting;
  158. __int64 m_cFilesZeroLength;
  159. __int64 m_cFilesRenamed;
  160. __int64 m_cFilesCopied;
  161. __int64 m_cFilesChanged;
  162. __int64 m_cbChangedFileSize;
  163. __int64 m_cbChangedFilePatchedSize;
  164. __int64 m_cbChangedFileNotPatchedSize;
  165. __int64 m_cFilesNoMatch;
  166. __int64 m_cbNoMatchFileSize;
  167. FileNode* m_aHashTable[HASH_SIZE];
  168. FileNode* m_aNameTable[HASH_SIZE];
  169. INT m_cchLocalRoot; // length of m_wszLocalRoot in characters, excl. term.
  170. };
  171. #endif // FILETREE_H