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.

97 lines
2.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #include "filesystem.h"
  10. #include "dedicated.h"
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "interface.h"
  14. #include <string.h>
  15. #include <malloc.h>
  16. #include "tier1/strtools.h"
  17. #include "tier0/icommandline.h"
  18. #include "tier0/dbg.h"
  19. #include "../filesystem/basefilesystem.h"
  20. #include "Steam.h"
  21. #include "appframework/AppFramework.h"
  22. #include "tier2/tier2.h"
  23. extern IFileSystem *g_pFileSystem;
  24. extern IBaseFileSystem *g_pBaseFileSystem;
  25. extern IFileSystem *g_pFileSystemSteam;
  26. extern IBaseFileSystem *g_pBaseFileSystemSteam;
  27. // We have two CBaseFilesystem objects, stdio and steam, so we have to manage the
  28. // BaseFileSystem() accessor ourselves.
  29. #ifdef _WIN32
  30. CBaseFileSystem *BaseFileSystem_Steam( void );
  31. CBaseFileSystem *BaseFileSystem_Stdio( void );
  32. static CBaseFileSystem *s_pBaseFileSystem = NULL;
  33. CBaseFileSystem *BaseFileSystem( void )
  34. {
  35. return s_pBaseFileSystem;
  36. }
  37. #endif
  38. // implement our own special factory that we don't export outside of the DLL, to stop
  39. // people being able to get a pointer to a FILESYSTEM_INTERFACE_VERSION stdio interface
  40. void* FileSystemFactory(const char *pName, int *pReturnCode)
  41. {
  42. #ifdef _WIN32
  43. if ( CommandLine()->FindParm( "-steam" ) )
  44. {
  45. s_pBaseFileSystem = BaseFileSystem_Steam();
  46. if ( !Q_stricmp(pName, FILESYSTEM_INTERFACE_VERSION ) )
  47. {
  48. if ( pReturnCode )
  49. {
  50. *pReturnCode = IFACE_OK;
  51. }
  52. return g_pFileSystemSteam;
  53. }
  54. if ( !Q_stricmp(pName, BASEFILESYSTEM_INTERFACE_VERSION ) )
  55. {
  56. if ( pReturnCode )
  57. {
  58. *pReturnCode = IFACE_OK;
  59. }
  60. return g_pBaseFileSystemSteam;
  61. }
  62. }
  63. else
  64. #endif
  65. {
  66. #ifdef _WIN32
  67. s_pBaseFileSystem = BaseFileSystem_Stdio();
  68. #endif
  69. if ( !Q_stricmp(pName, FILESYSTEM_INTERFACE_VERSION ) )
  70. {
  71. if ( pReturnCode )
  72. {
  73. *pReturnCode = IFACE_OK;
  74. }
  75. return g_pFileSystem;
  76. }
  77. if ( !Q_stricmp(pName, BASEFILESYSTEM_INTERFACE_VERSION ) )
  78. {
  79. if ( pReturnCode )
  80. {
  81. *pReturnCode = IFACE_OK;
  82. }
  83. return g_pBaseFileSystem;
  84. }
  85. }
  86. if ( pReturnCode )
  87. {
  88. *pReturnCode = IFACE_FAILED;
  89. }
  90. return NULL;
  91. }