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.

171 lines
4.8 KiB

  1. #include <fusenetincludes.h>
  2. #include <assemblyfile.h>
  3. // ---------------------------------------------------------------------------
  4. // CreateAssemblyFile
  5. // ---------------------------------------------------------------------------
  6. STDAPI
  7. CreateAssemblyFileInfo(
  8. LPASSEMBLY_FILE_INFO *ppAssemblyFile)
  9. {
  10. HRESULT hr = S_OK;
  11. CAssemblyFileInfo *pAssemblyFile = NULL;
  12. pAssemblyFile = new(CAssemblyFileInfo);
  13. if (!pAssemblyFile)
  14. {
  15. hr = E_OUTOFMEMORY;
  16. goto exit;
  17. }
  18. exit:
  19. *ppAssemblyFile = static_cast<IAssemblyFileInfo*> (pAssemblyFile);
  20. return hr;
  21. }
  22. // ---------------------------------------------------------------------------
  23. // IsEqualAssemblyFileInfo
  24. // ---------------------------------------------------------------------------
  25. BOOL
  26. IsEqualAssemblyFileInfo(LPASSEMBLY_FILE_INFO pAsmFileInfo1, LPASSEMBLY_FILE_INFO pAsmFileInfo2)
  27. {
  28. return (*(static_cast<CAssemblyFileInfo*> (pAsmFileInfo1))
  29. == *(static_cast<CAssemblyFileInfo*> (pAsmFileInfo2)));
  30. }
  31. // ---------------------------------------------------------------------------
  32. // ctor
  33. // ---------------------------------------------------------------------------
  34. CAssemblyFileInfo::CAssemblyFileInfo()
  35. : _dwSig('ELIF'), _cRef(1), _hr(S_OK)
  36. {
  37. memset(_fi, 0, sizeof(_fi));
  38. }
  39. // ---------------------------------------------------------------------------
  40. // dtor
  41. // ---------------------------------------------------------------------------
  42. CAssemblyFileInfo::~CAssemblyFileInfo()
  43. {
  44. for (DWORD i = ASM_FILE_NAME; i < ASM_FILE_MAX; i++)
  45. SAFEDELETEARRAY(_fi[i].pwzProperty);
  46. }
  47. // ---------------------------------------------------------------------------
  48. // operator==
  49. // ---------------------------------------------------------------------------
  50. BOOL
  51. CAssemblyFileInfo::operator==( CAssemblyFileInfo& asmFIRHS )
  52. {
  53. BOOL bEqual = TRUE;
  54. for (DWORD i = ASM_FILE_NAME; i < ASM_FILE_MAX; i++)
  55. {
  56. // BUGBUG?: case sensitivity and issues?
  57. // BUGBUG?: locale?
  58. if (((_fi[i].pwzProperty) && !((asmFIRHS._fi[i]).pwzProperty)) ||
  59. (!(_fi[i].pwzProperty) && ((asmFIRHS._fi[i]).pwzProperty)) ||
  60. ((_fi[i].pwzProperty)
  61. && wcscmp(_fi[i].pwzProperty, (asmFIRHS._fi[i]).pwzProperty) != 0))
  62. {
  63. bEqual = FALSE;
  64. break;
  65. }
  66. }
  67. return bEqual;
  68. }
  69. // ---------------------------------------------------------------------------
  70. // Set
  71. // ---------------------------------------------------------------------------
  72. HRESULT CAssemblyFileInfo::Set(DWORD dwId, LPCOLESTR pwzProperty)
  73. {
  74. DWORD ccProperty = lstrlen(pwzProperty) + 1;
  75. LPWSTR pwzTmp = new WCHAR[ccProperty];
  76. if (!pwzTmp)
  77. {
  78. _hr = E_OUTOFMEMORY;
  79. goto exit;
  80. }
  81. memcpy(pwzTmp, pwzProperty, ccProperty * sizeof(WCHAR));
  82. SAFEDELETEARRAY(_fi[dwId].pwzProperty);
  83. _fi[dwId].pwzProperty = pwzTmp;
  84. _fi[dwId].ccProperty = ccProperty;
  85. exit:
  86. return _hr;
  87. }
  88. // ---------------------------------------------------------------------------
  89. // Get
  90. // ---------------------------------------------------------------------------
  91. HRESULT CAssemblyFileInfo::Get(DWORD dwId, LPOLESTR *ppwzProperty, LPDWORD pccProperty)
  92. {
  93. *ppwzProperty = NULL;
  94. *pccProperty = 0;
  95. DWORD ccProperty = _fi[dwId].ccProperty ? _fi[dwId].ccProperty : 1;
  96. LPWSTR pwzProperty = new WCHAR[ccProperty];
  97. if (!pwzProperty)
  98. {
  99. _hr = E_OUTOFMEMORY;
  100. goto exit;
  101. }
  102. memcpy(pwzProperty, _fi[dwId].pwzProperty, ccProperty * sizeof(WCHAR));
  103. *ppwzProperty = pwzProperty;
  104. *pccProperty = ccProperty;
  105. exit:
  106. return _hr;
  107. }
  108. // IUnknown Boilerplate
  109. // ---------------------------------------------------------------------------
  110. // CAssemblyFileInfo::QI
  111. // ---------------------------------------------------------------------------
  112. STDMETHODIMP
  113. CAssemblyFileInfo::QueryInterface(REFIID riid, void** ppvObj)
  114. {
  115. if ( IsEqualIID(riid, IID_IUnknown)
  116. || IsEqualIID(riid, IID_IAssemblyFileInfo)
  117. )
  118. {
  119. *ppvObj = static_cast<IAssemblyFileInfo*> (this);
  120. AddRef();
  121. return S_OK;
  122. }
  123. else
  124. {
  125. *ppvObj = NULL;
  126. return E_NOINTERFACE;
  127. }
  128. }
  129. // ---------------------------------------------------------------------------
  130. // CAssemblyFileInfo::AddRef
  131. // ---------------------------------------------------------------------------
  132. STDMETHODIMP_(ULONG)
  133. CAssemblyFileInfo::AddRef()
  134. {
  135. return InterlockedIncrement ((LONG*) &_cRef);
  136. }
  137. // ---------------------------------------------------------------------------
  138. // CAssemblyFileInfo::Release
  139. // ---------------------------------------------------------------------------
  140. STDMETHODIMP_(ULONG)
  141. CAssemblyFileInfo::Release()
  142. {
  143. ULONG lRet = InterlockedDecrement ((LONG*) &_cRef);
  144. if (!lRet)
  145. delete this;
  146. return lRet;
  147. }