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.

191 lines
7.2 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef IP4_H
  7. #define IP4_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlsymbol.h"
  12. #include "tier1/utlvector.h"
  13. #include "tier1/utlstring.h"
  14. #include "appframework/iappsystem.h"
  15. //-----------------------------------------------------------------------------
  16. // Current perforce file state
  17. //-----------------------------------------------------------------------------
  18. enum P4FileState_t
  19. {
  20. P4FILE_UNOPENED = 0,
  21. P4FILE_OPENED_FOR_ADD,
  22. P4FILE_OPENED_FOR_EDIT,
  23. P4FILE_OPENED_FOR_DELETE,
  24. P4FILE_OPENED_FOR_INTEGRATE,
  25. };
  26. //-----------------------------------------------------------------------------
  27. // Purpose: definition of a file
  28. //-----------------------------------------------------------------------------
  29. struct P4File_t
  30. {
  31. CUtlSymbol m_sName; // file name
  32. CUtlSymbol m_sPath; // residing folder
  33. CUtlSymbol m_sDepotFile; // the name in the depot
  34. CUtlSymbol m_sClientFile; // the name on the client in Perforce syntax
  35. CUtlSymbol m_sLocalFile; // the name on the client in local syntax
  36. int m_iHeadRevision; // head revision number
  37. int m_iHaveRevision; // the revision the clientspec has synced locally
  38. bool m_bOpenedByOther; // opened by another user
  39. bool m_bDir; // directory
  40. bool m_bDeleted; // deleted
  41. P4FileState_t m_eOpenState; // current change state
  42. int m_iChangelist; // changelist current opened in
  43. };
  44. //-----------------------------------------------------------------------------
  45. // Purpose: a single revision of a file
  46. //-----------------------------------------------------------------------------
  47. struct P4Revision_t
  48. {
  49. int m_iChange; // changelist number
  50. int m_nYear, m_nMonth, m_nDay;
  51. int m_nHour, m_nMinute, m_nSecond;
  52. CUtlSymbol m_sUser; // submitting user
  53. CUtlSymbol m_sClient; // submitting client
  54. CUtlString m_Description;
  55. };
  56. //-----------------------------------------------------------------------------
  57. // Purpose: a single clientspec
  58. //-----------------------------------------------------------------------------
  59. struct P4Client_t
  60. {
  61. CUtlSymbol m_sName;
  62. CUtlSymbol m_sUser;
  63. CUtlSymbol m_sHost; // machine name this client is on
  64. CUtlSymbol m_sLocalRoot; // local path
  65. };
  66. //-----------------------------------------------------------------------------
  67. // Purpose: Interface to accessing P4 commands
  68. //-----------------------------------------------------------------------------
  69. #define P4_MAX_INPUT_BUFFER_SIZE 16384 // descriptions should be limited to this size!
  70. abstract_class IP4 : public IAppSystem
  71. {
  72. public:
  73. // name of the current clientspec
  74. virtual P4Client_t &GetActiveClient() = 0;
  75. // changes the current client
  76. virtual void SetActiveClient(const char *clientname) = 0;
  77. // Refreshes the current client from p4 settings
  78. virtual void RefreshActiveClient() = 0;
  79. // translate filespecs into the desired syntax
  80. virtual void GetDepotFilePath(char *depotFilePath, const char *filespec, int size) = 0;
  81. virtual void GetClientFilePath(char *clientFilePath, const char *filespec, int size) = 0;
  82. virtual void GetLocalFilePath(char *localFilePath, const char *filespec, int size) = 0;
  83. // retreives the list of files in a path
  84. virtual CUtlVector<P4File_t> &GetFileList( const char *path ) = 0;
  85. // returns the list of files opened for edit/integrate/delete
  86. virtual void GetOpenedFileList( CUtlVector<P4File_t> &fileList, bool bDefaultChangeOnly ) = 0;
  87. virtual void GetOpenedFileList( const char *pRootDirectory, CUtlVector<P4File_t> &fileList ) = 0;
  88. virtual void GetOpenedFileListInPath( const char *pPathID, CUtlVector<P4File_t> &fileList ) = 0;
  89. // retrieves revision history for a file or directory
  90. virtual CUtlVector<P4Revision_t> &GetRevisionList( const char *path, bool bIsDir ) = 0;
  91. // returns a list of clientspecs
  92. virtual CUtlVector<P4Client_t> &GetClientList() = 0;
  93. // changes the clientspec to remove the specified path (cloaking)
  94. virtual void RemovePathFromActiveClientspec( const char *path ) = 0;
  95. // file manipulation
  96. virtual bool OpenFileForAdd( const char *pFullPath ) = 0;
  97. virtual bool OpenFileForEdit( const char *pFullPath ) = 0;
  98. virtual bool OpenFileForDelete( const char *pFullPath ) = 0;
  99. virtual bool SyncFile( const char *pFullPath, int nRevision = -1 ) = 0; // default revision is to sync to the head revision
  100. // submit/revert
  101. virtual bool SubmitFile( const char *pFullPath, const char *pDescription ) = 0;
  102. virtual bool RevertFile( const char *pFullPath ) = 0;
  103. // file checkin/checkout for multiple files
  104. virtual bool OpenFilesForAdd( int nCount, const char **ppFullPathList ) = 0;
  105. virtual bool OpenFilesForEdit( int nCount, const char **ppFullPathList ) = 0;
  106. virtual bool OpenFilesForDelete( int nCount, const char **ppFullPathList ) = 0;
  107. // submit/revert for multiple files
  108. virtual bool SubmitFiles( int nCount, const char **ppFullPathList, const char *pDescription ) = 0;
  109. virtual bool RevertFiles( int nCount, const char **ppFullPathList ) = 0;
  110. // Is this file in perforce?
  111. virtual bool IsFileInPerforce( const char *pFullPath ) = 0;
  112. // Get the perforce file state
  113. virtual P4FileState_t GetFileState( const char *pFullPath ) = 0;
  114. // depot root
  115. virtual const char *GetDepotRoot() = 0;
  116. virtual int GetDepotRootLength() = 0;
  117. // local root
  118. virtual const char *GetLocalRoot() = 0;
  119. virtual int GetLocalRootLength() = 0;
  120. // Gets a string for a symbol
  121. virtual const char *String( CUtlSymbol s ) const = 0;
  122. // Returns which clientspec a file lies under. This will
  123. // search for p4config files in root directories of the file
  124. // It returns false if it didn't find a p4config file.
  125. virtual bool GetClientSpecForFile( const char *pFullPath, char *pClientSpec, int nMaxLen ) = 0;
  126. virtual bool GetClientSpecForDirectory( const char *pFullPathDir, char *pClientSpec, int nMaxLen ) = 0;
  127. // Returns which clientspec a filesystem path ID lies under. This will
  128. // search for p4config files in all root directories of the all paths in
  129. // the search path. NOTE: All directories in a path need to use the same clientspec
  130. // or this function will return false.
  131. // It returns false if it didn't find a p4config file.
  132. virtual bool GetClientSpecForPath( const char *pPathId, char *pClientSpec, int nMaxLen ) = 0;
  133. // Opens a file in p4 win
  134. virtual void OpenFileInP4Win( const char *pFullPath ) = 0;
  135. // have we connected? if not, nothing works
  136. virtual bool IsConnectedToServer( bool bRetry = true ) = 0;
  137. // Returns file information for a single file
  138. virtual bool GetFileInfo( const char *pFullPath, P4File_t *pFileInfo ) = 0;
  139. // retrieves the list of files in a path, using a known client spec
  140. virtual CUtlVector<P4File_t> &GetFileListUsingClientSpec( const char *pPath, const char *pClientSpec ) = 0;
  141. // retrieves the last error from the last op (which is likely to span multiple lines)
  142. // this is only valid after OpenFile[s]For{Add,Edit,Delete} or {Submit,Revert}File[s]
  143. virtual const char *GetLastError() = 0;
  144. // sets the name of the changelist to open files under, NULL for "Default" changelist
  145. virtual void SetOpenFileChangeList( const char *pChangeListName ) = 0;
  146. virtual void GetFileListInChangelist( unsigned int changeListNumber, CUtlVector<P4File_t> &fileList ) = 0;
  147. };
  148. DECLARE_TIER2_INTERFACE( IP4, p4 );
  149. #endif // IP4_H