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.

145 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "stdafx.h"
  9. #include <string>
  10. #include <ctype.h>
  11. #include <wchar.h>
  12. #include <assert.h>
  13. #include <direct.h>
  14. #include <time.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. using namespace std;
  18. void rmkdir( const char *pszPath )
  19. {
  20. char *pszScan = const_cast<char*>(pszPath);
  21. if ( *pszScan == '\\' && *(pszScan + 1) == '\\' )
  22. {
  23. assert( 0 );
  24. }
  25. else if ( *pszScan && *(pszScan + 1) == ':' && *(pszScan + 2) == '\\' )
  26. {
  27. pszScan += 3;
  28. }
  29. char *pszLimit = pszScan + strlen( pszScan ) + 1;
  30. while ( pszScan < pszLimit )
  31. {
  32. if ( *pszScan == '\\' || *pszScan == 0 )
  33. {
  34. char temp = *pszScan;
  35. *pszScan = 0;
  36. _mkdir( pszPath );
  37. *pszScan = temp;
  38. }
  39. pszScan++;
  40. }
  41. }
  42. int main(int argc, char* argv[])
  43. {
  44. char input[1024*16];
  45. string notCopied;
  46. if ( argc != 3 )
  47. {
  48. printf( "wrong arguments\n");
  49. return 1;
  50. }
  51. string sourceRoot(argv[1]);
  52. string workingFolder(argv[2]);
  53. if ( !workingFolder.length() )
  54. return 1;
  55. if ( workingFolder[workingFolder.length()] != '\\' )
  56. workingFolder += "\\";
  57. if ( !sourceRoot.length() )
  58. return 1;
  59. if ( sourceRoot[sourceRoot.length()] != '\\' )
  60. sourceRoot += "\\";
  61. int lenRoot = sourceRoot.length();
  62. int count = 0;
  63. unsigned nKBytesCopied = 0;
  64. time_t startTime = time(NULL);
  65. while ( gets(input) )
  66. {
  67. char *pszName = strstr(input, argv[1] );
  68. if ( !pszName )
  69. continue;
  70. if ( strlen(pszName) - lenRoot <= 0 )
  71. continue;
  72. string dest = workingFolder + ( pszName + lenRoot );
  73. string destDir = dest;
  74. destDir.erase( destDir.rfind( '\\' ) );
  75. rmkdir( destDir.c_str() );
  76. DWORD attributes = GetFileAttributes( dest.c_str() );
  77. if ( attributes != -1 && !(attributes & FILE_ATTRIBUTE_READONLY) )
  78. {
  79. notCopied += '\n';
  80. notCopied += dest;
  81. }
  82. else
  83. {
  84. if ( attributes != -1 )
  85. SetFileAttributes( dest.c_str(), (attributes & ~FILE_ATTRIBUTE_READONLY ) );
  86. printf("%s\n", dest.c_str() );
  87. fflush(NULL);
  88. if ( !CopyFile( pszName, dest.c_str(), false ) )
  89. {
  90. printf( " Failed to copy %s!\n", dest.c_str() );
  91. }
  92. else
  93. {
  94. struct _stat fileStat;
  95. _stat( dest.c_str(), &fileStat );
  96. nKBytesCopied += fileStat.st_size / 1024;
  97. }
  98. attributes = GetFileAttributes( dest.c_str() );
  99. SetFileAttributes( dest.c_str(), (attributes | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE) );
  100. count++;
  101. }
  102. }
  103. printf("\n");
  104. if ( count )
  105. {
  106. printf( "%d files copied\n", count );
  107. printf( "%dk copied\n", nKBytesCopied );
  108. }
  109. if ( notCopied.length() )
  110. {
  111. printf( "** The following files were not copied because they are writable **\n" );
  112. printf( notCopied.c_str() );
  113. printf( "\n" );
  114. }
  115. printf("%d seconds\n", time(NULL) - startTime);
  116. return 0;
  117. }