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.

126 lines
2.7 KiB

  1. //====== Copyright c 1996-2007, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "p4helpers.h"
  9. #include "tier2/tier2.h"
  10. #include "p4lib/ip4.h"
  11. #ifdef PLATFORM_WINDOWS_PC
  12. #include <Windows.h>
  13. #endif // PLATFORM_WINDOWS_PC
  14. // NOTE: This has to be the last file included!
  15. #include "tier0/memdbgon.h"
  16. //////////////////////////////////////////////////////////////////////////
  17. //
  18. // CP4File implementation
  19. //
  20. //////////////////////////////////////////////////////////////////////////
  21. CP4File::CP4File( char const *szFilename )
  22. {
  23. #ifdef PLATFORM_WINDOWS_PC
  24. // On windows, get the pathname of the file on disk first before using that as a perforce path
  25. // this avoids invalid Adds(). Have to go through GetShortPathName and then GetLongPathName from
  26. // the short path name
  27. TCHAR szShortPathName[ MAX_PATH ] = TEXT( "" );
  28. const DWORD shortRetVal = GetShortPathName( szFilename, szShortPathName, ARRAYSIZE( szShortPathName ) );
  29. if ( shortRetVal > 0 && shortRetVal <= ARRAYSIZE( szShortPathName ) )
  30. {
  31. TCHAR szLongPathName[ MAX_PATH ] = TEXT( "" );
  32. const DWORD longRetVal = GetLongPathName( szShortPathName, szLongPathName, ARRAYSIZE( szLongPathName ) );
  33. if ( longRetVal > 0 && longRetVal <= ARRAYSIZE( szLongPathName ) )
  34. {
  35. m_sFilename = szLongPathName;
  36. return;
  37. }
  38. }
  39. #endif // PLATFORM_WINDOWS_PC
  40. m_sFilename = szFilename;
  41. }
  42. CP4File::~CP4File()
  43. {
  44. }
  45. bool CP4File::Edit( void )
  46. {
  47. if ( !p4 )
  48. return true;
  49. return p4->OpenFileForEdit( m_sFilename.String() );
  50. }
  51. bool CP4File::Add( void )
  52. {
  53. if ( !p4 )
  54. return true;
  55. return p4->OpenFileForAdd( m_sFilename.String() );
  56. }
  57. // Is the file in perforce?
  58. bool CP4File::IsFileInPerforce()
  59. {
  60. if ( !p4 )
  61. return false;
  62. return p4->IsFileInPerforce( m_sFilename.String() );
  63. }
  64. //////////////////////////////////////////////////////////////////////////
  65. //
  66. // CP4Factory implementation
  67. //
  68. //////////////////////////////////////////////////////////////////////////
  69. CP4Factory::CP4Factory()
  70. {
  71. }
  72. CP4Factory::~CP4Factory()
  73. {
  74. }
  75. bool CP4Factory::SetDummyMode( bool bDummyMode )
  76. {
  77. bool bOld = m_bDummyMode;
  78. m_bDummyMode = bDummyMode;
  79. return bOld;
  80. }
  81. void CP4Factory::SetOpenFileChangeList( const char *szChangeListName )
  82. {
  83. if ( !m_bDummyMode && p4 )
  84. p4->SetOpenFileChangeList( szChangeListName );
  85. }
  86. CP4File *CP4Factory::AccessFile( char const *szFilename ) const
  87. {
  88. if ( !m_bDummyMode )
  89. return new CP4File( szFilename );
  90. else
  91. return new CP4File_Dummy( szFilename );
  92. }
  93. // Default p4 factory
  94. static CP4Factory s_static_p4_factory;
  95. CP4Factory *g_p4factory = &s_static_p4_factory; // NULL before the factory constructs