Counter Strike : Global Offensive Source Code
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.

114 lines
2.2 KiB

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