Team Fortress 2 Source Code as on 22/4/2020
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.

115 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include <io.h>
  9. #include <stdio.h>
  10. #include <windows.h>
  11. #include "vmtcheck_util.h"
  12. #include "tier0/dbg.h"
  13. extern bool uselogfile;
  14. //-----------------------------------------------------------------------------
  15. // Purpose:
  16. // Input : depth -
  17. // *fmt -
  18. // ... -
  19. //-----------------------------------------------------------------------------
  20. void vprint( int depth, const char *fmt, ... )
  21. {
  22. char string[ 8192 ];
  23. va_list va;
  24. va_start( va, fmt );
  25. vsprintf( string, fmt, va );
  26. va_end( va );
  27. FILE *fp = NULL;
  28. if ( uselogfile )
  29. {
  30. fp = fopen( "log.txt", "ab" );
  31. }
  32. while ( depth-- > 0 )
  33. {
  34. printf( " " );
  35. OutputDebugString( " " );
  36. if ( fp )
  37. {
  38. fprintf( fp, " " );
  39. }
  40. }
  41. ::printf( "%s", string );
  42. OutputDebugString( string );
  43. if ( fp )
  44. {
  45. char *p = string;
  46. while ( *p )
  47. {
  48. if ( *p == '\n' )
  49. {
  50. fputc( '\r', fp );
  51. }
  52. fputc( *p, fp );
  53. p++;
  54. }
  55. fclose( fp );
  56. }
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. // Input : *name -
  61. // *len -
  62. // Output : unsigned char
  63. //-----------------------------------------------------------------------------
  64. unsigned char *COM_LoadFile( const char *name, int *len)
  65. {
  66. FILE *fp;
  67. fp = fopen( name, "rb" );
  68. if ( !fp )
  69. {
  70. *len = 0;
  71. return NULL;
  72. }
  73. fseek( fp, 0, SEEK_END );
  74. *len = ftell( fp );
  75. fseek( fp, 0, SEEK_SET );
  76. unsigned char *buffer = new unsigned char[ *len + 1 ];
  77. fread( buffer, *len, 1, fp );
  78. fclose( fp );
  79. buffer[ *len ] = 0;
  80. return buffer;
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. // Input : *buffer -
  85. //-----------------------------------------------------------------------------
  86. void COM_FreeFile( unsigned char *buffer )
  87. {
  88. delete[] buffer;
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. // Input : *dir -
  93. // Output : Returns true on success, false on failure.
  94. //-----------------------------------------------------------------------------
  95. bool COM_DirectoryExists( const char *dir )
  96. {
  97. if ( !_access( dir, 0 ) )
  98. return true;
  99. return false;
  100. }