/[tivodecode]/tivocom/trunk/CTivoFile.cpp
ViewVC logotype

Contents of /tivocom/trunk/CTivoFile.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (show annotations) (download)
Wed Aug 29 06:53:05 2007 UTC (14 years, 4 months ago) by jeremyd2019
File size: 2301 byte(s)
squelch warnings

1 // CTivoFile.cpp : Implementation of CTivoFile
2
3 #include "stdafx.h"
4 #include "CTivoFile.h"
5 #include "CChunkCollection.h"
6
7 extern "C" {
8 int o_verbose = 0;
9 int fread_wrapper (void* mem, int size, void* fh)
10 {
11 return (int)fread(mem, 1, size, (FILE*)fh);
12 }
13 }
14
15
16 // CTivoFile
17
18 STDMETHODIMP CTivoFile::Init(const std::string & mak, BSTR filename)
19 {
20 try
21 {
22 USES_CONVERSION;
23 m_fname = OLE2CA(filename);
24 m_mak = mak;
25 _com_util::CheckError(AtlHresultFromWin32(fopen_s(&m_fh, m_fname.c_str(), "rb")));
26
27 if (read_tivo_header(m_fh, &m_fileheader, &fread_wrapper) < 0)
28 _com_raise_error(E_FAIL);
29
30 m_endoffileheader = ftell(m_fh);
31 }
32 catch (const _com_error & ex)
33 {
34 return ex.Error();
35 }
36
37 return S_OK;
38 }
39
40
41 STDMETHODIMP CTivoFile::get_filename(BSTR* pVal)
42 {
43 CComBSTR retval (m_fname.c_str());
44 return retval.CopyTo(pVal);
45 }
46
47 STDMETHODIMP CTivoFile::get_filetype(BSTR* pVal)
48 {
49 CComBSTR retval (4, m_fileheader.filetype);
50 return retval.CopyTo(pVal);
51 }
52
53 STDMETHODIMP CTivoFile::get_dummy_4(USHORT* pVal)
54 {
55 if (!pVal)
56 return E_POINTER;
57
58 *pVal = m_fileheader.dummy_0004;
59
60 return S_OK;
61 }
62
63 STDMETHODIMP CTivoFile::get_dummy_6(USHORT* pVal)
64 {
65 if (!pVal)
66 return E_POINTER;
67
68 *pVal = m_fileheader.dummy_0006;
69
70 return S_OK;
71 }
72
73 STDMETHODIMP CTivoFile::get_dummy_8(USHORT* pVal)
74 {
75 if (!pVal)
76 return E_POINTER;
77
78 *pVal = m_fileheader.dummy_0008;
79
80 return S_OK;
81 }
82
83 STDMETHODIMP CTivoFile::get_mpeg_offset(UINT* pVal)
84 {
85 if (!pVal)
86 return E_POINTER;
87
88 *pVal = m_fileheader.mpeg_offset;
89
90 return S_OK;
91 }
92
93 STDMETHODIMP CTivoFile::get_chunk_count(USHORT* pVal)
94 {
95 if (!pVal)
96 return E_POINTER;
97
98 *pVal = m_fileheader.chunks;
99
100 return S_OK;
101 }
102
103 STDMETHODIMP CTivoFile::get_chunks(IChunkCollection** pVal)
104 {
105 try
106 {
107 CComObject<CChunkCollection>* chunkColl = new CComObject<CChunkCollection> ();
108 CComPtr<IChunkCollection> ref (chunkColl);
109 _com_util::CheckError(chunkColl->Init(m_mak, m_fileheader.chunks, m_endoffileheader, this));
110 _com_util::CheckError(ref.CopyTo(pVal));
111 }
112 catch (const _com_error & ex)
113 {
114 return ex.Error();
115 }
116 return S_OK;
117 }
118
119 STDMETHODIMP CTivoFile::get_mak(BSTR* pVal)
120 {
121 CComBSTR mak (static_cast<int>(m_mak.size()), m_mak.data());
122 return mak.CopyTo(pVal);
123 }
124
125 STDMETHODIMP CTivoFile::put_mak(BSTR newVal)
126 {
127 USES_CONVERSION;
128 m_mak = OLE2CA(newVal);
129
130 return S_OK;
131 }

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13