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.

62 lines
1.8 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "closedcaptions.h"
  7. #include "filesystem.h"
  8. #include "tier1/utlbuffer.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // Assumed to be set up by calling code
  12. bool AsyncCaption_t::LoadFromFile( char const *pchFullPath )
  13. {
  14. FileHandle_t fh = g_pFullFileSystem->Open( pchFullPath, "rb" );
  15. if ( FILESYSTEM_INVALID_HANDLE == fh )
  16. return false;
  17. MEM_ALLOC_CREDIT();
  18. CUtlBuffer dirbuffer;
  19. // Read the header
  20. g_pFullFileSystem->Read( &m_Header, sizeof( m_Header ), fh );
  21. if ( m_Header.magic != COMPILED_CAPTION_FILEID )
  22. {
  23. if( IsPS3() )
  24. return false;
  25. else
  26. Error( "Invalid file id for %s\n", pchFullPath );
  27. }
  28. if ( m_Header.version != COMPILED_CAPTION_VERSION )
  29. {
  30. if( IsPS3() )
  31. return false;
  32. else
  33. Error( "Invalid file version for %s\n", pchFullPath );
  34. }
  35. if ( m_Header.directorysize < 0 || m_Header.directorysize > 64 * 1024 )
  36. {
  37. if( IsPS3() )
  38. return false;
  39. else
  40. Error( "Invalid directory size %d for %s\n", m_Header.directorysize, pchFullPath );
  41. }
  42. //if ( m_Header.blocksize != MAX_BLOCK_SIZE )
  43. // Error( "Invalid block size %d, expecting %d for %s\n", m_Header.blocksize, MAX_BLOCK_SIZE, pchFullPath );
  44. int directoryBytes = m_Header.directorysize * sizeof( CaptionLookup_t );
  45. m_CaptionDirectory.EnsureCapacity( m_Header.directorysize );
  46. dirbuffer.EnsureCapacity( directoryBytes );
  47. g_pFullFileSystem->Read( dirbuffer.Base(), directoryBytes, fh );
  48. g_pFullFileSystem->Close( fh );
  49. m_CaptionDirectory.CopyArray( (const CaptionLookup_t *)dirbuffer.PeekGet(), m_Header.directorysize );
  50. m_CaptionDirectory.RedoSort( true );
  51. m_DataBaseFile = pchFullPath;
  52. return true;
  53. }