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.

130 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "replay/replayutils.h"
  5. #include "dbg.h"
  6. #include "strtools.h"
  7. #include "qlimits.h"
  8. #include "filesystem.h"
  9. #include "replay/replaytime.h"
  10. #include "fmtstr.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //----------------------------------------------------------------------------------------
  14. static char gs_szGameDir[MAX_OSPATH];
  15. //----------------------------------------------------------------------------------------
  16. void Replay_GetFirstAvailableFilename( char *pDst, int nDstLen, const char *pIdealFilename, const char *pExt,
  17. const char *pFilePath, int nStartIndex )
  18. {
  19. // Strip extension from ideal filename
  20. char szIdealFilename[ MAX_OSPATH ];
  21. V_StripExtension( pIdealFilename, szIdealFilename, sizeof( szIdealFilename ) );
  22. int i = nStartIndex;
  23. while ( 1 )
  24. {
  25. V_strncpy( pDst, szIdealFilename, nDstLen );
  26. V_strcat( pDst, Replay_va( "_%i%s", i, pExt ), nDstLen );
  27. // Get a potential working path/filename
  28. CFmtStr fmtTestFilename(
  29. "%s%c%s",
  30. pFilePath,
  31. CORRECT_PATH_SEPARATOR,
  32. pDst
  33. );
  34. // Make sure slashes are correct for platform
  35. V_FixSlashes( fmtTestFilename.Access() );
  36. // Fix up double slashes
  37. V_FixDoubleSlashes( fmtTestFilename.Access() );
  38. if ( !g_pFullFileSystem->FileExists( fmtTestFilename ) )
  39. break;
  40. ++i;
  41. }
  42. }
  43. //----------------------------------------------------------------------------------------
  44. void Replay_ConstructReplayFilenameString( CUtlString &strOut, const char *pReplaySubDir, const char *pFilename, const char *pGameDir )
  45. {
  46. // Construct full filename
  47. strOut.Format( "%s%creplays%c%s%c%s", pGameDir,
  48. CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR, pReplaySubDir,
  49. CORRECT_PATH_SEPARATOR, pFilename
  50. );
  51. }
  52. //----------------------------------------------------------------------------------------
  53. char *Replay_va( const char *format, ... )
  54. {
  55. va_list argptr;
  56. static char string[8][512];
  57. static int curstring = 0;
  58. curstring = ( curstring + 1 ) % 8;
  59. va_start (argptr, format);
  60. Q_vsnprintf( string[curstring], sizeof( string[curstring] ), format, argptr );
  61. va_end (argptr);
  62. return string[curstring];
  63. }
  64. //----------------------------------------------------------------------------------------
  65. void Replay_SetGameDir( const char *pGameDir )
  66. {
  67. V_strcpy( gs_szGameDir, pGameDir );
  68. }
  69. //----------------------------------------------------------------------------------------
  70. const char *Replay_GetGameDir()
  71. {
  72. return gs_szGameDir;
  73. }
  74. //----------------------------------------------------------------------------------------
  75. const char *Replay_GetBaseDir()
  76. {
  77. return Replay_va(
  78. "%s%creplays%c",
  79. Replay_GetGameDir(),
  80. CORRECT_PATH_SEPARATOR,
  81. CORRECT_PATH_SEPARATOR
  82. );
  83. }
  84. //----------------------------------------------------------------------------------------
  85. void Replay_GetAutoName( wchar_t *pDest, int nDestSize, const char *pMapName )
  86. {
  87. // Get date/time
  88. CReplayTime now;
  89. now.InitDateAndTimeToNow();
  90. // Convert map name to unicode
  91. wchar_t wszMapName[256];
  92. extern vgui::ILocalize *g_pVGuiLocalize;
  93. g_pVGuiLocalize->ConvertANSIToUnicode( pMapName, wszMapName, sizeof( wszMapName ) );
  94. // Get localized date as string
  95. const wchar_t *pLocalizedDate = CReplayTime::GetLocalizedDate( g_pVGuiLocalize, now, true );
  96. // Create title
  97. g_pVGuiLocalize->ConstructString( pDest, nDestSize, L"%s1: %s2", 2, wszMapName, pLocalizedDate );
  98. }
  99. //----------------------------------------------------------------------------------------