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.

94 lines
2.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "tier2/riff.h"
  9. #include "snd_io.h"
  10. #include "filesystem.h"
  11. #include "filesystem_engine.h"
  12. #include "tier1/strtools.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Implements Audio IO on the engine's COMMON filesystem
  17. //-----------------------------------------------------------------------------
  18. class COM_IOReadBinary : public IFileReadBinary
  19. {
  20. public:
  21. FileHandle_t open( const char *pFileName );
  22. int read( void *pOutput, int size, FileHandle_t file );
  23. void seek( FileHandle_t file, int pos );
  24. unsigned int tell( FileHandle_t file );
  25. unsigned int size( FileHandle_t file );
  26. void close( FileHandle_t file );
  27. };
  28. // prepend sound/ to the filename -- all sounds are loaded from the sound/ directory
  29. FileHandle_t COM_IOReadBinary::open( const char *pFileName )
  30. {
  31. char namebuffer[512];
  32. FileHandle_t hFile;
  33. Q_strncpy( namebuffer, "sound", sizeof( namebuffer ) );
  34. // the server is sending back sound names with slashes in front...
  35. if ( pFileName[0] != '/' && pFileName[0] != '\\' )
  36. {
  37. Q_strncat( namebuffer, "/", sizeof( namebuffer ), COPY_ALL_CHARACTERS );
  38. }
  39. Q_strncat( namebuffer, pFileName, sizeof( namebuffer ), COPY_ALL_CHARACTERS );
  40. hFile = g_pFileSystem->Open( namebuffer, "rb", "GAME" );
  41. return hFile;
  42. }
  43. int COM_IOReadBinary::read( void *pOutput, int size, FileHandle_t file )
  44. {
  45. if ( !file )
  46. return 0;
  47. return g_pFileSystem->Read( pOutput, size, file );
  48. }
  49. void COM_IOReadBinary::seek( FileHandle_t file, int pos )
  50. {
  51. if ( !file )
  52. return;
  53. g_pFileSystem->Seek( file, pos, FILESYSTEM_SEEK_HEAD );
  54. }
  55. unsigned int COM_IOReadBinary::tell( FileHandle_t file )
  56. {
  57. if ( !file )
  58. return 0;
  59. return g_pFileSystem->Tell( file );
  60. }
  61. unsigned int COM_IOReadBinary::size( FileHandle_t file )
  62. {
  63. if (!file)
  64. return 0;
  65. return g_pFileSystem->Size( file );
  66. }
  67. void COM_IOReadBinary::close( FileHandle_t file )
  68. {
  69. if (!file)
  70. return;
  71. g_pFileSystem->Close( file );
  72. }
  73. static COM_IOReadBinary io;
  74. IFileReadBinary *g_pSndIO = &io;