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.

217 lines
6.7 KiB

  1. //========= Copyright 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. #if defined( _WIN32 ) || defined( WIN32 )
  17. #define PATHSEPARATOR(c) ((c) == '\\' || (c) == '/')
  18. #else //_WIN32
  19. #define PATHSEPARATOR(c) ((c) == '/')
  20. #endif //_WIN32
  21. enum FSReturnCode_t
  22. {
  23. FS_OK,
  24. FS_MISSING_GAMEINFO_FILE,
  25. FS_INVALID_GAMEINFO_FILE,
  26. FS_INVALID_PARAMETERS,
  27. FS_UNABLE_TO_INIT,
  28. FS_MISSING_STEAM_DLL
  29. };
  30. enum FSErrorMode_t
  31. {
  32. FS_ERRORMODE_AUTO, // Call Error() in case of an error.
  33. FS_ERRORMODE_VCONFIG, // Call Error() for errors and run vconfig when appropriate.
  34. FS_ERRORMODE_NONE, // Just return FSReturnCode values and setup the string for FileSystem_GetLastErrorString.
  35. };
  36. class CFSSteamSetupInfo
  37. {
  38. public:
  39. CFSSteamSetupInfo();
  40. // Inputs.
  41. public:
  42. // If this is set, then the init code will look in this directory up to the root for gameinfo.txt.
  43. // It must be set for FileSystem_LoadSearchPaths to work.
  44. //
  45. // (default: null)
  46. const char *m_pDirectoryName;
  47. // If this is true, then it won't look at -vproject, -game, or the vproject environment variable
  48. // to find gameinfo.txt. If this is true, then m_pDirectoryName must be set.
  49. //
  50. // (default: false)
  51. bool m_bOnlyUseDirectoryName;
  52. // If this is true, then:
  53. // 1. It will set the environment variables that steam.dll looks at for startup info.
  54. // 2. It will look for ToolsAppId in the gameinfo.txt file and load the
  55. // steam caches associated with that cache if it's there. This is so apps like Hammer and hlmv
  56. // can load the main steam caches (like for Counter-Strike or Half-Life 2), and also load the
  57. // caches that include tools-specific materials (materials\editor, materials\debug, etc).
  58. //
  59. // (default: true - should be FALSE for the engine)
  60. bool m_bToolsMode;
  61. // If this is true, and m_bToolsMode is false, then it will append the path to steam.dll to the
  62. // PATH environment variable. This makes it so you can run the engine under Steam without
  63. // having to copy steam.dll up into your hl2.exe folder.
  64. // (default: false)
  65. bool m_bSetSteamDLLPath;
  66. // Are we loading the Steam filesystem? This should be the same value that
  67. // FileSystem_GetFileSystemDLLName gave you.
  68. bool m_bSteam;
  69. // If this is true, then it won't look for a gameinfo.txt.
  70. //
  71. // (default: false)
  72. bool m_bNoGameInfo;
  73. // Outputs (if it returns FS_OK).
  74. public:
  75. char m_GameInfoPath[512]; // The directory that gameinfo.txt lives in.
  76. };
  77. class CFSLoadModuleInfo : public CFSSteamSetupInfo
  78. {
  79. public:
  80. CFSLoadModuleInfo();
  81. // Inputs.
  82. public:
  83. // Full path to the file system DLL (gotten from FileSystem_GetFileSystemDLLName).
  84. const char *m_pFileSystemDLLName;
  85. // Passed to IFileSystem::Connect.
  86. CreateInterfaceFn m_ConnectFactory;
  87. // Outputs (if it returns FS_OK).
  88. public:
  89. // The filesystem you got from FileSystem_LoadFileSystemModule.
  90. IFileSystem *m_pFileSystem;
  91. CSysModule *m_pModule;
  92. };
  93. class CFSMountContentInfo
  94. {
  95. public:
  96. CFSMountContentInfo();
  97. // Inputs.
  98. public:
  99. // See CFSLoadModuleInfo::m_bToolsMode (this valid should always be the same as you passed to CFSLoadModuleInfo::m_bToolsMode).
  100. bool m_bToolsMode;
  101. // This specifies the directory where gameinfo.txt is. This must be set.
  102. // It can come from CFSLoadModuleInfo::m_GameInfoPath.
  103. const char *m_pDirectoryName;
  104. // Gotten from CFSLoadModuleInfo::m_pFileSystem.
  105. IFileSystem *m_pFileSystem;
  106. };
  107. class CFSSearchPathsInit
  108. {
  109. public:
  110. CFSSearchPathsInit();
  111. // Inputs.
  112. public:
  113. // This specifies the directory where gameinfo.txt is. This must be set.
  114. const char *m_pDirectoryName;
  115. // If this is set, then any search paths with a _english will be replaced with _m_pLanguage and added before the
  116. // _english path
  117. // (default: null)
  118. const char *m_pLanguage;
  119. // This is the filesystem FileSystem_LoadSearchPaths is talking to.
  120. IFileSystem *m_pFileSystem;
  121. bool m_bMountHDContent;
  122. bool m_bLowViolence;
  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. // Returns the last error.
  159. const char *FileSystem_GetLastErrorString();
  160. void Q_getwd( char *out, int outSize );
  161. #endif // FILESYSTEM_INIT_H