Source code of Windows XP (NT5)
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.

329 lines
12 KiB

  1. /*
  2. Utility to do some processing in generation of the driver cab file
  3. This tool takes a sorted list of files and checks and strips duplicates.
  4. In addition, given a set of destination directories it will strip out files that don't exist in
  5. any one of these directories. The preference is specified in the order that they are listed.
  6. Author:
  7. Vijesh Shetty (vijeshs) 29-Sep-1998
  8. Revision History:
  9. */
  10. #include "cabprep.h"
  11. #define MAX_LOCATIONS 10
  12. #define MAX_SETS 10
  13. int _cdecl main ( int argc, char *argv[] );
  14. int _cdecl main ( int argc, char *argv[] )
  15. {
  16. PTCHAR i,c;
  17. TCHAR PreviousFile[MAX_PATH], FileNam[MAX_PATH], Path[MAX_SETS][MAX_LOCATIONS][MAX_PATH], DriverList[MAX_SETS][MAX_PATH];
  18. TCHAR CompressedPath[MAX_PATH], Buffer[512], Section[MAX_SETS][MAX_PATH];
  19. TCHAR CompPrependStr[MAX_PATH];
  20. FILE *Read_File, *Error_File, *Index_File, *Write_File, *Make_File;
  21. TCHAR Ddf_name[MAX_PATH];
  22. struct _tfinddata_t c_file;
  23. intptr_t h;
  24. int StrLen,rem,e,count,Found,num_path[MAX_SETS],num_sets=0,count2;
  25. if (argc < 2){
  26. _tprintf( TEXT("CABPREP /s:SortedFile,CabName,[SourceLocation1],[SourceLocation2..] /s:[..]\n"));
  27. _tprintf( TEXT("\n\nUtility to do some processing in generation of driver cab files.\n"));
  28. _tprintf( TEXT("This tool takes a sorted list of files and checks and strips duplicates.\n"));
  29. _tprintf( TEXT("In addition, given a set of destination directories it will strip out files\n"));
  30. _tprintf( TEXT("that don't exist in any one of these directories. The Source location preference follows\n"));
  31. _tprintf( TEXT("the order that they are specified in. Th tool checks for compressed files first\n"));
  32. _tprintf( TEXT("and then the real name. Errors reported in cabprep.err and the index file\n"));
  33. _tprintf( TEXT("created is drvindex.inf. Multiple sets can be given to create a single inf for many cabs.\n"));
  34. _tprintf( TEXT("Don't use any spaces between parameters for a given set.\n"));
  35. return 0;
  36. }
  37. if( argc >= 2 ){
  38. num_sets = argc - 1;
  39. for( count=0; count<num_sets; count++){
  40. num_path[count] = 0;
  41. #ifdef UNICODE
  42. StrLen = MultiByteToWideChar(CP_ACP,
  43. MB_PRECOMPOSED,
  44. argv[count+1],
  45. -1,
  46. Buffer,
  47. sizeof(Buffer)/sizeof(WCHAR)
  48. );
  49. if( !StrLen ){
  50. _tprintf( TEXT("ERROR: Invalid Argument"));
  51. return -1;
  52. }
  53. #else // !UNICODE
  54. lstrcpy( Buffer, argv[count+1] );
  55. #endif //UNICODE
  56. Buffer[2] = L'\0';
  57. if( lstrcmpi( Buffer, TEXT("/S"))){
  58. _tprintf( TEXT("ERROR: Invalid Argument"));
  59. return -1;
  60. }
  61. else{
  62. i = Buffer + 3;
  63. StrLen = lstrlen(i);
  64. for( count2=0; count2 < StrLen; count2++ ){
  65. if( i[count2] == L',' ){
  66. i[count2] = L'\0';
  67. num_path[count]++;
  68. }
  69. }
  70. num_path[count] = num_path[count] - 1;
  71. lstrcpy( DriverList[count], i );
  72. if( !DriverList[count] ){
  73. _tprintf( TEXT("ERROR: Invalid Source File"));
  74. return -1;
  75. }
  76. i = i + lstrlen( i ) + 1;
  77. lstrcpy( Section[count], i );
  78. if( !Section[count] ){
  79. _tprintf( TEXT("ERROR: Invalid Section Name"));
  80. return -1;
  81. }
  82. i = i + lstrlen( i ) + 1;
  83. if( num_path[count] > (MAX_LOCATIONS) ){
  84. _tprintf( TEXT("ERROR: Exceeded maximum no. of paths"));
  85. return( -1 );
  86. }
  87. for( count2=0;count2 < num_path[count]; count2++ ){
  88. lstrcpy( Path[count][count2], i );
  89. if( !Path[count][count2] ){
  90. _tprintf( TEXT("ERROR: Invalid Path"));
  91. return -1;
  92. }
  93. i = i + lstrlen( i ) + 1;
  94. }
  95. }
  96. }
  97. }
  98. Index_File = _tfopen( TEXT("drvindex.inf"), TEXT("w") );
  99. Make_File = _tfopen( TEXT("makefil0"), TEXT("w") );
  100. _ftprintf( Index_File, TEXT("[Version]\n"));
  101. _ftprintf( Index_File, TEXT("signature=\"$Windows NT$\"\n"));
  102. _ftprintf( Index_File, TEXT("CabFiles=%s"), Section[0]);
  103. _ftprintf( Make_File, TEXT("#*****Automatically generated file by cabprep.exe for the build proces************\n\n\n") );
  104. _ftprintf( Make_File, TEXT("all: %s%s.cab"), Path[0][0], Section[0] );
  105. for( count=1; count < num_sets; count++ ){
  106. _ftprintf( Index_File, TEXT(",%s"), Section[count]);
  107. _ftprintf( Make_File, TEXT(" disk1\\%s.cab"), Section[count] );
  108. }
  109. _ftprintf( Make_File, TEXT("\n\n\n") );
  110. Error_File = _tfopen( TEXT("cabprep.err"), TEXT("w") );
  111. for( count2=0; count2 < num_sets; count2++ ){
  112. if( num_sets > 1)
  113. wsprintf( Ddf_name, TEXT("Out%d.ddf"), count2); //use postfix digit for more than one cab
  114. else
  115. lstrcpy( Ddf_name, TEXT("Out.ddf") );
  116. Write_File = _tfopen( Ddf_name, TEXT("w") );
  117. _ftprintf( Write_File, TEXT(";*****Automatically generated file by cabprep.exe for Diamond************\n\n\n") );
  118. _ftprintf( Index_File, TEXT("\n\n\n[%s]\n"), Section[count2]);
  119. _ftprintf( Make_File, TEXT("\n%s%s.cab: "), Path[count2][0], Section[count2] );
  120. _ftprintf( Write_File, TEXT(".New Cabinet\n") );
  121. _ftprintf( Write_File, TEXT(".Set CabinetName%d=%s.cab\n"), (count2+1), Section[count2] );
  122. _ftprintf( Write_File, TEXT(".Set MaxDiskSize=CDROM\n") );
  123. _ftprintf( Write_File, TEXT(".Set CompressionType=LZX\n") );
  124. _ftprintf( Write_File, TEXT(".Set CompressionMemory=21\n") );
  125. _ftprintf( Write_File, TEXT(".Set CompressionLevel=1\n") );
  126. _ftprintf( Write_File, TEXT(".Set Compress=ON\n") );
  127. _ftprintf( Write_File, TEXT(".Set Cabinet=ON\n") );
  128. _ftprintf( Write_File, TEXT(".Set UniqueFiles=ON\n") );
  129. _ftprintf( Write_File, TEXT(".Set FolderSizeThreshold=1000000\n") );
  130. _ftprintf( Write_File, TEXT(".Set MaxErrors=300\n\n\n\n") );
  131. Read_File = _tfopen( DriverList[count2], TEXT("r") );
  132. lstrcpy( PreviousFile, TEXT("$$$.#$$") );
  133. if (Read_File) {
  134. while( 1 ){
  135. // HAck because of bug that doesn't allow the use of _TEOF. Bcoz of the bug
  136. // fscanf returns EOF but fwscanf returns 0 when it should return 0xffff. So _TEOF
  137. // is useless and causes us to loop.
  138. #ifdef UNICODE
  139. if( (_ftscanf( Read_File, TEXT("%s"), FileNam )) == 0 )
  140. #else //UNICODE
  141. if( (_ftscanf( Read_File, TEXT("%s"), FileNam )) == _TEOF )
  142. #endif //UNICODE
  143. break;
  144. for( i = FileNam; i < FileNam + lstrlen( FileNam ); i++ ) {
  145. *i = (TCHAR)towlower( *i );
  146. }
  147. if( lstrcmp( PreviousFile, FileNam )){
  148. if(!num_path[count2]){
  149. _ftprintf( Write_File, TEXT("%s\n"), FileNam );
  150. _ftprintf( Make_File, TEXT("\\\n\t%s "), FileNam );
  151. _ftprintf( Index_File, TEXT("%s\n"), FileNam );
  152. }else{
  153. //
  154. //Do the cross checking only if we specify source paths. Otherwise ignore Path information.
  155. //
  156. Found = 0;
  157. // Try for each path that was given to us first with the compressed name and then uncompressed
  158. for( count=0; count<num_path[count2]; count++){
  159. //
  160. //Construct the compressed full pathname
  161. //
  162. lstrcpy( CompPrependStr, Path[count2][count] );
  163. lstrcat( CompPrependStr, FileNam );
  164. c = _tcsrchr( CompPrependStr, L'.' );
  165. e = lstrlen(CompPrependStr);
  166. rem = (int)(CompPrependStr + e - c - 1);
  167. if( rem < 3 ){
  168. CompPrependStr[e] = '_';
  169. CompPrependStr[e+1] = '\0';
  170. }
  171. else
  172. CompPrependStr[e-1] = '_';
  173. //Look for the compressed file
  174. h=_tfindfirst(CompPrependStr,&c_file);
  175. if(h != -1){
  176. _ftprintf( Write_File, TEXT("%s\n"), CompPrependStr );
  177. _ftprintf( Make_File, TEXT("\\\n\t%s "), CompPrependStr );
  178. _ftprintf( Index_File, TEXT("%s\n"), FileNam );
  179. _findclose(h);
  180. Found=1;
  181. break;
  182. }
  183. else{
  184. // Then the uncompressed path
  185. _ftprintf( Error_File, TEXT("%s not found in %s \n"), CompPrependStr, Path[count2][count] );
  186. lstrcpy( CompPrependStr, Path[count2][count] );
  187. lstrcat( CompPrependStr, FileNam );
  188. h=_tfindfirst(CompPrependStr,&c_file);
  189. if(h != -1){
  190. Found = 1;
  191. _ftprintf( Write_File, TEXT("%s\n"), CompPrependStr );
  192. _ftprintf( Make_File, TEXT("\\\n\t%s "), CompPrependStr );
  193. _ftprintf( Index_File, TEXT("%s\n"), FileNam );
  194. _findclose(h);
  195. break;
  196. }
  197. _ftprintf( Error_File, TEXT("%s not found in %s \n"), CompPrependStr, Path[count2][count] );
  198. }
  199. }
  200. if( !Found )
  201. _ftprintf( Error_File, TEXT("%s missing from all locations \n"), CompPrependStr );
  202. }
  203. }
  204. else
  205. _ftprintf( Error_File, TEXT("Duplicate found - Removing %s\n"), FileNam );
  206. lstrcpy( PreviousFile, FileNam );
  207. }
  208. }
  209. clearerr(Read_File);
  210. fflush(Read_File);
  211. fclose(Read_File);
  212. _ftprintf( Write_File, TEXT("\n\n\n\n") );
  213. fclose(Write_File);
  214. // The line below will try to run recab to find timestamp diffs only for the first sourcepath
  215. _ftprintf( Make_File, TEXT("\n\trecab .\\drvindex.inf %s.cab %s delta.lst"),Section[count2], Path[count2][0] );
  216. _ftprintf( Make_File, TEXT("\n\n"));
  217. // Below lines are not needed with incremental cabs being available. Build process takes care of it
  218. /*_ftprintf( Make_File, TEXT("\n\tdiamond /f %s"), Ddf_name );
  219. _ftprintf( Make_File, TEXT("\n\tcopy /y disk1\\%s.cab %s%s.cab"),Section[count2], Path[count2][0], Section[count2] );
  220. _ftprintf( Make_File, TEXT("\n\tdel /q disk1\\%s.cab\n\n\n\n"),Section[count2] );*/
  221. }//For (count2)
  222. _ftprintf( Index_File, TEXT("\n\n\n[Cabs]\n"));
  223. for( count=0; count < num_sets; count++ ){
  224. _ftprintf( Index_File, TEXT("%s=%s.cab\n"), Section[count],Section[count]);
  225. }
  226. _flushall();
  227. _fcloseall();
  228. return 0;
  229. }