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.

268 lines
5.9 KiB

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. if /i NOT "%_echo%" == "" echo on
  4. if /i NOT "%verbose%" == "" echo on
  5. REM -------------------------------------------------------------------------
  6. REM drvcab.cmd - cab up the drivers for NT5 - VijeshS, owner
  7. REM -------------------------------------------------------------------------
  8. REM pushd %_NTTREE%
  9. REM echo ***Generating %_NTTREE%\out.ddf for driver.cab
  10. REM
  11. REM cabprep /s:sorted.lst,driver,%_NTTREE%\
  12. REM
  13. REM popd
  14. echo *** Generating driver.cab ***
  15. REM
  16. REM Set some variables
  17. REM
  18. set TempDir=%_NTTREE%\cabs\driver
  19. set ListDir=%TempDir%\lists
  20. set InList=%_NTTREE%\sorted.lst
  21. set FinalList=%ListDir%\final.lst
  22. REM TotalCabs is the number of temporary cabs
  23. set /a TotalCabs="%NUMBER_OF_PROCESSORS%*2"
  24. REM DestDir is the directory for the final cab
  25. set DestDir=%_NTTREE%
  26. REM DDFDir is the directory for the temporary DDF's
  27. set DDFDir=%TempDir%\ddf
  28. set Makefile=%DDFDir%\makefile
  29. set TargetFile=%DDFDir%\targets.lst
  30. REM CabDir is the directory for the temporary cabs
  31. set CabDir=%TempDir%\cabs
  32. REM CabName is the name of the cab, without .cab at the end
  33. set CabName=driver
  34. REM FileSizes contains the name of each file and its respective size
  35. set FileSizes=%ListDir%\filesize.lst
  36. REM
  37. REM Make the list of the files that go into driver cab
  38. REM The final list is in %ListDir%\driver.lst
  39. REM
  40. :CreateList
  41. echo Creating the list of files from %InList%
  42. if EXIST %ListDir% rd /s /q %ListDir%
  43. md %ListDir%
  44. set InList=%_NTTREE%\sorted.lst
  45. REM First remove any duplicates
  46. perl makelist.pl -i %InList% -i %InList% -o %ListDir%\nodupes.lst
  47. REM Now, sort the list
  48. sort %ListDir%\nodupes.lst > %ListDir%\sorted.lst
  49. REM Now, Add the paths
  50. perl makelist.pl -m %ListDir%\sorted.lst -s %_NTTREE% -p -x -o %ListDir%\paths.lst
  51. REM Now, remove the catalog signing stuff at the beginning of this
  52. for /f "tokens=2 delims==" %%a in (%ListDir%\paths.lst) do (
  53. echo %%a>>%FinalList%
  54. )
  55. REM
  56. REM Break it up into several cabs and ddfs
  57. REM
  58. if !TotalCabs! LSS 1 (
  59. echo ERROR: Number of cabs must be >= 1
  60. goto errend
  61. )
  62. if EXIST %DDFDir% rd /s /q %DDFDir%
  63. md %DDFDir%
  64. md %CabDir%
  65. REM
  66. REM Put the header into the top of all the DDF Files
  67. REM
  68. :CreateDDFHeader
  69. echo Creating %TotalCabs% DDF headers in %DDFDir%
  70. if EXIST %DDFDir%\%CabName%*.ddf del /f %DDFDir%\%CabName%*.ddf
  71. set /a count=1
  72. set /a TotalFileSize=0
  73. :CreateDDFHeaderLoop
  74. set CurDDF=%DDFDir%\%CabName%!count!.ddf
  75. echo ^.Option Explicit>>%CurDDF%
  76. REM If there's only 1 cab, no merging is needed
  77. REM Put the destination as the final destination
  78. REM and the name of the cab as the final name
  79. if "!TotalCabs!" EQU "1" (
  80. echo ^.Set DiskDirectoryTemplate=%DestDir%>>%CurDDF%
  81. echo ^.Set CabinetName1=%CabName%.cab>>%CurDDF%
  82. ) else (
  83. echo ^.Set DiskDirectoryTemplate=%CabDir%>>%CurDDF%
  84. echo ^.Set CabinetName1=%CabName%!count!.cab>>%CurDDF%
  85. )
  86. echo ^.Set MaxDiskSize=CDROM>>%CurDDF%
  87. echo ^.Set CompressionType=LZX>>%CurDDF%
  88. echo ^.Set CompressionMemory=21>>%CurDDF%
  89. echo ^.Set CompressionLevel=1 >>%CurDDF%
  90. echo ^.Set Compress=ON>>%CurDDF%
  91. echo ^.Set Cabinet=ON>>%CurDDF%
  92. echo ^.Set UniqueFiles=ON>>%CurDDF%
  93. echo ^.Set FolderSizeThreshold=1000000>>%CurDDF%
  94. echo ^.Set MaxErrors=300>>%CurDDF%
  95. set /a count=!count!+1
  96. if !count! LEQ %TotalCabs% goto CreateDDFHeaderLoop
  97. REM
  98. REM If there is only going to be one cab
  99. REM just create it, don't go through all of this
  100. REM
  101. if "!TotalCabs!" EQU "1" (
  102. type %FinalList%>>%DDFDir%\%CabName%.ddf
  103. makecab /F %DDFDir%\%CabName%.ddf
  104. goto end
  105. )
  106. REM
  107. REM Compute the total size of all the files
  108. REM
  109. :CountFileSize
  110. echo Computing the total size of all the files
  111. set /a TotalFileSize=0
  112. for /f %%a in (%FinalList%) do (
  113. set /a line=0
  114. for /f "usebackq tokens=3 delims= " %%b in (`dir /-c %%a`) do (
  115. set /a line="!line!+1"
  116. if !line! EQU 4 (
  117. set /a TotalFileSize="!TotalFileSize!+%%b"
  118. echo %%a %%b>>%FileSizes%
  119. )
  120. )
  121. )
  122. echo ---Total File Size = !TotalFileSize!
  123. set /a Threshold=!TotalFileSize!/%TotalCabs%
  124. echo ---Threshold for each cab = %Threshold%
  125. REM
  126. REM Add the files to the DDF's
  127. REM Create the makefile at the same time
  128. REM
  129. :CreateDDFs
  130. echo Adding the files to the DDF's
  131. set /a cabnum=1
  132. set /a FileSize=0
  133. for /f "tokens=1,2 delims= " %%a in (%FileSizes%) do (
  134. REM Echo the file to the current ddf
  135. echo %%a>>%DDFDir%\%CabName%!cabnum!.ddf
  136. set /a FileSize="!FileSize!+%%b"
  137. REM If this has crossed the threshold, go to the next DDF
  138. if !FileSize! GTR %Threshold% (
  139. set /a cabnum="!cabnum!+1"
  140. set /a FileSize=0
  141. )
  142. )
  143. if "!cabnum!" GTR "%TotalCabs%" (
  144. echo "ERROR: The CreateDDFs loop has a cab number that is too high
  145. goto errend
  146. )
  147. REM
  148. REM Create a makefile
  149. REM
  150. REM
  151. REM Create the cabs
  152. REM
  153. :CreateCabs
  154. echo Kicking off cab generation
  155. if /i EXIST %DDFDir%\*.txt del /f /q %DDFDir%\*.txt
  156. set /a cabnum=1
  157. :CreateCabsLoop
  158. start "drvcabgen %DDFDir%\%CabName%!cabnum!.ddf" /MIN cmd /c "drvcabgen %DDFDir% %CabName%!cabnum!"
  159. set /a cabnum="!cabnum+1"
  160. if !cabnum! LEQ %TotalCabs% (
  161. sleep 1
  162. goto CreateCabsLoop
  163. )
  164. REM
  165. REM Wait for the cabs to finish
  166. REM
  167. echo Waiting for temporary driver cabs to finish
  168. :WaitCabs
  169. sleep 5
  170. if EXIST %DDFDir%\*.txt goto WaitCabs
  171. REM
  172. REM Merge all of the cabs
  173. REM
  174. :MergeCabs
  175. echo Merging the cabs in %CabDir% into %DestDir%\%CabName%.cab
  176. set /a cabnum=1
  177. set MergeCommand=load %CabDir%\%CabName%!cabnum!.cab
  178. :MergeAdd
  179. set /a cabnum="!cabnum!+1"
  180. if !cabnum! GTR %TotalCabs% goto MergeFinal
  181. set MergeCommand=!MergeCommand! load %CabDir%\%CabName%!cabnum!.cab merge
  182. goto MergeAdd
  183. :MergeFinal
  184. set MergeCommand=%MergeCommand% save %DestDir%\%CabName%.cab
  185. cabbench.exe %MergeCommand%
  186. echo %DestDir%\%CabName%.cab is finished
  187. goto end
  188. :end
  189. echo *** %DestDir%\%CabName%.cab has finished!!
  190. endlocal
  191. goto :EOF
  192. :errend
  193. echo *** %DestDir%\%CabName%.cab had ERRORS!!
  194. endlocal
  195. goto :EOF
  196. :Usage
  197. echo %0 <creates a driver cab file for your machine>
  198. :exit
  199. endlocal