Leaked source code of windows server 2003
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.

589 lines
20 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM copywow64.cmd - WadeLa
  4. @REM Copy appropriate 32bit files from a release into a 64bit build
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM ------------------------------------------------------------------
  9. @if defined _CPCMAGIC goto CPCBegin
  10. @perl -x "%~f0" %*
  11. @goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. sub Usage { print<<USAGE; exit(1) }
  19. copywow64 [-l <language>]
  20. Copy appropriate 32bit files from a release into a 64bit build.
  21. If _NTWOWBINSTREE is set that is the location 32bit files will be
  22. copied from.
  23. USAGE
  24. parseargs('?' => \&Usage);
  25. # *** TEMPLATE CODE ***
  26. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  27. __END__
  28. @:CPCBegin
  29. @set _CPCMAGIC=
  30. @setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  31. @if not defined DEBUG echo off
  32. @REM *** CMD SCRIPT BELOW ***
  33. REM This script generates a list of wow32 binaries to be copied from
  34. REM a 32 bit machine. The list itself is generated on the 64 bit machine
  35. REM Bail if your not on a 64 bit machine
  36. if /i "%_BuildArch%" neq "ia64" (
  37. if /i "%_BuildArch%" neq "amd64" (
  38. call logmsg.cmd "Not Win64, exiting."
  39. goto :End
  40. )
  41. )
  42. REM define comp if it's not already defined
  43. if NOT defined Comp (
  44. set Comp=No
  45. if %NUMBER_OF_PROCESSORS% GEQ 4 set Comp=Yes
  46. if defined OFFICIAL_BUILD_MACHINE set Comp=Yes
  47. )
  48. REM First find the latest build from which to copy the binaries
  49. if defined _NTWoWBinsTREE (
  50. set SourceDir=%_NTWoWBinsTREE%
  51. goto :EndGetBuild
  52. )
  53. REM read the copy location from build_logs\CPLocation.txt
  54. set CPFile=%_NTPOSTBLD%\build_logs\CPLocation.txt
  55. if not exist %CPFile% (
  56. call logmsg.cmd "Copy Location file not found, will attempt to create ..."
  57. call %RazzleToolPath%\PostBuildScripts\CPLocation.cmd -l:%lang%
  58. if not exist %CPFile% (
  59. call errmsg.cmd "CPLocation.cmd failed, exiting ..."
  60. goto :End
  61. )
  62. )
  63. for /f "delims=" %%a in ('type %CPFile%') do set CPLocation=%%a
  64. if not exist %CPLocation% (
  65. call logmsg.cmd "Copy Location from %CPFile% does not exist, retry ..."
  66. call %RazzleToolPath%\PostBuildScripts\CPLocation.cmd -l:%lang%
  67. if not exist %CPFile% (
  68. call errmsg.cmd "CPLocation.cmd failed, exiting ..."
  69. goto :End
  70. )
  71. for /f "delims=" %%a in ('type %CPFile%') do set CPLocation=%%a
  72. if not exist !CPLocation! (
  73. call errmsg.cmd "Copy Location !CPLocation! does not exist ..."
  74. goto :End
  75. )
  76. )
  77. call logmsg.cmd "Copy Location is set to %CPLocation% ..."
  78. set SourceDir=%CPLocation%
  79. :EndGetBuild
  80. if not exist %SourceDir% (
  81. call errmsg.cmd "The source dir %SourceDir% does not exist ..."
  82. goto :End
  83. )
  84. REM Now compare the services.tab files from the 32-bit build and
  85. REM the 64-bit build and make sure they're identical
  86. call logmsg.cmd "Verifying services.tab..."
  87. if not exist %SourceDir%\ntsv6432\kesvc32.tab (
  88. call logmsg.cmd "%SourceDir%\ntsv6432\kesvc32.tab not found"
  89. goto :CompFailed
  90. )
  91. if not exist %_NTPOSTBLD%\ntsv6432\kesvc.tab (
  92. call logmsg.cmd "%_NTPOSTBLD%\ntsv6432\kesvc.tab not found"
  93. goto :CompFailed
  94. )
  95. fc /w %SourceDir%\ntsv6432\kesvc32.tab %_NTPOSTBLD%\ntsv6432\kesvc.tab >Nul
  96. if %ERRORLEVEL% NEQ 0 (
  97. call logmsg.cmd "services.tab [kernel] comparison failed"
  98. goto :CompFailed
  99. )
  100. if not exist %SourceDir%\ntsv6432\guisvc32.tab (
  101. call logmsg.cmd "%SourceDir%\ntsv6432\guisvc32.tab not found"
  102. goto :CompFailed
  103. )
  104. if not exist %_NTPOSTBLD%\ntsv6432\guisvc.tab (
  105. call logmsg.cmd "%_NTPOSTBLD%\ntsv6432\guisvc.tab not found"
  106. goto :CompFailed
  107. )
  108. fc /w %SourceDir%\ntsv6432\guisvc32.tab %_NTPOSTBLD%\ntsv6432\guisvc.tab >Nul
  109. if %ERRORLEVEL% == 0 (
  110. call logmsg.cmd "services.tab comparison successful"
  111. goto :CompSucceeded
  112. )
  113. :CompFailed
  114. if defined OFFICIAL_BUILD_MACHINE (
  115. call errmsg.cmd "services.tab [gui] comparison failed"
  116. goto :END
  117. ) else (
  118. echo.
  119. call logmsg.cmd "--------------- WARNING: ---------------------------
  120. call logmsg.cmd "This Win64 build has a services.tab that's "
  121. call logmsg.cmd "incompatible with the 32-bit build used by Wow64."
  122. call logmsg.cmd "If the new services.tab entry you added isn't"
  123. call logmsg.cmd "located at the end of the file, then don't expect"
  124. call logmsg.cmd "32-bit component registration during 64-bit GUI "
  125. call logmsg.cmd "setup to work. Basically, 32-bit apps won't work on "
  126. call logmsg.cmd "this build."
  127. echo.
  128. )
  129. : CompSucceeded
  130. REM Set the Destination directory
  131. set DestDir=!_NTPostBld!\wowbins
  132. set UnCompDestDir=!_NTPostBld!\wowbins_uncomp
  133. REM Set the rest
  134. set outputfile=%tmp%\copywowlist.txt
  135. set WowMiss=%tmp%\MissingWowFiles.txt
  136. call logmsg.cmd "Copying files from %SourceDir%"
  137. REM Delete the output file if it already exists
  138. if exist %tmp%\copywowlist.txt del /f %tmp%\copywowlist.txt
  139. if exist %tmp%\copywowlist1 del /f %tmp%\copywowlist1
  140. pushd %_NTPostBld%\congeal_scripts
  141. REM File compare the x86 and 64-bit layout.inf
  142. REM If they are different log a warning
  143. fc %SourceDir%\congeal_scripts\layout.inx layout.inx 2>Nul 1>Nul
  144. if /i NOT "%ErrorLevel%" == "0" (
  145. call logmsg.cmd /t "WARNING: the x86 build machine's layout.inx is different than this machine's - continuing"
  146. )
  147. if /i "%Comp%" == "No" (
  148. if exist !DestDir! (
  149. if exist !UnCompDestDir! rd /s /q !UnCompDestDir!
  150. if exist !DestDir! move !DestDir! !UnCompDestDir!
  151. )
  152. )
  153. REM Make the dosnet.tmp1 list: file with filenames and Media IDs.
  154. for %%a in (p w s e d b l @) do (
  155. copy /b layout.inx+layout.txt dosnet.tmp1
  156. prodfilt dosnet.tmp1 dosnet.tmp2 +%%a
  157. prodfilt dosnet.tmp2 dosnet.tmp1 +i
  158. wowlist -i dosnet.tmp1 -c wowlist.inf -f w -o dosnet.tmp2 -ac -p 2>NUL
  159. copy /b dosnet.tmp2+wowexcp.txt dosnet.tmp1
  160. copy /b layout.inx+layout.txt layout64.tmp1
  161. prodfilt layout64.tmp1 layout64.tmp2 +w
  162. prodfilt layout64.tmp2 layout64.tmp1 +m
  163. REM Process dosnet.tmp1 using layout64.tmp1 to get appropriate
  164. REM folder relative to \i386 and prepend to the entry before writing out to the outputfile
  165. call ExecuteCmd "perl %RazzleToolPath%\postbuildscripts\Copywowlist.pl layout64.tmp1 dosnet.tmp1 %outputfile%"
  166. if not %%a == @ (
  167. copy %outputfile% %_NTPostBld%\congeal_scripts\copywowlist_%%a.txt
  168. perl -ne "@a=split/:/;chomp @a;$a[1]=~s/^(.*)(.)$/\1/;print $a[1].\"*\n\"" copywowlist_%%a.txt > copywowlist_%%a.lst
  169. ) else (
  170. copy %outputfile% %_NTPostBld%\congeal_scripts\copywowlist.txt
  171. )
  172. )
  173. if not exist !UnCompDestDir! md !UnCompDestDir!
  174. if /i "%Comp%" == "Yes" (
  175. if not exist !DestDir! md !DestDir!
  176. )
  177. REM Convert "<relative_src>:<destination>" format into "<relative_src>,<relative_dest>,<full_dest>" format
  178. perl -ne "if ( /(.*\\)?([^\\]+):(.*)/ ) {print qq($1$2,$1$3,$ENV{DestDir}\\$1$3\n)} else {print STDERR qq(WARNING: UNRECOGNIZED LINE ($_)\n)}" %outputfile% >%tmp%\WowStuff.txt
  179. REM ren files back to original name so that incremental compdir works.
  180. for /f "tokens=1,2 delims=," %%a in (%tmp%\WowStuff.txt) do (
  181. if exist %UnCompDestDir%\%%b ren %UnCompDestDir%\%%b %%~nxa
  182. )
  183. rem Reduce the number of calls to compdir.
  184. call :WRAP_COMPDIR %SourceDir% %UnCompDestDir% %outputfile%
  185. REM if exist dosnet.tmp1 del dosnet.tmp1
  186. REM if exist dosnet.tmp2 del dosnet.tmp2
  187. popd
  188. REM copy special wow6432 files over top of the stock versions
  189. REM Can't use /d because the wow6432 files MUST be copied over the same named
  190. REM files from root.
  191. call ExecuteCmd.cmd "xcopy /cyi %SourceDir%\wow6432 %UnCompDestDir%"
  192. REM Rename files to their new wow names
  193. for /f "tokens=1,2 delims=," %%a in (%tmp%\WowStuff.txt) do (
  194. if exist %UnCompDestDir%\%%a ren %UnCompDestDir%\%%a %%~nxb
  195. )
  196. REM Sign it
  197. call ExecuteCmd "deltacat.cmd %UnCompDestDir%"
  198. if exist %UnCompDestDir%\..\wow64.cat (
  199. del %UnCompDestDir%\..\wow64.cat
  200. )
  201. move %UnCompDestDir%\delta.cat %UnCompDestDir%\..\wow64.cat
  202. REM And now sign lang
  203. call ExecuteCmd "deltacat.cmd %UnCompDestDir%\lang"
  204. if exist %UnCompDestDir%\..\wowlang.cat (
  205. del %UnCompDestDir%\..\wowlang.cat
  206. )
  207. move %UnCompDestDir%\lang\delta.cat %UnCompDestDir%\..\wowlang.cat
  208. REM Populate wowbins
  209. if /i "%Comp%" == "Yes" (
  210. call :WRAP_COMPRESS !UnCompDestDir! !DestDir! %_NTPostBld%\congeal_scripts\wowfilesuncomp.lst
  211. REM Copy uncompressed files over as well
  212. for %%a in (%_NTPostBld%\congeal_scripts\wowfilesuncomp.lst) do (
  213. if "0" NEQ "%%~za" CALL ExecuteCmd "compdir /eznu /m:%_NTPostBld%\congeal_scripts\wowfilesuncomp.lst !UnCompDestDir! !DestDir!"
  214. )
  215. ) else (
  216. call ExecuteCmd.cmd "if exist !DestDir! rd /s/q !DestDir!"
  217. call ExecuteCmd.cmd "move !UnCompDestDir! !DestDir!"
  218. )
  219. REM
  220. REM We used to put stuff here, delete for incremental over old builds.
  221. REM
  222. rd /q/s %DestDir%\asms
  223. rd /q/s %DestDir%\wasms
  224. REM
  225. REM Give sxsofflineinstall one merged asms directory to install from.
  226. REM The directory names do clash, so offset by inserting an extra directory level.
  227. REM
  228. REM Note that just like "regular" stuff, the wow6432 files overwrite the
  229. REM "regular" x86 files, so we cannot use /d for incremental, and the order
  230. REM of the two copies must be what it is.
  231. REM
  232. call ExecuteCmd.cmd "xcopy /cyie %SourceDir%\asms %_NTPostBld%\asms\x86"
  233. call ExecuteCmd.cmd "xcopy /cyie %SourceDir%\wow6432\asms %_NTPostBld%\asms\x86"
  234. REM Check that we have all the wow files
  235. if exist !WowMiss! del /f !WowMiss!
  236. for /f "tokens=1-3 delims=," %%a in (%tmp%\WowStuff.txt) do (
  237. if NOT exist %%c (
  238. call :CompName %%c
  239. if NOT exist %%~dpc!CompFileName! (
  240. echo %%a,%%b,%%c >> !WowMiss!
  241. )
  242. )
  243. )
  244. REM If we are missing files we have to wait for the x86 machine
  245. if NOT exist !WowMiss! goto SkipTryAgain
  246. echo Missing WowFiles :
  247. if exist !WowMiss! for /f "tokens=2 delims=," %%a in (!WowMiss!) do @echo %%a
  248. if defined OFFICIAL_BUILD_MACHINE (
  249. echo.
  250. call logmsg.cmd "This 64-bit build machine must now wait for the"
  251. call logmsg.cmd "for corresponding x86 build machine to complete"
  252. call logmsg.cmd "build and postbuild in order to copy wow64 files"
  253. call logmsg.cmd "that are required by setup."
  254. echo.
  255. ) else (
  256. echo.
  257. call logmsg.cmd "You are missing the files listed above."
  258. call logmsg.cmd "This means there will be missing files during setup."
  259. echo.
  260. call logmsg.cmd "This probably occurred because someone in your VBL"
  261. call logmsg.cmd "added new wow64 files to layout.inx, but the VBL x86"
  262. call logmsg.cmd "build machine has not finished it's build with"
  263. call logmsg.cmd "these changes."
  264. echo.
  265. call logmsg.cmd "You MUST UNDERSTAND these missing files"
  266. call logmsg.cmd "before checking in your changes."
  267. echo.
  268. call errmsg.cmd "Continuing with missing wow files."
  269. goto :SkipTryAgain
  270. )
  271. REM
  272. REM if there were failed file copies, then let's generate our copy location
  273. REM again and retry
  274. REM
  275. call %RazzleToolPath%\PostBuildScripts\CPLocation.cmd -l:%lang%
  276. set CPFile=%_NTPOSTBLD%\build_logs\CPLocation.txt
  277. if not exist %CPFile% (
  278. call errmsg.cmd "Failed to find %CPFile%, exiting ..."
  279. goto :End
  280. )
  281. for /f "delims=" %%a in ('type %CPFile%') do set CPLocation=%%a
  282. if not exist %CPLocation% (
  283. call errmsg.cmd "Copy location %CPLocation% not found, exiting ..."
  284. goto :End
  285. )
  286. call logmsg.cmd "Retrying, copying from %CPLocation% ..."
  287. set SourceDir=%CPLocation%
  288. REM Copy and compress the files one by one - there shouldn't be many
  289. REM Note that the file may have been removed so check for existence
  290. REM before attempting to copy
  291. if /i "%Comp%" == "Yes" (
  292. pushd !DestDir!
  293. for /f "tokens=1,2 delims=," %%a in (!WowMiss!) do (
  294. if exist !SourceDir!\%%a (
  295. echo copying %%a from !SourceDir! ...
  296. call ExecuteCmd.cmd "copy !SourceDir!\%%a !UnCompDestDir!\%%b"
  297. findstr /i %%a %_NTPostBld%\congeal_scripts\wowfilesuncomp.lst>NUL
  298. if errorlevel 1 (
  299. echo compressing %%b ...
  300. call ExecuteCmd.cmd "compress -zx21 -r -d -s !UnCompDestDir!\%%b ."
  301. ) else (
  302. echo placing %%b ...
  303. call ExecuteCmd.cmd "copy /Y !UnCompDestDir!\%%b"
  304. )
  305. )
  306. )
  307. for /f "tokens=1,2 delims=," %%a in (!WowMiss!) do (
  308. if exist !SourceDir!\wow6432\%%a (
  309. echo copying %%a from !SourceDir!\wow6432 ...
  310. call ExecuteCmd.cmd "copy !SourceDir!\wow6432\%%a !UnCompDestDir!\%%b"
  311. findstr /i %%a %_NTPostBld%\congeal_scripts\wowfilesuncomp.lst>NUL
  312. if errorlevel 1 (
  313. echo compressing %%b ...
  314. call ExecuteCmd.cmd "compress -zx21 -r -d -s !UnCompDestDir!\%%b ."
  315. ) else (
  316. echo placing %%b ...
  317. call ExecuteCmd.cmd "copy /Y !UnCompDestDir!\%%b"
  318. )
  319. )
  320. )
  321. popd
  322. ) else (
  323. pushd !DestDir!
  324. for /f "tokens=1,2 delims=," %%a in (!WowMiss!) do (
  325. if exist !SourceDir!\%%a (
  326. echo copying %%a from !SourceDir! ...
  327. call ExecuteCmd.cmd "copy !SourceDir!\%%a !DestDir!\%%b"
  328. )
  329. )
  330. for /f "tokens=1,2 delims=," %%a in (!WowMiss!) do (
  331. if exist !SourceDir!\wow6432\%%a (
  332. echo copying %%a from !SourceDir!\wow6432 ...
  333. call ExecuteCmd.cmd "copy !SourceDir!\wow6432\%%a !DestDir!\%%b"
  334. )
  335. )
  336. popd
  337. )
  338. REM Now make sure there are no missing files
  339. if exist !WowMiss! del /f !WowMiss!
  340. for /f "tokens=1-3 delims=," %%a in (%tmp%\WowStuff.txt) do (
  341. if NOT exist %%c (
  342. call :CompName %%c
  343. if NOT exist %%~dpc!CompFileName! (
  344. echo %%a,%%b,%%c >> !WowMiss!
  345. )
  346. )
  347. )
  348. REM Now remake the catalog - It doesn't take very long
  349. REM Also note that catalog signing doesn't care if I compress
  350. REM first or sign first, so we can sign the uncompressed binaries now.
  351. if /i "%Comp%" == "Yes" (
  352. call deltacat.cmd %UnCompDestDir%
  353. if exist %UnCompDestDir%\..\wow64.cat (
  354. del %UnCompDestDir%\..\wow64.cat
  355. )
  356. move %UnCompDestDir%\delta.cat %UnCompDestDir%\..\wow64.cat
  357. copy %tmp%\cdf\delta.cdf %_ntpostbld%\build_logs\copywow64.cdf
  358. copy %tmp%\log\delta.log %_ntpostbld%\build_logs\copywow64.log
  359. ) else (
  360. call deltacat.cmd -d %DestDir%
  361. if exist %DestDir%\..\wow64.cat (
  362. del %DestDir%\..\wow64.cat
  363. )
  364. move %DestDir%\delta.cat %DestDir%\..\wow64.cat
  365. )
  366. REM If the files are missing now we're screwed - log an error
  367. if exist !WowMiss! (
  368. call errmsg.cmd "Missing Wow64 files after x86 build finished - you cannot boot this build."
  369. if exist !WowMiss! for /f "tokens=2 delims=," %%a in (!WowMiss!) do @echo %%a
  370. )
  371. :SkipTryAgain
  372. REM ************************************************
  373. REM ********** BEGIN AMD64 BOOT FILE HACK **********
  374. REM ************************************************
  375. REM
  376. REM the following is necessary because a few 32-bit x86 boot files are copied
  377. REM over to the AMD64 build, but the "nocompress" (_x) directive is not currently
  378. REM honored in wowfile.inx.
  379. REM
  380. if /i "%_BuildArch%" == "amd64" (
  381. call :ExpandWow64 ntldr._ ntldr
  382. call :ExpandWow64 bootfix.bi_ bootfix.bin
  383. call :ExpandWow64 setupldr.bi_ setupldr.bin
  384. call :ExpandWow64 ntdetect.co_ ntdetect.com
  385. )
  386. goto :end
  387. REM
  388. REM Function :ExpandWow64
  389. REM Arguments:
  390. REM %1 - Compressed file name
  391. REM %2 - Expanded file name
  392. REM
  393. :ExpandWow64
  394. if exist %DestDir%\%1 call ExecuteCmd.cmd "expand %DestDir%\%1 %DestDir%\%2"
  395. goto :EOF
  396. REM ************************************************
  397. REM *********** END AMD64 BOOT FILE HACK ***********
  398. REM ************************************************
  399. goto end
  400. REM
  401. REM Function :CompName
  402. REM Arguments : File Name Returns : Compressed File Name
  403. REM
  404. :CompName
  405. for %%a in (%1) do (
  406. set FileName=%%~na
  407. set FileExt=%%~xa
  408. )
  409. if NOT defined FileExt (
  410. set CompFileExt=._
  411. ) else (
  412. set FourthExtChar=!FileExt:~3,1!
  413. if defined FourthExtChar (
  414. set CompFileExt=!FileExt:~0,-1!_
  415. ) else (
  416. set CompFileExt=!FileExt!_
  417. )
  418. )
  419. set CompFileName=!FileName!!CompFileExt!
  420. goto :EOF
  421. :WRAP_COMPDIR
  422. rem =======================================================
  423. rem = %iRawList% parser
  424. rem = groups files by path and feeds compdir
  425. rem = with suitable matchlists
  426. rem =======================================================
  427. SET iSrcPath=%~1
  428. SET iDstPath=%~2
  429. SET iRawList=%3
  430. SET iSrcPath=%iSrcPath: =%
  431. SET iDstPath=%iDstPath: =%
  432. set iSelf=%~n0
  433. set iTmp1=%TEMP%\!iSelf!.parse.1.temp
  434. set iTmp2=%TEMP%\!iSelf!.parse.2.temp
  435. set iTmp3=%TEMP%\!iSelf!.parse.3.temp
  436. rem
  437. rem Step 1. compdir the bare files in %iRawList%
  438. set count=1
  439. set iPlainList=%TEMP%\!iSelf!.compdir.!count!.temp
  440. set iDummyName=!iSelf!.matchlist.!count!.txt
  441. perl -ne "print qq($1\n) if (/^([^\\]+):/)" %iRawList%>!iPlainList!
  442. call :MATCHLIST !iDummyName! %iSrcPath% %iDstPath% !iPlainList!
  443. rem Step 2. Check for the paths in %iRawList%
  444. perl -ne "print qq($1\n) if (/^(.*\\.*):/)" %iRawList%>%iTmp1%
  445. :HAVEDIR
  446. rem Step 3. Loop over the dirs in %iRawList%
  447. for /F %%p in (%iTmp1%) do (
  448. set prefix=%%~dpp&set prefix=!prefix:%CD%=!
  449. set dir=!prefix:~0,-1!&set dir=!dir:~1!
  450. set pattern=!dir!&set pattern=!pattern:\=\\!
  451. rem Step 4. restrict to files in !dir!
  452. set /A count=!count!+1
  453. set iPlainList=%TEMP%\%iSelf%.compdir.!count!.temp
  454. set iDummyName=%TEMP%\%iSelf%.matchlist.!count!.txt
  455. findstr /irc:"!pattern!\\\\" %iTmp1%>%iTmp2%
  456. rem Step 5. Get bare filenames
  457. del !iPlainList!>NUL
  458. for /F %%f in (%iTmp2%) do (set iFile=%%~nxf&echo !iFile!>>!iPlainList!)
  459. rem Step 6. Feed compdir with modified arguments...
  460. rem appending !dir! to !iSrcPath!
  461. call :MATCHLIST !iDummyName! %iSrcPath%\!dir! %iDstPath%\!dir! !iPlainList!
  462. copy %iTmp1% %iTmp3%>NUL
  463. rem Step 7. Remove the !dir!\.. from the %iRawList%: we done with it
  464. findstr /irVc:"!pattern!\\\\" %iTmp3%>%iTmp1%
  465. goto :HAVEDIR
  466. )
  467. del !iTmp1!&del !iTmp2!&del !iTmp3!
  468. goto :EOF
  469. :MATCHLIST
  470. pushd %TEMP%
  471. set iFound=
  472. set iMatchList=%~1
  473. set iSrcPath=%~2
  474. set iDstPath=%~3
  475. set iLisiTmp=%~4
  476. if exist %iMatchList% del %iMatchList%
  477. for /f %%i in (%iLisiTmp%) do (
  478. set iFileTest=%%i
  479. if exist %iSrcPath%\!iFileTest! SET iFound=Y && echo !iFileTest!>>%iMatchList%
  480. rem Step 1. Raise the flag and collect the filename
  481. )
  482. if defined iFound (
  483. call ExecuteCmd.cmd "compdir.exe /enrstdm:%iMatchList% %iSrcPath% %iDstPath%"
  484. )
  485. popd
  486. goto :EOF
  487. :WRAP_COMPRESS
  488. rem =======================================================
  489. rem = compress the contents
  490. rem = of %iSrcPath% in one run
  491. rem =======================================================
  492. pushd %TEMP%
  493. set iSelf=%~n0
  494. set iLstFile=%TEMP%\%iSelf%.compress.list.txt
  495. set iSrcPath=%1
  496. set iDstPath=%2
  497. set iExcludeList=%3
  498. rem Step 1. Generate the tree structure
  499. for /F %%d in ('dir /b/s/ad %iSrcPath%') do (
  500. set iDstDir=%%d&set iDstDir=!iDstDir:%iSrcPath%=%iDstPath%!
  501. if not exist !iDstDir! call ExecuteCmd.cmd "md !iDstDir!")
  502. pushd !iDstDir!
  503. if errorlevel 1 (
  504. call errmsg.cmd "invalid dir !iDstDir!, exiting ..."
  505. goto :End
  506. )
  507. popd
  508. rem Step 2. Generate the list file to compress
  509. if exist %iLstFile% del %iLstFile%
  510. rem only want to compress those files that are supposed to be compressed
  511. for /F %%f in ('perl -e "open F, $ARGV[0];$u{lc$_}=1 foreach <F>;print foreach grep {/([^\\]+)$/ and not exists $u{lc$1}} qx(dir /b/s/a-d $ARGV[1])" %iExcludeList% %iSrcPath%') do (
  512. SET iSrcDir=%%~dpf
  513. set iSrcFile=%%~nxf
  514. set iDstDir=!iSrcDir:%iSrcPath%=%iDstPath%!
  515. call :CompName !iSrcFile!
  516. set iDstFile=!iDstDir!!CompFileName!
  517. set iSrcFile=!iSrcDir!!iSrcFile!
  518. echo !iSrcFile!>>%iLstFile%&echo !iDstFile!>>%iLstFile%
  519. )
  520. call ExecuteCmd.cmd "compress.exe -zx21 -s -d @%iLstFile%"
  521. popd
  522. goto :EOF
  523. :end
  524. seterror.exe "%errors%"& goto :EOF