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.

318 lines
7.6 KiB

  1. // Rebuild.cpp : Implementation of CNntpAdminRebuild.
  2. #include "stdafx.h"
  3. #include "nntpcmn.h"
  4. #include "oleutil.h"
  5. #include "Rebuild.h"
  6. #include "nntptype.h"
  7. #include "nntpapi.h"
  8. #include <lmapibuf.h>
  9. //
  10. // Defaults:
  11. //
  12. #define DEFAULT_VERBOSE ( FALSE )
  13. #define DEFAULT_CLEAN_REBUILD ( TRUE )
  14. #define DEFAULT_DONT_DELETE_HISTORY ( FALSE )
  15. #define DEFAULT_REUSE_INDEX_FILES ( TRUE )
  16. #define DEFAULT_OMIT_NON_LEAF_DIRS ( TRUE )
  17. #define DEFAULT_GROUP_FILE ( NULL )
  18. #define DEFAULT_REPORT_FILE ( _T("nntpbld.log") )
  19. #define DEFAULT_NUM_THREADS ( 0 )
  20. // Must define THIS_FILE_* macros to use NntpCreateException()
  21. #define THIS_FILE_HELP_CONTEXT 0
  22. #define THIS_FILE_PROG_ID _T("Nntpadm.Rebuild.1")
  23. #define THIS_FILE_IID IID_INntpAdminRebuild
  24. /////////////////////////////////////////////////////////////////////////////
  25. //
  26. //
  27. // Use a macro to define all the default methods
  28. //
  29. DECLARE_METHOD_IMPLEMENTATION_FOR_STANDARD_EXTENSION_INTERFACES(NntpAdminRebuild, CNntpAdminRebuild, IID_INntpAdminRebuild)
  30. STDMETHODIMP CNntpAdminRebuild::InterfaceSupportsErrorInfo(REFIID riid)
  31. {
  32. static const IID* arr[] =
  33. {
  34. &IID_INntpAdminRebuild,
  35. };
  36. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  37. {
  38. if (InlineIsEqualGUID(*arr[i],riid))
  39. return S_OK;
  40. }
  41. return S_FALSE;
  42. }
  43. CNntpAdminRebuild::CNntpAdminRebuild () :
  44. m_fVerbose ( FALSE ),
  45. m_fCleanRebuild ( FALSE ),
  46. m_fDontDeleteHistory ( FALSE ),
  47. m_fReuseIndexFiles ( FALSE ),
  48. m_fOmitNonLeafDirs ( FALSE ),
  49. m_dwNumThreads ( 0 ),
  50. m_fRebuildInProgress ( FALSE )
  51. // CComBSTR's are initialized to NULL by default.
  52. {
  53. InitAsyncTrace ( );
  54. m_iadsImpl.SetService ( MD_SERVICE_NAME );
  55. m_iadsImpl.SetName ( _T("Rebuild") );
  56. m_iadsImpl.SetClass ( _T("IIsNntpRebuild") );
  57. }
  58. CNntpAdminRebuild::~CNntpAdminRebuild ()
  59. {
  60. // All CComBSTR's are freed automatically.
  61. TermAsyncTrace ( );
  62. }
  63. //
  64. // IADs methods:
  65. //
  66. DECLARE_SIMPLE_IADS_IMPLEMENTATION(CNntpAdminRebuild,m_iadsImpl)
  67. //
  68. // Properties:
  69. //
  70. STDMETHODIMP CNntpAdminRebuild::get_Verbose ( BOOL * pfVerbose )
  71. {
  72. return StdPropertyGet ( m_fVerbose, pfVerbose );
  73. }
  74. STDMETHODIMP CNntpAdminRebuild::put_Verbose ( BOOL fVerbose )
  75. {
  76. return StdPropertyPut ( &m_fVerbose, fVerbose );
  77. }
  78. STDMETHODIMP CNntpAdminRebuild::get_CleanRebuild ( BOOL * pfCleanRebuild )
  79. {
  80. return StdPropertyGet ( m_fCleanRebuild, pfCleanRebuild );
  81. }
  82. STDMETHODIMP CNntpAdminRebuild::put_CleanRebuild ( BOOL fCleanRebuild )
  83. {
  84. return StdPropertyPut ( &m_fCleanRebuild, fCleanRebuild );
  85. }
  86. STDMETHODIMP CNntpAdminRebuild::get_DontDeleteHistory ( BOOL * pfDontDeleteHistory )
  87. {
  88. return StdPropertyGet ( m_fDontDeleteHistory, pfDontDeleteHistory );
  89. }
  90. STDMETHODIMP CNntpAdminRebuild::put_DontDeleteHistory ( BOOL fDontDeleteHistory )
  91. {
  92. return StdPropertyPut ( &m_fDontDeleteHistory, fDontDeleteHistory );
  93. }
  94. STDMETHODIMP CNntpAdminRebuild::get_ReuseIndexFiles ( BOOL * pfReuseIndexFiles )
  95. {
  96. return StdPropertyGet ( (DWORD) m_fReuseIndexFiles, (DWORD *) pfReuseIndexFiles );
  97. }
  98. STDMETHODIMP CNntpAdminRebuild::put_ReuseIndexFiles ( BOOL fReuseIndexFiles )
  99. {
  100. return StdPropertyPut ( (DWORD *) &m_fReuseIndexFiles, (DWORD) fReuseIndexFiles );
  101. }
  102. STDMETHODIMP CNntpAdminRebuild::get_OmitNonLeafDirs ( BOOL * pfOmitNonLeafDirs )
  103. {
  104. return StdPropertyGet ( m_fOmitNonLeafDirs, pfOmitNonLeafDirs );
  105. }
  106. STDMETHODIMP CNntpAdminRebuild::put_OmitNonLeafDirs ( BOOL fOmitNonLeafDirs )
  107. {
  108. return StdPropertyPut ( &m_fOmitNonLeafDirs, fOmitNonLeafDirs );
  109. }
  110. STDMETHODIMP CNntpAdminRebuild::get_GroupFile ( BSTR * pstrGroupFile )
  111. {
  112. return StdPropertyGet ( m_strGroupFile, pstrGroupFile );
  113. }
  114. STDMETHODIMP CNntpAdminRebuild::put_GroupFile ( BSTR strGroupFile )
  115. {
  116. return StdPropertyPut ( &m_strGroupFile, strGroupFile );
  117. }
  118. STDMETHODIMP CNntpAdminRebuild::get_ReportFile ( BSTR * pstrReportFile )
  119. {
  120. return StdPropertyGet ( m_strReportFile, pstrReportFile );
  121. }
  122. STDMETHODIMP CNntpAdminRebuild::put_ReportFile ( BSTR strReportFile )
  123. {
  124. return StdPropertyPut ( &m_strReportFile, strReportFile );
  125. }
  126. STDMETHODIMP CNntpAdminRebuild::get_NumThreads ( long * plNumThreads )
  127. {
  128. return StdPropertyGet ( m_dwNumThreads, plNumThreads );
  129. }
  130. STDMETHODIMP CNntpAdminRebuild::put_NumThreads ( long lNumThreads )
  131. {
  132. return StdPropertyPut ( &m_dwNumThreads, lNumThreads );
  133. }
  134. //////////////////////////////////////////////////////////////////////
  135. // Methods:
  136. //////////////////////////////////////////////////////////////////////
  137. STDMETHODIMP CNntpAdminRebuild::Default ( )
  138. {
  139. HRESULT hr = NOERROR;
  140. m_fVerbose = DEFAULT_VERBOSE;
  141. m_fCleanRebuild = DEFAULT_CLEAN_REBUILD;
  142. m_fDontDeleteHistory = DEFAULT_DONT_DELETE_HISTORY;
  143. m_fReuseIndexFiles = DEFAULT_REUSE_INDEX_FILES;
  144. m_fOmitNonLeafDirs = DEFAULT_OMIT_NON_LEAF_DIRS;
  145. // m_strGroupFile = DEFAULT_GROUP_FILE;
  146. m_strReportFile = DEFAULT_REPORT_FILE;
  147. m_dwNumThreads = DEFAULT_NUM_THREADS;
  148. return hr;
  149. }
  150. STDMETHODIMP CNntpAdminRebuild::StartRebuild ( )
  151. {
  152. TraceFunctEnter ( "CNntpAdminRebuild::StartRebuild" );
  153. HRESULT hr = NOERROR;
  154. NNTPBLD_INFO bldinfo;
  155. DWORD dwError;
  156. if ( m_fRebuildInProgress ) {
  157. return NntpCreateException ( IDS_NNTPEXCEPTION_ALREADY_BUILDING );
  158. }
  159. ZeroMemory ( &bldinfo, sizeof (bldinfo) );
  160. bldinfo.Verbose = !!m_fVerbose;
  161. bldinfo.DoClean = !!m_fCleanRebuild;
  162. bldinfo.NoHistoryDelete = !!m_fDontDeleteHistory;
  163. bldinfo.ReuseIndexFiles = m_fReuseIndexFiles;
  164. bldinfo.OmitNonleafDirs = !!m_fOmitNonLeafDirs;
  165. bldinfo.szGroupFile = m_strGroupFile;
  166. bldinfo.cbGroupFile = STRING_BYTE_LENGTH ( m_strGroupFile );
  167. bldinfo.szReportFile = m_strReportFile;
  168. bldinfo.cbReportFile = STRING_BYTE_LENGTH ( m_strReportFile );
  169. bldinfo.NumThreads = m_dwNumThreads;
  170. dwError = NntpStartRebuild (
  171. m_iadsImpl.QueryComputer(),
  172. m_iadsImpl.QueryInstance(),
  173. &bldinfo,
  174. NULL
  175. );
  176. if ( dwError == NOERROR ) {
  177. // We've successfully started a rebuild.
  178. m_fRebuildInProgress = TRUE;
  179. }
  180. else {
  181. _ASSERT ( dwError != NOERROR );
  182. hr = RETURNCODETOHRESULT ( dwError );
  183. }
  184. TRACE_HRESULT(hr);
  185. TraceFunctLeave ();
  186. return hr;
  187. }
  188. STDMETHODIMP CNntpAdminRebuild::GetProgress ( long * pdwProgress )
  189. {
  190. TraceFunctEnter ( "CNntpAdminRebuild::GetProgress" );
  191. HRESULT hr = NOERROR;
  192. DWORD dwError;
  193. DWORD dwProgress;
  194. _ASSERT ( IS_VALID_OUT_PARAM ( pdwProgress ) );
  195. if ( pdwProgress == NULL ) {
  196. return E_POINTER;
  197. }
  198. *pdwProgress = 0;
  199. // Should I send back an exception if the build is finished?
  200. if ( !m_fRebuildInProgress ) {
  201. *pdwProgress = 100;
  202. return NOERROR;
  203. }
  204. dwError = NntpGetBuildStatus (
  205. m_iadsImpl.QueryComputer(),
  206. m_iadsImpl.QueryInstance(),
  207. FALSE,
  208. &dwProgress
  209. );
  210. if ( dwError == NOERROR ) {
  211. *pdwProgress = dwProgress;
  212. }
  213. else {
  214. _ASSERT ( dwError != NOERROR );
  215. hr = RETURNCODETOHRESULT ( dwError );
  216. }
  217. // Are we still rebuilding?
  218. if ( dwError != NOERROR || dwProgress == 100 ) {
  219. // The rebuild is finished.
  220. m_fRebuildInProgress = FALSE;
  221. }
  222. TRACE_HRESULT(hr);
  223. TraceFunctLeave ();
  224. return hr;
  225. }
  226. STDMETHODIMP CNntpAdminRebuild::Cancel ( )
  227. {
  228. TraceFunctEnter ( "CNntpAdminRebuild::Cancel" );
  229. HRESULT hr = NOERROR;
  230. DWORD dwError;
  231. DWORD dwProgress;
  232. // Should I send back an exception if the build is finished?
  233. if ( !m_fRebuildInProgress ) {
  234. return NOERROR;
  235. }
  236. dwError = NntpGetBuildStatus (
  237. m_iadsImpl.QueryComputer(),
  238. m_iadsImpl.QueryInstance(),
  239. TRUE,
  240. &dwProgress
  241. );
  242. if ( dwError != NOERROR ) {
  243. hr = RETURNCODETOHRESULT ( dwError );
  244. }
  245. // Cancel always stops a rebuild:
  246. m_fRebuildInProgress = FALSE;
  247. TRACE_HRESULT(hr);
  248. TraceFunctLeave ();
  249. return hr;
  250. }