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.

73 lines
2.4 KiB

  1. //===== Copyright c 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "resourcefile/resourcedictionary.h"
  8. #include "tier1/generichash.h"
  9. #include "tier0/dbg.h"
  10. #include "tier2/fileutils.h"
  11. // Must be last
  12. #include "tier0/memdbgon.h"
  13. #define RESOURCE_ID_HASH_SEED 0xEDABCDEF
  14. //-----------------------------------------------------------------------------
  15. // Computes a resource id given a resource name
  16. //-----------------------------------------------------------------------------
  17. ResourceId_t ComputeResourceIdHash( const char *pResourceName )
  18. {
  19. if ( !pResourceName || !pResourceName[0] )
  20. return RESOURCE_ID_INVALID;
  21. int nLength = Q_strlen( pResourceName );
  22. return (ResourceId_t)MurmurHash2( pResourceName, nLength, RESOURCE_ID_HASH_SEED );
  23. }
  24. void GenerateResourceFileName( const char *pFileName, char *pResourceFileName, size_t nBufLen )
  25. {
  26. char pContentName[MAX_PATH];
  27. char pContentNameNoExt[MAX_PATH];
  28. char pFixedContentName[MAX_PATH];
  29. if ( Q_IsAbsolutePath( pFileName ) )
  30. {
  31. ComputeModContentFilename( pFileName, pContentName, sizeof(pContentName) );
  32. Q_StripExtension( pContentName, pContentNameNoExt, sizeof(pContentNameNoExt) );
  33. Q_FixupPathName( pFixedContentName, sizeof(pFixedContentName), pContentNameNoExt );
  34. g_pFullFileSystem->FullPathToRelativePathEx( pFixedContentName, "CONTENT", pResourceFileName, nBufLen );
  35. }
  36. else
  37. {
  38. Q_StripExtension( pFileName, pContentNameNoExt, sizeof(pContentNameNoExt) );
  39. Q_FixupPathName( pResourceFileName, nBufLen, pContentNameNoExt );
  40. }
  41. }
  42. void GenerateResourceName( const char *pFileName, const char *pSubResourceName, char *pResourceName, size_t pBufLen )
  43. {
  44. if ( !pSubResourceName )
  45. {
  46. pSubResourceName = "";
  47. }
  48. char pFixedFileName[MAX_PATH];
  49. char pFixedSubResourceName[MAX_PATH];
  50. GenerateResourceFileName( pFileName, pFixedFileName, sizeof(pFixedFileName) );
  51. Q_strncpy( pFixedSubResourceName, pSubResourceName, sizeof(pFixedSubResourceName) );
  52. Q_strlower( pFixedSubResourceName );
  53. Q_snprintf( pResourceName, pBufLen, "%s::%s", pFixedFileName, pFixedSubResourceName );
  54. }
  55. ResourceId_t ComputeResourceIdHash( const char *pFileName, const char *pSubResourceName )
  56. {
  57. if ( !pFileName || !pFileName[0] )
  58. return RESOURCE_ID_INVALID;
  59. char pTemp[MAX_PATH+128];
  60. GenerateResourceName( pFileName, pSubResourceName, pTemp, sizeof(pTemp) );
  61. return ComputeResourceIdHash( pTemp );
  62. }