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.

164 lines
3.8 KiB

  1. /// The unmanaged side of wrapping the app system for CLR
  2. #include "stdafx.h"
  3. #include "cli_appsystem_unmanaged_wrapper.h"
  4. #include "cli_appsystem_adapter.h"
  5. // temporarily make unicode go away as we deal with Valve types
  6. #ifdef _UNICODE
  7. #define PUT_UNICODE_BACK
  8. #undef _UNICODE
  9. #endif
  10. #include "filesystem_helpers.h"
  11. #include "utils\common\filesystem_tools.h"
  12. #ifdef PUT_UNICODE_BACK
  13. #define _UNICODE
  14. #undef PUT_UNICODE_BACK
  15. #endif
  16. inline void CCLIAppSystemAdapter::Wipe( bool bPerformDelete )
  17. {
  18. if ( bPerformDelete )
  19. {
  20. delete m_pLocalRandomStream;
  21. }
  22. m_pFilesystem = NULL;
  23. m_pLocalRandomStream = NULL;
  24. // m_pCommandline = NULL;
  25. }
  26. CCLIAppSystemAdapter::CCLIAppSystemAdapter()
  27. {
  28. Wipe( false );
  29. }
  30. CCLIAppSystemAdapter::~CCLIAppSystemAdapter()
  31. {
  32. Wipe( true );
  33. g_pFullFileSystem = NULL;
  34. }
  35. bool CCLIAppSystemAdapter::Create()
  36. {
  37. AppSystemInfo_t appSystems[] =
  38. {
  39. { "filesystem_stdio.dll", FILESYSTEM_INTERFACE_VERSION },
  40. { "", "" } // Required to terminate the list
  41. };
  42. return AddSystems( appSystems );
  43. }
  44. bool CCLIAppSystemAdapter::PreInit( )
  45. {
  46. CreateInterfaceFn factory = GetFactory();
  47. #if TIER2_USE_INIT_DEFAULT_FILESYSTEM
  48. #else
  49. m_pFilesystem = (IFileSystem*)factory(FILESYSTEM_INTERFACE_VERSION,NULL );
  50. #endif
  51. // m_pCommandline = CommandLine();
  52. m_pLocalRandomStream = new CUniformRandomStream();
  53. // GetCommandLine()->AppendParm("rreditor.exe","");
  54. // GetCommandLine()->AppendParm("-noasync","1");
  55. #if TIER2_USE_INIT_DEFAULT_FILESYSTEM
  56. return true;
  57. #else
  58. return ( m_pFilesystem != NULL );
  59. #endif
  60. }
  61. void CCLIAppSystemAdapter::SetupFileSystem( )
  62. {
  63. g_pFullFileSystem = m_pFilesystem;
  64. g_pFullFileSystem->RemoveAllSearchPaths();
  65. g_pFullFileSystem->AddSearchPath( "", "LOCAL", PATH_ADD_TO_HEAD );
  66. g_pFullFileSystem->AddSearchPath( "", "DEFAULT_WRITE_PATH", PATH_ADD_TO_HEAD );
  67. #if TIER2_USE_INIT_DEFAULT_FILESYSTEM
  68. InitDefaultFileSystem();
  69. #endif
  70. FileSystem_Init( "./", 0, FS_INIT_COMPATIBILITY_MODE, true );
  71. // m_pFilesystem->AddSearchPath( "./", "GAME", PATH_ADD_TO_HEAD );
  72. }
  73. void CCLIAppSystemAdapter::AddFileSystemRoot( const char *pPath )
  74. {
  75. g_pFullFileSystem->AddSearchPath( pPath, "LOCAL", PATH_ADD_TO_HEAD );
  76. g_pFullFileSystem->AddSearchPath( pPath, "GAME", PATH_ADD_TO_HEAD );
  77. }
  78. IFileSystem * CCLIAppSystemAdapter::GetFilesytem()
  79. {
  80. #if TIER2_USE_INIT_DEFAULT_FILESYSTEM
  81. return g_pFullFileSystem;
  82. #else
  83. return m_pFilesystem;
  84. #endif
  85. }
  86. // -----------------------------------------------------------
  87. // | unmanaged-code implementations for the AppSystemWrapper |
  88. // -----------------------------------------------------------
  89. CCLIAppSystemAdapter * AppSystemWrapper_Unmanaged::sm_pAppSystemSingleton = NULL;
  90. int AppSystemWrapper_Unmanaged::sm_nSingletonReferences = 0;
  91. AppSystemWrapper_Unmanaged::AppSystemWrapper_Unmanaged( const char *pCommandLine )
  92. {
  93. if ( sm_pAppSystemSingleton != NULL )
  94. {
  95. Assert( sm_nSingletonReferences > 0 );
  96. sm_nSingletonReferences++;
  97. }
  98. else
  99. {
  100. Assert( sm_nSingletonReferences == 0 );
  101. sm_pAppSystemSingleton = new CCLIAppSystemAdapter();
  102. sm_nSingletonReferences = 1;
  103. InitializeAppSystem( sm_pAppSystemSingleton, pCommandLine );
  104. }
  105. }
  106. AppSystemWrapper_Unmanaged::~AppSystemWrapper_Unmanaged()
  107. {
  108. if ( sm_nSingletonReferences > 1 )
  109. {
  110. sm_nSingletonReferences--;
  111. }
  112. else if ( sm_nSingletonReferences == 1 )
  113. {
  114. TerminateAppSystem( sm_pAppSystemSingleton );
  115. delete sm_pAppSystemSingleton;
  116. sm_pAppSystemSingleton = NULL;
  117. sm_nSingletonReferences = 0;
  118. }
  119. else
  120. {
  121. Assert( sm_pAppSystemSingleton == NULL && sm_nSingletonReferences == 0 ) ;
  122. }
  123. }
  124. void AppSystemWrapper_Unmanaged::InitializeAppSystem( CCLIAppSystemAdapter * pAppSys, const char *pCommandLine )
  125. {
  126. pAppSys->GetCommandLine()->CreateCmdLine( pCommandLine );
  127. pAppSys->Startup();
  128. pAppSys->SetupFileSystem();
  129. }
  130. void AppSystemWrapper_Unmanaged::TerminateAppSystem( CCLIAppSystemAdapter * pAppSys )
  131. {
  132. pAppSys->Shutdown();
  133. }