diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-04-03 17:22:25 +0300 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-04-03 17:22:39 +0300 |
commit | 52d9d76c503fcea5e4a1431127fe2f916ba830db (patch) | |
tree | 08a88a0acf188e3eb1f866e8b0397d61dcd34aea /common | |
parent | 8690f88e88e429718ece59850f6504d616031059 (diff) |
Export coverart and attachments through IDSMResourceBag
Based on a patch by Underground78 <underground78@users.sourceforge.net>
Diffstat (limited to 'common')
-rw-r--r-- | common/DSUtilLite/DSMResourceBag.cpp | 148 | ||||
-rw-r--r-- | common/DSUtilLite/DSMResourceBag.h | 40 | ||||
-rw-r--r-- | common/DSUtilLite/DSUtilLite.vcxproj | 2 | ||||
-rw-r--r-- | common/DSUtilLite/DSUtilLite.vcxproj.filters | 6 | ||||
-rw-r--r-- | common/includes/IDSMResourceBag.h | 31 |
5 files changed, 227 insertions, 0 deletions
diff --git a/common/DSUtilLite/DSMResourceBag.cpp b/common/DSUtilLite/DSMResourceBag.cpp new file mode 100644 index 00000000..d57d9a0c --- /dev/null +++ b/common/DSUtilLite/DSMResourceBag.cpp @@ -0,0 +1,148 @@ +#include "stdafx.h" +#include "DSMResourceBag.h" + + +CDSMResource::CDSMResource() + : mime(L"application/octet-stream") +{ +} + +CDSMResource::CDSMResource(LPCWSTR name, LPCWSTR desc, LPCWSTR mime, BYTE* pData, int len, DWORD_PTR tag) +{ + this->name = name; + this->desc = desc; + this->mime = mime; + data.resize(len); + memcpy(data.data(), pData, data.size()); + this->tag = tag; +} + +CDSMResource& CDSMResource::operator=(const CDSMResource& r) +{ + if (this != &r) { + name = r.name; + desc = r.desc; + mime = r.mime; + data = r.data; + tag = r.tag; + } + return *this; +} + +CDSMResourceBag::CDSMResourceBag() +{ +} + + +CDSMResourceBag::~CDSMResourceBag() +{ + m_resources.clear(); +} + +STDMETHODIMP_(DWORD) CDSMResourceBag::ResGetCount() +{ + CAutoLock lock(&m_csResources); + return m_resources.size(); +} + +STDMETHODIMP CDSMResourceBag::ResGet(DWORD iIndex, BSTR * ppName, BSTR * ppDesc, BSTR * ppMime, BYTE** ppData, DWORD * pDataLen, DWORD_PTR * pTag) +{ + CAutoLock lock(&m_csResources); + + if (ppData && !pDataLen) + return E_INVALIDARG; + + if (iIndex >= m_resources.size()) + return E_INVALIDARG; + + CDSMResource& r = m_resources[iIndex]; + + if (ppName) { + *ppName = SysAllocString(r.name.data()); + if (*ppName == NULL) + return E_OUTOFMEMORY; + } + if (ppDesc) { + *ppDesc = SysAllocString(r.desc.data()); + if (*ppDesc == NULL) + return E_OUTOFMEMORY; + } + if (ppMime) { + *ppMime = SysAllocString(r.mime.data()); + if (*ppMime == NULL) + return E_OUTOFMEMORY; + } + if (ppData) { + *pDataLen = (DWORD)r.data.size(); + memcpy(*ppData = (BYTE*)CoTaskMemAlloc(*pDataLen), r.data.data(), *pDataLen); + } + if (pTag) { + *pTag = r.tag; + } + + return S_OK; +} + +STDMETHODIMP CDSMResourceBag::ResSet(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, const BYTE * pData, DWORD len, DWORD_PTR tag) +{ + CAutoLock lock(&m_csResources); + + if (iIndex >= m_resources.size()) + return E_INVALIDARG; + + CDSMResource& r = m_resources[iIndex]; + + if (pName) + r.name = pName; + + if (pDesc) + r.desc = pDesc; + + if (pMime) + r.mime = pMime; + + if (pData || len == 0) { + r.data.resize(len); + if (pData) { + memcpy(r.data.data(), pData, r.data.size()); + } + } + + r.tag = tag; + + return S_OK; +} + +STDMETHODIMP CDSMResourceBag::ResAppend(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE * pData, DWORD len, DWORD_PTR tag) +{ + CAutoLock lock(&m_csResources); + m_resources.push_back(CDSMResource()); + return ResSet((DWORD)m_resources.size() - 1, pName, pDesc, pMime, pData, len, tag); +} + +STDMETHODIMP CDSMResourceBag::ResRemoveAt(DWORD iIndex) +{ + CAutoLock lock(&m_csResources); + + if (iIndex >= m_resources.size()) + return E_INVALIDARG; + + m_resources.erase(m_resources.cbegin() + iIndex); + + return S_OK; +} + +STDMETHODIMP CDSMResourceBag::ResRemoveAll(DWORD_PTR tag) +{ + if (tag) { + for (auto crit = m_resources.cend() - 1; crit >= m_resources.begin(); --crit) { + if (crit->tag == tag) { + m_resources.erase(crit); + } + } + } else { + m_resources.clear(); + } + + return S_OK; +} diff --git a/common/DSUtilLite/DSMResourceBag.h b/common/DSUtilLite/DSMResourceBag.h new file mode 100644 index 00000000..cf4a1dcd --- /dev/null +++ b/common/DSUtilLite/DSMResourceBag.h @@ -0,0 +1,40 @@ +#pragma once + +#include "IDSMResourceBag.h" + +#include <string> +#include <vector> +#include <map> + +class CDSMResource +{ +public: + CDSMResource(); + CDSMResource(LPCWSTR name, LPCWSTR desc, LPCWSTR mime, BYTE* pData, int len, DWORD_PTR tag = 0); + + CDSMResource& operator=(const CDSMResource& r); + +public: + DWORD_PTR tag; + std::wstring name, desc, mime; + std::vector<BYTE> data; +}; + +class CDSMResourceBag : public IDSMResourceBag +{ +public: + CDSMResourceBag(); + virtual ~CDSMResourceBag(); + + // IDSMResourceBag + STDMETHODIMP_(DWORD) ResGetCount(); + STDMETHODIMP ResGet(DWORD iIndex, BSTR * ppName, BSTR * ppDesc, BSTR * ppMime, BYTE** ppData, DWORD * pDataLen, DWORD_PTR * pTag = nullptr); + STDMETHODIMP ResSet(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, const BYTE * pData, DWORD len, DWORD_PTR tag = 0); + STDMETHODIMP ResAppend(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE * pData, DWORD len, DWORD_PTR tag = 0); + STDMETHODIMP ResRemoveAt(DWORD iIndex); + STDMETHODIMP ResRemoveAll(DWORD_PTR tag = 0); + +private: + CCritSec m_csResources; + std::vector<CDSMResource> m_resources; +}; diff --git a/common/DSUtilLite/DSUtilLite.vcxproj b/common/DSUtilLite/DSUtilLite.vcxproj index b34e0af4..37a89aff 100644 --- a/common/DSUtilLite/DSUtilLite.vcxproj +++ b/common/DSUtilLite/DSUtilLite.vcxproj @@ -77,6 +77,7 @@ <ItemGroup> <ClInclude Include="BaseDSPropPage.h" /> <ClInclude Include="CueSheet.h" /> + <ClInclude Include="DSMResourceBag.h" /> <ClInclude Include="PopupMenu.h" /> <ClInclude Include="BaseTrayIcon.h" /> <ClInclude Include="ByteParser.h" /> @@ -99,6 +100,7 @@ <ItemGroup> <ClCompile Include="BaseDSPropPage.cpp" /> <ClCompile Include="CueSheet.cpp" /> + <ClCompile Include="DSMResourceBag.cpp" /> <ClCompile Include="PopupMenu.cpp" /> <ClCompile Include="BaseTrayIcon.cpp" /> <ClCompile Include="ByteParser.cpp" /> diff --git a/common/DSUtilLite/DSUtilLite.vcxproj.filters b/common/DSUtilLite/DSUtilLite.vcxproj.filters index 3a896110..f3d369eb 100644 --- a/common/DSUtilLite/DSUtilLite.vcxproj.filters +++ b/common/DSUtilLite/DSUtilLite.vcxproj.filters @@ -81,6 +81,9 @@ <ClInclude Include="timer.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="DSMResourceBag.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="stdafx.cpp"> @@ -128,5 +131,8 @@ <ClCompile Include="CueSheet.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="DSMResourceBag.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/common/includes/IDSMResourceBag.h b/common/includes/IDSMResourceBag.h new file mode 100644 index 00000000..21492007 --- /dev/null +++ b/common/includes/IDSMResourceBag.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2003-2006 Gabest + * Copyright (C) 2010-2015 Hendrik Leppkes + * http://www.1f0.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#pragma once + +interface __declspec(uuid("EBAFBCBE-BDE0-489A-9789-05D5692E3A93")) +IDSMResourceBag : +public IUnknown { + STDMETHOD_(DWORD, ResGetCount)() PURE; + STDMETHOD(ResGet)(DWORD iIndex, BSTR * ppName, BSTR * ppDesc, BSTR * ppMime, BYTE** ppData, DWORD * pDataLen, DWORD_PTR * pTag) PURE; + STDMETHOD(ResSet)(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, const BYTE * pData, DWORD len, DWORD_PTR tag) PURE; + STDMETHOD(ResAppend)(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE * pData, DWORD len, DWORD_PTR tag) PURE; + STDMETHOD(ResRemoveAt)(DWORD iIndex) PURE; + STDMETHOD(ResRemoveAll)(DWORD_PTR tag) PURE; +}; |