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.

233 lines
6.9 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: History.h
  6. // Author: Charles Ma, 10/13/2000
  7. //
  8. // Revision History:
  9. //
  10. //
  11. //
  12. // Description:
  13. //
  14. // Class to handle history log
  15. //
  16. //=======================================================================
  17. #include "iuxml.h"
  18. // ----------------------------------------------------------------------
  19. //
  20. // define the enum for download/install status
  21. //
  22. // ----------------------------------------------------------------------
  23. enum _HISTORY_STATUS {
  24. HISTORY_STATUS_COMPLETE = 0,
  25. HISTORY_STATUS_IN_PROGRESS = 1, // currently should be ignored of this!
  26. HISTORY_STATUS_FAILED = -1
  27. };
  28. // ----------------------------------------------------------------------
  29. //
  30. // define the class for history
  31. //
  32. // ----------------------------------------------------------------------
  33. class CIUHistory
  34. {
  35. public:
  36. CIUHistory();
  37. ~CIUHistory();
  38. // ------------------------------------------------------------------
  39. //
  40. // public function SetDownloadBasePath()
  41. // this function should be called before AddHistoryItemDownloadStatus()
  42. // for corporate case to set the download path that the user has input,
  43. // so that we know where to save the history log.
  44. //
  45. // ------------------------------------------------------------------
  46. HRESULT SetDownloadBasePath(LPCTSTR pszDownloadedBasePath);
  47. // ------------------------------------------------------------------
  48. //
  49. // public function AddHistoryItemDownloadStatus()
  50. // this function should be called when you want to record the
  51. // download status of this item. A new history item will be
  52. // added to the history file
  53. //
  54. // ------------------------------------------------------------------
  55. HRESULT AddHistoryItemDownloadStatus(
  56. CXmlCatalog* pCatalog,
  57. HANDLE_NODE hCatalogItem, // a handle points to node in catalog
  58. _HISTORY_STATUS enDownloadStatus,
  59. LPCTSTR lpcszDownloadedTo,
  60. LPCTSTR lpcszClient,
  61. DWORD dwErrorCode = 0
  62. );
  63. // ------------------------------------------------------------------
  64. //
  65. // public function AddHistoryItemInstallStatus()
  66. // this function should be called when you want to record the
  67. // install status of this item. This function will go to the
  68. // existing history tree and find the first item that matches
  69. // the identity of hCatalogItem, and assume that one as
  70. // the one you want to modify the install status
  71. //
  72. //
  73. // return:
  74. // HRESULT - S_OK if succeeded
  75. // - E_HANDLE if can't find hCatalogItem from
  76. // the current history log tree
  77. // - or other HRESULT error
  78. //
  79. // ------------------------------------------------------------------
  80. HRESULT AddHistoryItemInstallStatus(
  81. CXmlCatalog* pCatalog,
  82. HANDLE_NODE hCatalogItem, // a handle points to node in catalog
  83. _HISTORY_STATUS enInstallStatus,
  84. LPCTSTR lpcszClient,
  85. BOOL fNeedsReboot,
  86. DWORD dwErrorCode = 0
  87. );
  88. // ------------------------------------------------------------------
  89. //
  90. // public function UpdateHistoryItemInstallStatus()
  91. // this function should be called when you want to record the
  92. // install status of this item. This function will go to the
  93. // existing history tree and find the first item that matches
  94. // the identity of hCatalogItem, and assume that one as
  95. // the one you want to modify the install status
  96. //
  97. //
  98. // return:
  99. // HRESULT - S_OK if succeeded
  100. // - E_HANDLE if can't find hCatalogItem from
  101. // the current history log tree
  102. // - or other HRESULT error
  103. //
  104. // ------------------------------------------------------------------
  105. HRESULT UpdateHistoryItemInstallStatus(
  106. CXmlCatalog* pCatalog,
  107. HANDLE_NODE hCatalogItem, // a handle points to node in catalog
  108. _HISTORY_STATUS enInstallStatus,
  109. BOOL fNeedsReboot,
  110. DWORD dwErrorCode /*= 0*/
  111. );
  112. /* // ------------------------------------------------------------------
  113. //
  114. // public function RetrieveItemDownloadPath()
  115. // this function will go to the existing history tree and find
  116. // the first item that matches the identity of hCatalogItem, and
  117. // assume that's the one you want to retrieve the download path from
  118. //
  119. // return:
  120. // HRESULT - S_OK if succeeded
  121. // - E_HANDLE if can't find hCatalogItem from
  122. // the current history log tree
  123. // - or other HRESULT error
  124. //
  125. // ------------------------------------------------------------------
  126. HRESULT CIUHistory::RetrieveItemDownloadPath(
  127. CXmlCatalog* pCatalog,
  128. HANDLE_NODE hCatalogItem, // a handle points to node in catalog
  129. BSTR* pbstrDownloadPath
  130. );
  131. */
  132. // ------------------------------------------------------------------
  133. //
  134. // public function ReadHistoryFromDisk()
  135. // this function will read the history from the given file
  136. //
  137. // ------------------------------------------------------------------
  138. HRESULT ReadHistoryFromDisk(LPCTSTR lpszLogFile, BOOL fCorpAdmin = FALSE);
  139. // ------------------------------------------------------------------
  140. //
  141. // public function SaveHistoryToDisk()
  142. // this function will re-read the history in exclusive mode, and
  143. // merge the newly added data to the tree (so we don't overwrite
  144. // new changes made by other instances of this control) and
  145. // write it back
  146. //
  147. // ------------------------------------------------------------------
  148. HRESULT SaveHistoryToDisk(void);
  149. // ------------------------------------------------------------------
  150. //
  151. // public function to set the client name
  152. //
  153. // a client name is used to put in history to denode who
  154. // caused download/install happened.
  155. //
  156. // ------------------------------------------------------------------
  157. void SetClientName(BSTR bstrClientName);
  158. // ------------------------------------------------------------------
  159. //
  160. // public function GetHistory
  161. //
  162. // read the current history XML file and convert it
  163. // into bstr to pass out
  164. //
  165. // ------------------------------------------------------------------
  166. HRESULT GetHistoryStr(
  167. LPCTSTR lpszLogFile,
  168. BSTR BeginDateTime,
  169. BSTR EndDateTime,
  170. BSTR* pbstrHistory);
  171. private:
  172. // ------------------------------------------------------------------
  173. //
  174. // private inline function GetBSTRStatus
  175. //
  176. // ------------------------------------------------------------------
  177. inline BSTR GetBSTRStatus(_HISTORY_STATUS enStatus)
  178. {
  179. BSTR bstrStatus = NULL;
  180. switch (enStatus)
  181. {
  182. case HISTORY_STATUS_COMPLETE:
  183. bstrStatus = SysAllocString(L"COMPLETE");
  184. break;
  185. case HISTORY_STATUS_IN_PROGRESS:
  186. bstrStatus = SysAllocString(L"IN_PROGRESS");
  187. break;
  188. default:
  189. bstrStatus = SysAllocString(L"FAILED");
  190. };
  191. return bstrStatus;
  192. };
  193. //
  194. // named mutex used to gain exclusive access to the history file
  195. //
  196. BOOL m_fSavePending;
  197. HANDLE m_hMutex;
  198. HRESULT m_ErrorCode;
  199. BSTR m_bstrCurrentClientName;
  200. TCHAR m_szLogFilePath[MAX_PATH];
  201. LPTSTR m_pszDownloadBasePath;
  202. CXmlItems *m_pxmlExisting;
  203. CXmlItems *m_pxmlDownload;
  204. CXmlItems *m_pxmlInstall;
  205. };