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.

135 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CONFIGMANAGER_H
  7. #define CONFIGMANAGER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "keyvalues.h"
  12. #include "utlvector.h"
  13. #include "filesystem_init.h"
  14. // See filesystem_init for the vconfig registry values.
  15. #define TOKEN_GAMES "Games"
  16. #define TOKEN_GAME_DIRECTORY "GameDir"
  17. #define TOKEN_TOOLS "Tools"
  18. // STEAM CLOUD FLAGS
  19. #define STEAMREMOTESTORAGE_CLOUD_CONFIG (1<<0)
  20. #define STEAMREMOTESTORAGE_CLOUD_ALL 0x7fff // all bits set, so any new items added will be on by default
  21. struct defaultConfigInfo_t
  22. {
  23. char gameName[MAX_PATH];
  24. char gameDir[MAX_PATH];
  25. char FGD[MAX_PATH];
  26. char steamPath[MAX_PATH];
  27. char defaultPointEntity[MAX_PATH];
  28. char exeName[MAX_PATH];
  29. int steamAppID;
  30. };
  31. enum eSDKEpochs
  32. {
  33. SDK_EPOCH_HL2 = 1,
  34. SDK_EPOCH_EP1 = 2,
  35. SDK_EPOCH_EP2 = 3,
  36. SDK_EPOCH_PORTAL2 = 4,
  37. SDK_EPOCH_CSS15 = 5,
  38. };
  39. extern defaultConfigInfo_t *gDefaultConfigs[];
  40. class CGameConfigManager
  41. {
  42. public:
  43. enum loadStatus_t
  44. {
  45. LOADSTATUS_NONE = 0, // Configs were loaded with no error
  46. LOADSTATUS_CONVERTED, // GameConfig.txt did not exist and was created by converting GameCfg.INI
  47. LOADSTATUS_CREATED, // GameCfg.INI was not found, the system created the default configuration based on found GameInfo.txt resources
  48. LOADSTATUS_ERROR, // File was not loaded and was unable to perform the above fail-safe procedures
  49. };
  50. CGameConfigManager( void );
  51. CGameConfigManager( const char *fileName );
  52. ~CGameConfigManager( void );
  53. bool LoadConfigs( const char *baseDir = NULL );
  54. bool SaveConfigs( const char *baseDir = NULL );
  55. bool ResetConfigs( const char *baseDir = NULL );
  56. int GetNumConfigs( void );
  57. KeyValues *GetGameBlock( void );
  58. KeyValues *GetGameSubBlock( const char *keyName );
  59. bool GetDefaultGameBlock( KeyValues *pIn );
  60. bool IsLoaded( void ) const { return m_pData != NULL; }
  61. bool WasConvertedOnLoad( void ) const { return m_LoadStatus == LOADSTATUS_CONVERTED; }
  62. bool WasCreatedOnLoad( void ) const { return m_LoadStatus == LOADSTATUS_CREATED; }
  63. bool AddDefaultConfig( const defaultConfigInfo_t &info, KeyValues *out, const char *rootDirectory, const char *gameExeDir );
  64. void SetBaseDirectory( const char *pDirectory );
  65. void GetRootGameDirectory( char *out, size_t outLen, const char *rootDir, const char *steamDir );
  66. const char *GetRootDirectory( void );
  67. void SetSDKEpoch( eSDKEpochs epoch ) { m_eSDKEpoch = epoch; };
  68. static bool IsSDKDeployment()
  69. {
  70. static bool bRetVal = false;
  71. static bool bInitialized = false;
  72. if ( g_pFullFileSystem && !bInitialized )
  73. {
  74. char szBaseDirectory[MAX_PATH];
  75. // Check to see whether 'steamapps/common' is part of the path to this EXE
  76. g_pFullFileSystem->GetCurrentDirectory( szBaseDirectory, sizeof( szBaseDirectory ) );
  77. V_FixSlashes( szBaseDirectory, '/' );
  78. bRetVal = ( V_stristr( szBaseDirectory, "steamapps/common" ) != NULL );
  79. bInitialized = true;
  80. }
  81. return ( bRetVal );
  82. };
  83. private:
  84. void GetRootContentDirectory( char *out, size_t outLen, const char *rootDir );
  85. const char *GetBaseDirectory( void );
  86. const char *GetIniFilePath( void );
  87. bool LoadConfigsInternal( const char *baseDir, bool bRecursiveCall );
  88. void UpdateConfigsInternal( void );
  89. void VersionConfig( void );
  90. bool IsConfigCurrent( void );
  91. bool ConvertGameConfigsINI( void );
  92. bool CreateAllDefaultConfigs( void );
  93. bool IsAppSubscribed( int nAppID );
  94. loadStatus_t m_LoadStatus; // Holds various state about what occured while loading
  95. KeyValues *m_pData; // Data as read from configuration file
  96. char m_szBaseDirectory[MAX_PATH]; // Default directory
  97. eSDKEpochs m_eSDKEpoch; // Holds the "working version" of the SDK for times when we need to create an older set of game configurations.
  98. // This is required now that the SDK is deploying the tools for both the latest and previous versions of the engine.
  99. };
  100. #endif // CONFIGMANAGER_H