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.

93 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // winutils.cpp
  4. //
  5. //===========================================================================//
  6. #include "winutils.h"
  7. #ifndef _WIN32
  8. #include "appframework/ilaunchermgr.h"
  9. // LINUX path taken from //Steam/main/src/tier0/platform_posix.cpp - Returns installed RAM in MB.
  10. static unsigned long GetInstalledRAM()
  11. {
  12. unsigned long ulTotalRamMB = 2047;
  13. #ifdef LINUX
  14. char rgchLine[256];
  15. FILE *fpMemInfo = fopen( "/proc/meminfo", "r" );
  16. if ( !fpMemInfo )
  17. return ulTotalRamMB;
  18. const char *pszSearchString = "MemTotal:";
  19. const uint cchSearchString = strlen( pszSearchString );
  20. while ( fgets( rgchLine, sizeof(rgchLine), fpMemInfo ) )
  21. {
  22. if ( !strncasecmp( pszSearchString, rgchLine, cchSearchString ) )
  23. {
  24. char *pszVal = rgchLine+cchSearchString;
  25. while( isspace(*pszVal) )
  26. ++pszVal;
  27. ulTotalRamMB = atol( pszVal ) / 1024; // go from kB to MB
  28. break;
  29. }
  30. }
  31. fclose( fpMemInfo );
  32. #endif
  33. // 128 Gb limit for now (should future proof us for a while)
  34. ulTotalRamMB = MIN( ulTotalRamMB, 1024 * 128 );
  35. return ulTotalRamMB;
  36. }
  37. void GlobalMemoryStatus( MEMORYSTATUS *pOut )
  38. {
  39. unsigned long nInstalledRamInMB = GetInstalledRAM();
  40. // For safety assume at least 128MB
  41. nInstalledRamInMB = MAX( nInstalledRamInMB, 128 );
  42. uint64 ulTotalRam = static_cast<uint64>( nInstalledRamInMB ) * ( 1024 * 1024 );
  43. ulTotalRam = MIN( ulTotalRam, 0xFFFFFFFF );
  44. pOut->dwTotalPhys = static_cast<SIZE_T>( ulTotalRam );
  45. }
  46. void Sleep( unsigned int ms )
  47. {
  48. DebuggerBreak();
  49. ThreadSleep( ms );
  50. }
  51. bool IsIconic( VD3DHWND hWnd )
  52. {
  53. // FIXME for now just act non-minimized all the time
  54. //DebuggerBreak();
  55. return false;
  56. }
  57. BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint )
  58. {
  59. DebuggerBreak();
  60. return true;
  61. }
  62. void* GetCurrentThread()
  63. {
  64. DebuggerBreak();
  65. return 0;
  66. }
  67. void SetThreadAffinityMask( void *hThread, int nMask )
  68. {
  69. DebuggerBreak();
  70. }
  71. bool GUID::operator==( const struct _GUID &other ) const
  72. {
  73. DebuggerBreak();
  74. return memcmp( this, &other, sizeof( GUID ) ) == 0;
  75. }
  76. #endif