1 /////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000 John Adcock. All rights reserved.
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or (at your
8 // option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 // License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public License
16 // along with this library; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 // The id3lib authors encourage improvements and optimisations to be sent to
20 // the id3lib coordinator. Please see the README file for details on where to
21 // send such submissions. See the AUTHORS file for a list of people who have
22 // contributed to id3lib. See the ChangeLog file for a list of changes to
23 // id3lib. These files are distributed with id3lib at
24 // http://download.sourceforge.net/id3lib/
25 //
26 /////////////////////////////////////////////////////////////////////////////
27 // ID3Field.cpp : Implementation of CID3Field
28 /////////////////////////////////////////////////////////////////////////////
29 // Change Log
30 //
31 // Date Developer Changes
32 //
33 // 05 Jan 2000 John Adcock Original Release
34 // 26 Apr 2000 John Adcock Got working with id3lib 3.7.3
35 // 18 Aug 2000 Philip Oldaker Added Picture Functionality
36 //
37 /////////////////////////////////////////////////////////////////////////////
38
39 #include "stdafx.h"
40 #include "ID3COM.h"
41 #include "ID3Field.h"
42 #include "ID3Frame.h"
43
44 /////////////////////////////////////////////////////////////////////////////
45 // CID3Field
46
CID3Field()47 CID3Field::CID3Field()
48 {
49 m_Field = NULL;
50 m_FrameParent = NULL;
51 }
52
~CID3Field()53 CID3Field::~CID3Field()
54 {
55 if(m_FrameParent != NULL)
56 {
57 m_FrameParent->Release();
58 }
59 m_Field = NULL;
60 }
61
CreateObject(IID3ComFrame * FrameParent,ID3_Field * Field)62 IID3ComField* CID3Field::CreateObject(IID3ComFrame* FrameParent, ID3_Field* Field)
63 {
64 CComObject<CID3Field>* pRetVal = new CComObject<CID3Field>;
65 pRetVal->m_Field = Field;
66 pRetVal->m_FrameParent = FrameParent;
67 FrameParent->AddRef();
68 return (IID3ComField*)pRetVal;
69 }
70
InterfaceSupportsErrorInfo(REFIID riid)71 STDMETHODIMP CID3Field::InterfaceSupportsErrorInfo(REFIID riid)
72 {
73 static const IID* arr[] =
74 {
75 &IID_IID3ComField
76 };
77 for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
78 {
79 if (InlineIsEqualGUID(*arr[i],riid))
80 return S_OK;
81 }
82 return S_FALSE;
83 }
84
get_Text(long ItemNum,BSTR * pVal)85 STDMETHODIMP CID3Field::get_Text(long ItemNum, BSTR *pVal)
86 {
87 USES_CONVERSION;
88 luint TryChars = 0;
89 luint GotChars = 0;
90 try
91 {
92 *pVal = NULL;
93 size_t nText = m_Field->Size();
94 if(m_Field->GetEncoding() == ID3TE_UNICODE)
95 {
96 unicode_t* sText = new unicode_t[nText + 1];
97 try
98 {
99 m_Field->Get(sText, nText, ItemNum - 1);
100 sText[nText] = '\0';
101 *pVal = SysAllocString(sText);
102 }
103 catch (...)
104 {
105 *pVal = NULL;
106 }
107 delete [] sText;
108 }
109 else
110 {
111 char* sText = new char[nText + 1];
112 try
113 {
114 m_Field->Get(sText, nText, ItemNum - 1);
115 sText[nText] = '\0';
116 *pVal = SysAllocString(A2W(sText));
117 }
118 catch (...)
119 {
120 *pVal = NULL;
121 }
122 delete [] sText;
123 }
124 return S_OK;
125 }
126 catch (...)
127 {
128 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
129 }
130 }
131
put_Text(long ItemNum,BSTR newVal)132 STDMETHODIMP CID3Field::put_Text(long ItemNum, BSTR newVal)
133 {
134 try
135 {
136 m_Field->Set(newVal);
137 return S_OK;
138 }
139 catch (...)
140 {
141 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
142 }
143 }
144
get_Long(long * pVal)145 STDMETHODIMP CID3Field::get_Long(long *pVal)
146 {
147 try
148 {
149 *pVal = m_Field->Get();
150 return S_OK;
151 }
152 catch (...)
153 {
154 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
155 }
156 }
157
put_Long(long newVal)158 STDMETHODIMP CID3Field::put_Long(long newVal)
159 {
160 try
161 {
162 m_Field->Set(newVal);
163 return S_OK;
164 }
165 catch (...)
166 {
167 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
168 }
169 }
170
Clear()171 STDMETHODIMP CID3Field::Clear()
172 {
173 try
174 {
175 m_Field->Clear();
176 return S_OK;
177 }
178 catch (...)
179 {
180 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
181 }
182 }
183
CopyDataToFile(BSTR FileName)184 STDMETHODIMP CID3Field::CopyDataToFile(BSTR FileName)
185 {
186 USES_CONVERSION;
187 try
188 {
189 m_Field->ToFile(OLE2A(FileName));
190 return S_OK;
191 }
192 catch (...)
193 {
194 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
195 }
196 }
197
CopyDataFromFile(BSTR FileName)198 STDMETHODIMP CID3Field::CopyDataFromFile(BSTR FileName)
199 {
200 USES_CONVERSION;
201 try
202 {
203 m_Field->FromFile(OLE2A(FileName));
204 return S_OK;
205 }
206 catch (...)
207 {
208 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
209 }
210 }
211
get_NumTextItems(long * pVal)212 STDMETHODIMP CID3Field::get_NumTextItems(long *pVal)
213 {
214 try
215 {
216 *pVal = m_Field->GetNumTextItems();
217 return S_OK;
218 }
219 catch (...)
220 {
221 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
222 }
223 }
224
get_Binary(BSTR * pVal)225 STDMETHODIMP CID3Field::get_Binary(BSTR *pVal)
226 {
227 // TODO: Add your implementation code here
228 if (pVal == NULL)
229 return E_POINTER;
230 try
231 {
232 *pVal = NULL;
233 const uchar *pData = m_Field->GetRawBinary();
234 if (pData == NULL)
235 return E_FAIL;
236 ID3_Frame *pFrame = ((CID3Frame*)m_FrameParent)->GetID3Frame();
237 if (pFrame->GetID() == ID3FID_PICTURE)
238 {
239 *pVal = _bstr_t((LPCTSTR)pData).copy();
240 }
241 else
242 {
243 *pVal = SysAllocStringByteLen((const char *)pData,m_Field->Size());
244 }
245 }
246 catch (...)
247 {
248 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
249 }
250 return S_OK;
251 }
252
put_Binary(BSTR newVal)253 STDMETHODIMP CID3Field::put_Binary(BSTR newVal)
254 {
255 // TODO: Add your implementation code here
256 try
257 {
258 size_t Size = SysStringByteLen(newVal);
259 m_Field->Set((const uchar *)newVal,Size);
260 }
261 catch (...)
262 {
263 return Error(IDS_UNEXPECTED_ERROR, IID_IID3ComField, E_UNEXPECTED);
264 }
265 return S_OK;
266 }
267 ///////////////////////////////////////////////////////
268 // End Added Philip Oldaker 12-Aug 2000
269 ///////////////////////////////////////////////////////
270
271