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.

223 lines
7.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef FILESYSTEM_INIT_H
  7. #define FILESYSTEM_INIT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "filesystem.h"
  12. // If this option is on the command line, then filesystem_init won't bring up the vconfig
  13. // dialog even if FS_ERRORMODE_VCONFIG is used.
  14. #define CMDLINEOPTION_NOVCONFIG "-NoVConfig"
  15. #define GAMEDIR_TOKEN "VProject"
  16. #define GAMEROOT_TOKEN "VGame"
  17. #define CONTENTROOT_TOKEN "VContent"
  18. #if defined( _WIN32 ) || defined( WIN32 )
  19. #define PATHSEPARATOR(c) ((c) == '\\' || (c) == '/')
  20. #else //_WIN32
  21. #define PATHSEPARATOR(c) ((c) == '/')
  22. #endif //_WIN32
  23. enum FSReturnCode_t
  24. {
  25. FS_OK,
  26. FS_MISSING_GAMEINFO_FILE,
  27. FS_INVALID_GAMEINFO_FILE,
  28. FS_INVALID_PARAMETERS,
  29. FS_UNABLE_TO_INIT,
  30. FS_MISSING_STEAM_DLL
  31. };
  32. enum FSErrorMode_t
  33. {
  34. FS_ERRORMODE_AUTO, // Call Error() in case of an error.
  35. FS_ERRORMODE_VCONFIG, // Call Error() for errors and run vconfig when appropriate.
  36. FS_ERRORMODE_NONE, // Just return FSReturnCode values and setup the string for FileSystem_GetLastErrorString.
  37. };
  38. class CFSSteamSetupInfo
  39. {
  40. public:
  41. CFSSteamSetupInfo();
  42. // Inputs.
  43. public:
  44. // If this is set, then the init code will look in this directory up to the root for gameinfo.txt.
  45. // It must be set for FileSystem_LoadSearchPaths to work.
  46. //
  47. // (default: null)
  48. const char *m_pDirectoryName;
  49. // If this is true, then it won't look at -vproject, -game, or the vproject environment variable
  50. // to find gameinfo.txt. If this is true, then m_pDirectoryName must be set.
  51. //
  52. // (default: false)
  53. bool m_bOnlyUseDirectoryName;
  54. // If this is true, then:
  55. // 1. It will set the environment variables that steam.dll looks at for startup info.
  56. // 2. It will look for ToolsAppId in the gameinfo.txt file and load the
  57. // steam caches associated with that cache if it's there. This is so apps like Hammer and hlmv
  58. // can load the main steam caches (like for Counter-Strike or Half-Life 2), and also load the
  59. // caches that include tools-specific materials (materials\editor, materials\debug, etc).
  60. //
  61. // (default: true - should be FALSE for the engine)
  62. bool m_bToolsMode;
  63. // If this is true, and m_bToolsMode is false, then it will append the path to steam.dll to the
  64. // PATH environment variable. This makes it so you can run the engine under Steam without
  65. // having to copy steam.dll up into your hl2.exe folder.
  66. // (default: false)
  67. bool m_bSetSteamDLLPath;
  68. // Are we loading the Steam filesystem? This should be the same value that
  69. // FileSystem_GetFileSystemDLLName gave you.
  70. bool m_bSteam;
  71. // If this is true, then it won't look for a gameinfo.txt.
  72. //
  73. // (default: false)
  74. bool m_bNoGameInfo;
  75. // Outputs (if it returns FS_OK).
  76. public:
  77. char m_GameInfoPath[512]; // The directory that gameinfo.txt lives in.
  78. };
  79. class CFSLoadModuleInfo : public CFSSteamSetupInfo
  80. {
  81. public:
  82. CFSLoadModuleInfo();
  83. // Inputs.
  84. public:
  85. // Full path to the file system DLL (gotten from FileSystem_GetFileSystemDLLName).
  86. const char *m_pFileSystemDLLName;
  87. // Passed to IFileSystem::Connect.
  88. CreateInterfaceFn m_ConnectFactory;
  89. // Outputs (if it returns FS_OK).
  90. public:
  91. // The filesystem you got from FileSystem_LoadFileSystemModule.
  92. IFileSystem *m_pFileSystem;
  93. CSysModule *m_pModule;
  94. };
  95. class CFSMountContentInfo
  96. {
  97. public:
  98. CFSMountContentInfo();
  99. // Inputs.
  100. public:
  101. // See CFSLoadModuleInfo::m_bToolsMode (this valid should always be the same as you passed to CFSLoadModuleInfo::m_bToolsMode).
  102. bool m_bToolsMode;
  103. // This specifies the directory where gameinfo.txt is. This must be set.
  104. // It can come from CFSLoadModuleInfo::m_GameInfoPath.
  105. const char *m_pDirectoryName;
  106. // Gotten from CFSLoadModuleInfo::m_pFileSystem.
  107. IFileSystem *m_pFileSystem;
  108. };
  109. class CFSSearchPathsInit
  110. {
  111. public:
  112. CFSSearchPathsInit();
  113. // Inputs.
  114. public:
  115. // This specifies the directory where gameinfo.txt is. This must be set.
  116. const char *m_pDirectoryName;
  117. // If this is set, then it will add a search path with _<language> appended to the pathname
  118. // for each search path with a path ID of "game".
  119. // (default: null)
  120. const char *m_pLanguage;
  121. // This is the filesystem FileSystem_LoadSearchPaths is talking to.
  122. IFileSystem *m_pFileSystem;
  123. // Outputs.
  124. public:
  125. // This is the location of the first search path called "game", which also becomes your "mod" search path.
  126. char m_ModPath[512];
  127. };
  128. const char *GetVProjectCmdLineValue();
  129. // Call this to use a bin directory relative to VPROJECT
  130. void FileSystem_UseVProjectBinDir( bool bEnable );
  131. // This is used by all things that use the application framework:
  132. // Note that the application framework automatically takes care of step 1 if you use CSteamApplication.
  133. // Step 1: Ask filesystem_init for the name of the filesystem DLL to load
  134. FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLen, bool &bSteam );
  135. // Step 2: Use filesystem framework to load/connect/init that filesystem DLL
  136. // -or- just set up the steam environment and get back the gameinfo.txt path
  137. // The second method is used by the application framework, which wants to connect/init the filesystem itself
  138. FSReturnCode_t FileSystem_LoadFileSystemModule( CFSLoadModuleInfo &info );
  139. FSReturnCode_t FileSystem_SetupSteamEnvironment( CFSSteamSetupInfo &info );
  140. // Step 3: Ask filesystem_init to set up the executable search path, and mount the steam content based on the mod gameinfo.txt file
  141. FSReturnCode_t FileSystem_MountContent( CFSMountContentInfo &fsInfo );
  142. // Step 4: Load the search paths out of pGameDirectory\gameinfo.txt.
  143. FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo );
  144. // This is automatically done during step 3, but if you want to redo all the search
  145. // paths (like Hammer does), you can call this to reset executable_path.
  146. FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem );
  147. // Utility function to add the PLATFORM search path.
  148. void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *szGameInfoPath );
  149. // See FSErrorMode_t. If you don't specify one here, then the default is FS_ERRORMODE_VCONFIG.
  150. void FileSystem_SetErrorMode( FSErrorMode_t errorMode = FS_ERRORMODE_VCONFIG );
  151. bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen );
  152. // Clear SteamAppUser, SteamUserPassphrase, and SteamAppId from this process's environment.
  153. // TODO: always do this after LoadFileSysteModule.. there's no reason it should be
  154. // in the environment.
  155. void FileSystem_ClearSteamEnvVars();
  156. // Find the steam.cfg above you for optional stuff
  157. FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen );
  158. // Setup the Steam.dll path without needing all the extra gameinfo stuff first
  159. // used by the CSteamApplication::Create() code to LoadModule() on the filesystem
  160. // before the underlying apps know specific details about the environment to load
  161. FSReturnCode_t FileSystem_SetupSteamInstallPath();
  162. // Returns the last error.
  163. const char *FileSystem_GetLastErrorString();
  164. void Q_getwd( char *out, int outSize );
  165. KeyValues* ReadKeyValuesFile( const char *pFilename );
  166. #endif // FILESYSTEM_INIT_H