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.

160 lines
3.7 KiB

  1. #include "shellprv.h"
  2. #include "ftascstr.h"
  3. #include "ftassoc.h" //for now, until use CoCreateInstance
  4. #include "ftenum.h" //for now, until use CoCreateInstance
  5. HRESULT CFTAssocStore::_hresAccess = -1;
  6. HRESULT CFTAssocStore::EnumAssocInfo(ASENUM asenumFlags, LPTSTR pszStr,
  7. AIINIT aiinitFlags, IEnumAssocInfo** ppEnum)
  8. {
  9. //for now
  10. *ppEnum = new CFTEnumAssocInfo();
  11. if (*ppEnum)
  12. {
  13. (*ppEnum)->Init(asenumFlags, pszStr, aiinitFlags);
  14. }
  15. return (*ppEnum) ? S_OK : E_OUTOFMEMORY;
  16. }
  17. HRESULT CFTAssocStore::GetAssocInfo(LPTSTR pszStr, AIINIT aiinitFlags, IAssocInfo** ppAI)
  18. {
  19. HRESULT hres = E_FAIL;
  20. *ppAI = new CFTAssocInfo();
  21. if (*ppAI)
  22. hres = (*ppAI)->Init(aiinitFlags, pszStr);
  23. else
  24. hres = E_OUTOFMEMORY;
  25. return hres;
  26. }
  27. HRESULT CFTAssocStore::GetComplexAssocInfo(LPTSTR pszStr1, AIINIT aiinitFlags1,
  28. LPTSTR pszStr2, AIINIT aiinitFlags2, IAssocInfo** ppAI)
  29. {
  30. HRESULT hres = E_FAIL;
  31. *ppAI = new CFTAssocInfo();
  32. if (*ppAI)
  33. hres = (*ppAI)->InitComplex(aiinitFlags1, pszStr1, aiinitFlags2, pszStr2);
  34. else
  35. hres = E_OUTOFMEMORY;
  36. return hres;
  37. }
  38. HRESULT CFTAssocStore::CheckAccess()
  39. {
  40. #if 0
  41. // Should be something like this but it does not work
  42. if (-1 == _hresAccess)
  43. {
  44. HKEY hkey;
  45. _hresAccess = S_FALSE;
  46. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, NULL, 0,
  47. KEY_CREATE_SUB_KEY | KEY_READ | KEY_SET_VALUE | KEY_QUERY_VALUE, &hkey))
  48. {
  49. _hresAccess = S_OK;
  50. RegCloseKey(hkey);
  51. }
  52. }
  53. #endif
  54. if (-1 == _hresAccess)
  55. {
  56. TCHAR szGUID[] = TEXT("{A4BFEC7C-F821-11d2-86BE-0000F8757D7E}");
  57. DWORD dwDisp = 0;
  58. int cTry = 0;
  59. HKEY hkey;
  60. _hresAccess = S_FALSE;
  61. // we want to try this only two times
  62. while ((S_FALSE == _hresAccess) && (cTry <= 1))
  63. {
  64. ++cTry;
  65. // we try to write a GUID to HKCR and delete it
  66. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, szGUID, 0, NULL, REG_OPTION_NON_VOLATILE,
  67. MAXIMUM_ALLOWED, NULL, &hkey, &dwDisp))
  68. {
  69. // Did we really created a new key?
  70. if (REG_CREATED_NEW_KEY == dwDisp)
  71. {
  72. // yes
  73. RegCloseKey(hkey);
  74. if (ERROR_SUCCESS == RegDeleteKey(HKEY_CLASSES_ROOT, szGUID))
  75. {
  76. _hresAccess = S_OK;
  77. }
  78. }
  79. else
  80. {
  81. // No, there was already one, maybe we crashed right in the middle of this fct
  82. // some other time in the past
  83. // delete the key and try again
  84. RegDeleteKey(HKEY_CLASSES_ROOT, szGUID);
  85. }
  86. }
  87. }
  88. }
  89. return _hresAccess;
  90. }
  91. ///////////////////////////////////////////////////////////////////////////////
  92. //
  93. CFTAssocStore::CFTAssocStore()
  94. {
  95. _hresCoInit = SHCoInitialize();
  96. //DLLAddRef();
  97. }
  98. CFTAssocStore::~CFTAssocStore()
  99. {
  100. //DLLRelease();
  101. SHCoUninitialize(_hresCoInit);
  102. }
  103. //IUnknown methods
  104. HRESULT CFTAssocStore::QueryInterface(REFIID riid, PVOID* ppv)
  105. {
  106. #if 0
  107. static const QITAB qit[] = {
  108. QITABENT(CFTAssocStore, IAssocStore),
  109. { 0 },
  110. };
  111. return QISearch(this, qit, riid, ppvObj);
  112. #endif
  113. if (IsEqualIID(riid, IID_IUnknown))
  114. *ppv = static_cast<IUnknown*>(this);
  115. else
  116. *ppv = static_cast<IAssocStore*>(this);
  117. return S_OK;
  118. }
  119. ULONG CFTAssocStore::AddRef()
  120. {
  121. return InterlockedIncrement(&_cRef);
  122. }
  123. ULONG CFTAssocStore::Release()
  124. {
  125. if (InterlockedDecrement(&_cRef))
  126. return _cRef;
  127. delete this;
  128. return 0;
  129. }