UtilityDepend.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "StdH.h"
  13. #include "Dependency.h"
  14. // Depend - extract dependencies and create group file utility
  15. #define ACHR_OPTION argv[1]
  16. #define ACHR_APP_DIR argv[2]
  17. void PrintUsage()
  18. {
  19. printf(
  20. "\nUSAGE:\n"
  21. "Depend d <application dir> <file 1> <file 2> <output file>\n"
  22. " make difference beetween two dependency files (result = file 1 - file 2)\n"
  23. "Depend i <application dir> <lst file> <dep file>\n"
  24. " create dependencies for files listed in given list file\n"
  25. "Depend u <application dir> <in dep file> <out dep file>\n"
  26. " remove updated files from dependency file\n"
  27. "Depend e <application dir> <dep file> <lst file>\n"
  28. " export dependency file to ascii list file\n"
  29. "Depend t <application dir> <lst file> <translation file>\n"
  30. " export strings for translation\n"
  31. "\n");
  32. exit( EXIT_FAILURE);
  33. }
  34. void SubMain( int argc, char *argv[]);
  35. int main( int argc, char *argv[])
  36. {
  37. CTSTREAM_BEGIN {
  38. SubMain(argc, argv);
  39. } CTSTREAM_END;
  40. return 0;
  41. }
  42. void SubMain( int argc, char *argv[])
  43. {
  44. // there must be 4 or 6 parameters (first is depend.exe file name)
  45. if( (argc < 4) || (argc > 6) )
  46. {
  47. PrintUsage();
  48. }
  49. // initialize engine
  50. SE_InitEngine("");
  51. // get application path from cmd line
  52. _fnmApplicationPath = CTString(ACHR_APP_DIR);
  53. // if not ending with backslash
  54. if (_fnmApplicationPath[strlen(_fnmApplicationPath)-1]!='\\') {
  55. _fnmApplicationPath += "\\";
  56. }
  57. // get all filenames from command line
  58. CTFileName afnFiles[3];
  59. INDEX ctFiles = argc-3;
  60. if (ctFiles>ARRAYCOUNT(afnFiles)) {
  61. PrintUsage();
  62. }
  63. for (INDEX iFile=0; iFile<ctFiles; iFile++) {
  64. afnFiles[iFile] = CTString(argv[iFile+3]);
  65. }
  66. // lenght of options string must be 1
  67. if( strlen( ACHR_OPTION) != 1) {
  68. printf( "First argument must be letter representing wanted option.\n\n");
  69. PrintUsage();
  70. }
  71. // try to
  72. try {
  73. // remove application paths
  74. for (INDEX iFile=0; iFile<ctFiles; iFile++) {
  75. AdjustFilePath_t(afnFiles[iFile]);
  76. }
  77. // see what option was requested
  78. switch( tolower(ACHR_OPTION[0]) ) {
  79. case 'i': {
  80. if( ctFiles != 2) PrintUsage();
  81. CDependencyList dl;
  82. CTFileStream strmDep;
  83. // import files into dependency list from given ascii file
  84. dl.ImportASCII( afnFiles[0]);
  85. // extract dependencies
  86. dl.ExtractDependencies();
  87. // write dependency list
  88. strmDep.Create_t( afnFiles[1], CTStream::CM_BINARY);
  89. dl.Write_t( &strmDep);
  90. } break;
  91. case 'e': {
  92. if( ctFiles != 2) PrintUsage();
  93. CDependencyList dl;
  94. CTFileStream strmDepIn;
  95. // read dependency list
  96. strmDepIn.Open_t( afnFiles[0], CTStream::OM_READ);
  97. dl.Read_t( &strmDepIn);
  98. strmDepIn.Close();
  99. // export file suitable for archivers
  100. dl.ExportASCII_t( afnFiles[1]);
  101. } break;
  102. case 'u': {
  103. if( ctFiles != 2) PrintUsage();
  104. CDependencyList dl;
  105. CTFileStream strmDepIn, strmDepOut;
  106. // read dependency list
  107. strmDepIn.Open_t( afnFiles[0], CTStream::OM_READ);
  108. dl.Read_t( &strmDepIn);
  109. strmDepIn.Close();
  110. // remove updated files from list
  111. dl.RemoveUpdatedFiles();
  112. // write dependency list
  113. strmDepOut.Create_t( afnFiles[1], CTStream::CM_BINARY);
  114. dl.Write_t( &strmDepOut);
  115. } break;
  116. case 'd': { // UNTESTED!!!!
  117. if( ctFiles != 3) PrintUsage();
  118. // load dependency lists
  119. CDependencyList dl1, dl2;
  120. CTFileStream strmDep1, strmDep2, strmDepDiff;
  121. strmDep1.Open_t( afnFiles[0], CTStream::OM_READ);
  122. strmDep2.Open_t( afnFiles[1], CTStream::OM_READ);
  123. dl1.Read_t( &strmDep1);
  124. dl2.Read_t( &strmDep2);
  125. strmDep1.Close();
  126. strmDep2.Close();
  127. // calculate difference dependency 1 and 2 (res = 1-2)
  128. dl1.Substract( dl2);
  129. // save the difference dependency list
  130. strmDepDiff.Create_t( afnFiles[2], CTStream::CM_BINARY);
  131. dl1.Write_t( &strmDepDiff);
  132. } break;
  133. case 't': {
  134. if( ctFiles != 2) PrintUsage();
  135. CDependencyList dl;
  136. // read file list
  137. dl.ImportASCII( afnFiles[0]);
  138. // extract translations
  139. dl.ExtractTranslations_t( afnFiles[1]);
  140. } break;
  141. default: {
  142. printf( "Unrecognizable option requested.\n\n");
  143. PrintUsage();
  144. }
  145. }
  146. }
  147. catch( char *pError)
  148. {
  149. printf( "Error occured.\n%s\n", pError);
  150. }
  151. }