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.

287 lines
7.8 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM DMDGenericCabber.cmd - Imranp,NSBLD
  4. @REM Generic cab script.
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @if NOT defined HOST_PROCESSOR_ARCHITECTURE set HOST_PROCESSOR_ARCHITECTURE=%PROCESSOR_ARCHITECTURE%
  10. @perl -x "%~f0" %*
  11. @goto :EOF
  12. #!perl
  13. use lib $ENV{RAZZLETOOLPATH};
  14. use Logmsg;
  15. ###############################################################################
  16. { # Begin Main Package
  17. ###############################################################################
  18. # ParseArgs is designed to remap some args to global variables.
  19. sub ParseArgs
  20. {
  21. ## First, handle the usage case
  22. if (
  23. ( grep(/-\?/,$ARGV[0]) ) ||
  24. ( grep(/^$/,$ARGV[0]) ) ||
  25. ( $#ARGV != 2 )
  26. )
  27. {
  28. print "
  29. Usage:
  30. DMDGenericCabber.cmd CabDirectory OutputCab DeltaOutputName
  31. Example:
  32. DMDGenericCabber.cmd %_NTTREE%\WMS %_NTTREE%\WMS.cab %_NTTREE%\WMSOCM.*
  33. \n";
  34. logmsg( "END Execution" );
  35. exit 0;
  36. }
  37. ## Return Args.
  38. return ( $ARGV[0],$ARGV[1],$ARGV[2] );
  39. } ## End Sub
  40. ###############################################################################
  41. # ErrorHandler logs error messages for us.
  42. sub ErrorHandler
  43. {
  44. logmsg( " ERROR: $_[0] " );
  45. exit ( 1 );
  46. }
  47. ###############################################################################
  48. # GetHeader is a function that returns a string[] with a Header approved
  49. # by BarbKess for MediaServer -- modified by imranp for Being generic
  50. sub GetHeader
  51. {
  52. ## Declare a header A bit messy.
  53. local @lstHeader = ".Option Explicit
  54. .Set DiskDirectoryTemplate=DDDD
  55. .Set CabinetNameTemplate=ZZZZ
  56. .Set CompressionType=LZX
  57. .Set MaxDiskSize=CDROM
  58. .Set Compress=on
  59. .Set Cabinet=on
  60. .Set CompressionMemory=21
  61. .Set InfFileName=nul
  62. .Set RptFileName=nul
  63. ";
  64. ## Now, substitute the cab name for ZZZZ
  65. my $strRemadeString;
  66. $strRemadeString = $_[1] ;
  67. ## Break it into tokens
  68. my @lstTokensOfFinalCab;
  69. @lstTokensOfFinalCab = split ( /\\/,$strRemadeString );
  70. $strRemadeString =~ s/$lstTokensOfFinalCab[$#lstTokensOfFinalCab]//;
  71. $strRemadeString =~ s/\\$//;
  72. foreach $strPieceOfHeader ( @lstHeader )
  73. {
  74. $strPieceOfHeader =~ s/DDDD/$strRemadeString/i;
  75. $strPieceOfHeader =~ s/ZZZZ/$lstTokensOfFinalCab[$#lstTokensOfFinalCab]/i;
  76. }
  77. return ( @lstHeader );
  78. }
  79. ###########################################################################################################
  80. # RemakeMetaStringAsLiteral takes a metastring ( $.*?\ ) and makes it into an escaped string.
  81. sub RemakeMetaStringAsLiteral
  82. {
  83. local $strInputString; ## remember, pass by value, not reference in this call.
  84. $strInputString = $_[0];
  85. local @lstOfMetaChars;
  86. ## The list of MetaCharacters I currently know about.
  87. push(@lstOfMetaChars,"\\\\");
  88. push(@lstOfMetaChars,"\\\$");
  89. push(@lstOfMetaChars,"\\\.");
  90. push(@lstOfMetaChars,"\\\*");
  91. push(@lstOfMetaChars,"\\\?");
  92. push(@lstOfMetaChars,"\\\'");
  93. push(@lstOfMetaChars,"\\\{");
  94. push(@lstOfMetaChars,"\\\}");
  95. foreach my $strMetachar (@lstOfMetaChars)
  96. {
  97. if ( grep (/$strMetachar/,$strInputString) )
  98. {
  99. $strInputString =~ s/$strMetachar/$strMetachar/g;
  100. }
  101. }
  102. return ( $strInputString );
  103. }
  104. ###############################################################################
  105. # Cleanup Cleans up the directories before doing anything.
  106. sub CleanUp
  107. {
  108. ## Put the parameter into a useful named var
  109. my $strDirectoryToClean;
  110. $strDirectoryToClean = $_[0];
  111. ## Hard-code a list of bad extensions.
  112. my @lstBadExtensions;
  113. push( @lstBadExtensions,".cat" );
  114. push( @lstBadExtensions,".cdf" );
  115. push( @lstBadExtensions,".ddf" );
  116. ## Remove any files in the dir with the extensions
  117. chomp $strDirectoryToClean;
  118. if ( grep(/[a..z]/,$strDirectoryToClean) )
  119. {
  120. foreach $strDeleteThisExtension ( @lstBadExtensions )
  121. {
  122. my $strDeleteMe = $strDirectoryToClean . '\\*' . $strDeleteThisExtension;
  123. print `del /s /q $strDeleteMe`;
  124. }
  125. }
  126. }
  127. ###############################################################################
  128. # RenameDeltaFiles moves the delta.*, and renames it.
  129. sub RenameDeltaFiles
  130. {
  131. my $strDeltaHere,$strDeltaProcess;
  132. ($strDeltaHere,$strDeltaProcess) = ($_[0],$_[1]);
  133. ## Take the filename, and make it into a token list, remove the final token from the string.
  134. my @lstTokensOfFinalDelta;
  135. @lstTokensOfFinalDelta = split ( /\\/,$strDeltaProcess );
  136. $strDeltaProcess =~ s/$lstTokensOfFinalDelta[$#lstTokensOfFinalDelta]//;
  137. $strDeltaProcess =~ s/\\$//;
  138. ## Actually rename the file here.
  139. chomp $lstTokensOfFinalDelta[$#lstTokensOfFinalDelta];
  140. print `pushd $strDeltaHere & rename delta.* $lstTokensOfFinalDelta[$#lstTokensOfFinalDelta] & popd`;
  141. ## Now, move the files to the location specified as part of the arguments.
  142. print `pushd $strDeltaHere & move $lstTokensOfFinalDelta[$#lstTokensOfFinalDelta] $strDeltaProcess & popd`;
  143. }
  144. ###############################################################################
  145. # CreateFile is a generic file procedure.
  146. # Parameters:
  147. # Code1, Code2, FileName, Data.
  148. # Code1 = AppendCode (0 = overwrite, 1 = append)
  149. # Code2 = AttribCode (0 = R/W, 1 = R/O, 2+ = undef)
  150. sub CreateFile
  151. {
  152. local $nAppendCode,$nAttribCode,$strFile,@lstData;
  153. $nAppendCode=shift @_;
  154. $nAttribCode=shift @_;
  155. $strFile=shift@_;
  156. @lstData=@_;
  157. if ( $nAppendCode==0 )
  158. {
  159. open(HANDLE,">$strFile") || ErrorHandler "Could not open file $strFile for write";
  160. foreach $strDatum (@lstData)
  161. {
  162. print HANDLE $strDatum;
  163. }
  164. close HANDLE;
  165. }
  166. elsif ( $nAppendCode==1 )
  167. {
  168. open(HANDLE,">>$strFile") || ErrorHandler "Could not open file $strFile for append.";
  169. foreach $strDatum (@lstData)
  170. {
  171. print HANDLE $strDatum;
  172. }
  173. close HANDLE;
  174. }
  175. if ( $nAttribCode == 0 )
  176. {
  177. }
  178. elsif ( $nAttribCode == 1 )
  179. {
  180. `attrib +r $strFile`;
  181. }
  182. }
  183. ###############################################################################
  184. ## void main()
  185. {
  186. logmsg( "BEGIN Execution" );
  187. local $g_strOutPutDirectory,$g_strOutPutCab,$g_strRenameDelta;
  188. ( $g_strOutPutDirectory,$g_strOutPutCab,$g_strRenameDelta ) = ParseArgs();
  189. ## Get the header made.
  190. my @lstGeneratedHeader;
  191. @lstGeneratedHeader = GetHeader( $g_strOutPutDirectory,$g_strOutPutCab );
  192. ## Since we might do incrementals, let's be paranoid
  193. CleanUp( $g_strOutPutDirectory );
  194. ## Get the list of files in the directory
  195. my @lstFilesInDirectory;
  196. @lstFilesInDirectory = `dir /s /a-d /b $g_strOutPutDirectory 2>&1`;
  197. ## Add Begin and end quotes to each line.
  198. foreach $strAddQuotesToMe ( @lstFilesInDirectory )
  199. {
  200. chomp $strAddQuotesToMe;
  201. $strAddQuotesToMe = '"' . $strAddQuotesToMe . '"' ."\n";
  202. }
  203. ## merge this together
  204. local @lstDDFFile;
  205. @lstDDFFile = @lstGeneratedHeader;
  206. push( @lstDDFFile,@lstFilesInDirectory );
  207. ## Now, let's sign the sucker.
  208. logmsg( "Calling deltacat" );
  209. print `$ENV{'RAZZLETOOLPATH'}\\deltacat.cmd $g_strOutPutDirectory`;
  210. RenameDeltaFiles( $g_strOutPutDirectory,$g_strRenameDelta );
  211. ## Now, let's go out and flush the DDF.
  212. my @lstTemp,$strDDFName;
  213. @lstTemp = split( /\\/,$g_strOutPutCab );
  214. $strDDFName = $lstTemp[$#lstTemp];
  215. $strDDFName =~ s/\.cab/.ddf/;
  216. if ( grep(/\\$/,$g_strOutPutDirectory) )
  217. {
  218. $strDDFName = $g_strOutPutDirectory . $strDDFName;
  219. }
  220. else
  221. {
  222. $strDDFName = $g_strOutPutDirectory . '\\' . $strDDFName;
  223. }
  224. CreateFile( 0,0,$strDDFName,@lstDDFFile );
  225. ## Begin Cabbing
  226. logmsg ( "Begin Cabbing $strDDFName" );
  227. `$ENV{'RAZZLETOOLPATH'}\\$ENV{'HOST_PROCESSOR_ARCHITECTURE'}\\makecab.exe /f $strDDFName`;
  228. if ( -f $g_strOutPutCab )
  229. {
  230. logmsg( "Complete Execution" );
  231. }
  232. else
  233. {
  234. ErrorHandler( "Failed to create $g_strOutPutCab" );
  235. }
  236. }
  237. ################################################################################
  238. } ## end main package