1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Command sink interface implementation.
//
// $NoKeywords: $
//
//=============================================================================//
#include "cmdsink.h"
namespace CmdSink
{
// ------ implementation of CResponseFiles --------------
CResponseFiles::CResponseFiles( char const *szFileResult, char const *szFileListing ) :
m_fResult(NULL),
m_fListing(NULL),
m_lenResult(0),
m_dataResult(NULL),
m_dataListing(NULL)
{
sprintf( m_szFileResult, szFileResult );
sprintf( m_szFileListing, szFileListing );
}
CResponseFiles::~CResponseFiles( void )
{
if ( m_fResult )
fclose( m_fResult );
if ( m_fListing )
fclose( m_fListing );
}
bool CResponseFiles::Succeeded( void )
{
OpenResultFile();
return ( m_fResult != NULL );
}
size_t CResponseFiles::GetResultBufferLen( void )
{
ReadResultFile();
return m_lenResult;
}
const void * CResponseFiles::GetResultBuffer( void )
{
ReadResultFile();
return m_dataResult;
}
const char * CResponseFiles::GetListing( void )
{
ReadListingFile();
return ( ( m_dataListing && *m_dataListing ) ? m_dataListing : NULL );
}
void CResponseFiles::OpenResultFile( void )
{
if ( !m_fResult )
{
m_fResult = fopen( m_szFileResult, "rb" );
}
}
void CResponseFiles::ReadResultFile( void )
{
if ( !m_dataResult )
{
OpenResultFile();
if ( m_fResult )
{
fseek( m_fResult, 0, SEEK_END );
m_lenResult = (size_t) ftell( m_fResult );
if ( m_lenResult != size_t(-1) )
{
m_bufResult.EnsureCapacity( m_lenResult );
fseek( m_fResult, 0, SEEK_SET );
fread( m_bufResult.Base(), 1, m_lenResult, m_fResult );
m_dataResult = m_bufResult.Base();
}
}
}
}
void CResponseFiles::ReadListingFile( void )
{
if ( !m_dataListing )
{
if ( !m_fListing )
m_fListing = fopen( m_szFileListing, "rb" );
if ( m_fListing )
{
fseek( m_fListing, 0, SEEK_END );
size_t len = (size_t) ftell( m_fListing );
if ( len != size_t(-1) )
{
m_bufListing.EnsureCapacity( len );
fseek( m_fListing, 0, SEEK_SET );
fread( m_bufListing.Base(), 1, len, m_fListing );
m_dataListing = (const char *) m_bufListing.Base();
}
}
}
}
}; // namespace CmdSink
|