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.

126 lines
2.1 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <wbemcomn.h>
  7. #include <reposit.h>
  8. #include "filecach.h"
  9. #include "creposit.h"
  10. long CFileCache::InnerInitialize(LPCWSTR wszBaseName)
  11. {
  12. long lRes;
  13. wcscpy(m_wszBaseName, wszBaseName);
  14. wcscat(m_wszBaseName, L"\\");
  15. m_dwBaseNameLen = wcslen(m_wszBaseName);
  16. lRes = m_TransactionManager.Init();
  17. if(lRes != ERROR_SUCCESS)
  18. return lRes;
  19. lRes = m_TransactionManager.BeginTrans();
  20. if (lRes != ERROR_SUCCESS)
  21. return lRes;
  22. lRes = m_ObjectHeap.Initialize(&m_TransactionManager,
  23. (WCHAR*)wszBaseName,
  24. m_dwBaseNameLen);
  25. if(lRes != ERROR_SUCCESS)
  26. {
  27. m_TransactionManager.RollbackTrans();
  28. }
  29. else
  30. {
  31. lRes = m_TransactionManager.CommitTrans();
  32. if (lRes != ERROR_SUCCESS)
  33. m_TransactionManager.RollbackTrans();
  34. }
  35. return lRes;
  36. }
  37. long CFileCache::RepositoryExists(LPCWSTR wszBaseName)
  38. {
  39. CFileName wszStagingName;
  40. if (wszStagingName == NULL)
  41. return ERROR_OUTOFMEMORY;
  42. swprintf(wszStagingName, L"%s\\index.btr", wszBaseName);
  43. DWORD dwAttributes = GetFileAttributesW(wszStagingName);
  44. if (dwAttributes == -1)
  45. return ERROR_FILE_NOT_FOUND;
  46. return ERROR_SUCCESS;
  47. }
  48. long CFileCache::Initialize(LPCWSTR wszBaseName)
  49. {
  50. long lRes;
  51. if (m_bInit)
  52. return ERROR_SUCCESS;
  53. lRes = RepositoryExists(wszBaseName);
  54. if (ERROR_FILE_NOT_FOUND == lRes)
  55. {
  56. //If we have a database restore to do, go ahead and do it...
  57. lRes = DoAutoDatabaseRestore();
  58. }
  59. //
  60. // Initialize file cache. It will read the registry itself to find out
  61. // its size limitations
  62. //
  63. if (SUCCEEDED(lRes))
  64. {
  65. lRes = InnerInitialize(wszBaseName);
  66. if (ERROR_SUCCESS == lRes)
  67. {
  68. m_bInit = TRUE;
  69. }
  70. }
  71. return lRes;
  72. }
  73. CFileCache::CFileCache()
  74. : m_lRef(1), m_bInit(FALSE)
  75. {
  76. }
  77. CFileCache::~CFileCache()
  78. {
  79. }
  80. long CFileCache::Uninitialize(DWORD dwShutDownFlags)
  81. {
  82. if (!m_bInit)
  83. return 0;
  84. Clear(dwShutDownFlags);
  85. m_bInit = FALSE;
  86. return 0;
  87. }