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.

127 lines
3.5 KiB

  1. // xfrmserv.cpp -- Implementation for the Transform Services class
  2. #include "stdafx.h"
  3. HRESULT CTransformServices::Create
  4. (IUnknown *punkOuter, IITFileSystem *pITSFS, ITransformServices **ppTransformServices)
  5. {
  6. CTransformServices *pTS = New CTransformServices(punkOuter);
  7. return FinishSetup(pTS? pTS->m_ImpITransformServices.Initial(pITSFS)
  8. : STG_E_INSUFFICIENTMEMORY,
  9. pTS, IID_ITransformServices, (PPVOID) ppTransformServices
  10. );
  11. }
  12. CTransformServices::CImpITransformServices::CImpITransformServices
  13. (CTransformServices *pBackObj, IUnknown *punkOuter)
  14. : IITTransformServices(pBackObj, punkOuter)
  15. {
  16. m_pITSFS = NULL;
  17. }
  18. CTransformServices::CImpITransformServices::~CImpITransformServices()
  19. {
  20. if (m_pITSFS)
  21. m_pITSFS->Release();
  22. }
  23. HRESULT CTransformServices::CImpITransformServices::Initial(IITFileSystem *pITSFS)
  24. {
  25. m_pITSFS = pITSFS;
  26. m_pITSFS->AddRef();
  27. return NO_ERROR;
  28. }
  29. // ITransformServices methods
  30. HRESULT STDMETHODCALLTYPE CTransformServices::CImpITransformServices::PerTransformStorage
  31. (REFCLSID rclsidXForm, IStorage **ppStg)
  32. {
  33. WCHAR awcsClassID[CWC_GUID_STRING_BUFFER];
  34. UINT cbResult = StringFromGUID2(rclsidXForm, awcsClassID, CWC_GUID_STRING_BUFFER);
  35. if (cbResult == 0)
  36. return STG_E_UNKNOWN;
  37. RonM_ASSERT(wcsLen(pwcsTransformStorage) + wcsLen(awcsClassID) + 1 < MAX_PATH);
  38. WCHAR awcsPath[MAX_PATH];
  39. wcsCpy(awcsPath, pwcsTransformStorage);
  40. wcsCat(awcsPath, awcsClassID);
  41. wcsCat(awcsPath, L"/");
  42. return m_pITSFS->CreateStorage(NULL, awcsPath, STGM_READWRITE, (IStorageITEx **) ppStg);
  43. }
  44. HRESULT STDMETHODCALLTYPE CTransformServices::CImpITransformServices::PerTransformInstanceStorage
  45. (REFCLSID rclsidXForm, const WCHAR *pwszDataSpace, IStorage **ppStg)
  46. {
  47. WCHAR awcsClassID[CWC_GUID_STRING_BUFFER];
  48. UINT cbResult = StringFromGUID2(rclsidXForm, awcsClassID, CWC_GUID_STRING_BUFFER);
  49. if (cbResult == 0)
  50. return STG_E_UNKNOWN;
  51. UINT cwc = wcsLen(pwcsSpaceNameStorage) + wcsLen(pwszDataSpace)
  52. + wcsLen(pwcsTransformSubStorage)
  53. + wcsLen(awcsClassID)
  54. + wcsLen(pwcsInstanceSubStorage);
  55. if (cwc >= MAX_PATH)
  56. return STG_E_INVALIDNAME;
  57. WCHAR awcsPath[MAX_PATH];
  58. wcsCpy(awcsPath, pwcsSpaceNameStorage);
  59. wcsCat(awcsPath, pwszDataSpace);
  60. wcsCat(awcsPath, pwcsTransformSubStorage);
  61. wcsCat(awcsPath, awcsClassID);
  62. wcsCat(awcsPath, pwcsInstanceSubStorage);
  63. HRESULT hr = m_pITSFS->OpenStorage(NULL, awcsPath, STGM_READWRITE, (IStorageITEx **) ppStg);
  64. if (hr == STG_E_FILENOTFOUND)
  65. hr = m_pITSFS->CreateStorage(NULL, awcsPath, STGM_READWRITE, (IStorageITEx **) ppStg);
  66. return hr;
  67. }
  68. HRESULT STDMETHODCALLTYPE CTransformServices::CImpITransformServices::SetKeys
  69. (REFCLSID rclsidXForm, const WCHAR *pwszDataSpace,
  70. PBYTE pbReadKey, UINT cbReadKey,
  71. PBYTE pbWriteKey, UINT cbWriteKey
  72. )
  73. {
  74. RonM_ASSERT(FALSE);
  75. return E_NOTIMPL;
  76. }
  77. HRESULT STDMETHODCALLTYPE CTransformServices::CImpITransformServices::CreateTemporaryStream
  78. (IStream **ppStrm)
  79. {
  80. ILockBytes *pLockBytes = NULL;
  81. HRESULT hr = CFSLockBytes::CreateTemp(NULL, &pLockBytes);
  82. if (SUCCEEDED(hr))
  83. {
  84. hr = CStream::OpenStream(NULL, pLockBytes, STGM_READWRITE, (IStreamITEx **) ppStrm);
  85. if (!SUCCEEDED(hr))
  86. pLockBytes->Release();
  87. }
  88. return hr;
  89. }