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.

320 lines
7.6 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM chgsfcinf.cmd
  5. REM Change SFC INF file for system files protection for MUI language neutral
  6. REM resource file
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use File::Basename;
  16. use IO::File;
  17. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  18. use lib $ENV{RAZZLETOOLPATH};
  19. use PbuildEnv;
  20. use ParseArgs;
  21. use Logmsg;
  22. use cksku;
  23. require Exporter;
  24. BEGIN {
  25. $ENV{SCRIPT_NAME} = 'chgsfcinf.cmd';
  26. }
  27. sub Usage { print<<USAGE; exit(1) }
  28. cghsfcinf [-p Path_of_SFCGEN.INF ]
  29. USAGE
  30. # Global variables
  31. my ($Neutral_LogDir);
  32. my( $INFPath);
  33. my( $LogFilename );
  34. my( $TempDir );
  35. my( $nttree, $razpath, $TempDir, $fNeedGenerateCMF, $lang);
  36. ##################
  37. #
  38. # parse command line
  39. #
  40. ##################
  41. parseargs( '?' => \&Usage,
  42. 'p:' => \$INFPath,
  43. 'l:' => \$lang
  44. );
  45. &Main();
  46. #
  47. # Check if Language Neutral is enabled or not
  48. #
  49. sub IsLGNActivated()
  50. {
  51. my ($MUI_MAGIC, $Result);
  52. $Result = 0;
  53. $MUI_MAGIC= $ENV{ "MUI_MAGIC" };
  54. if ( defined($MUI_MAGIC))
  55. {
  56. $Result=1;
  57. }
  58. return $Result
  59. }
  60. sub IsCMFActivated()
  61. {
  62. my ($MUI_MAGIC_CMF, $Result);
  63. $Result = 0;
  64. $MUI_MAGIC_CMF= $ENV{ "MUI_MAGIC_CMF" };
  65. if ( defined($MUI_MAGIC_CMF))
  66. {
  67. $Result=1;
  68. }
  69. return $Result
  70. }
  71. sub Main
  72. {
  73. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  74. # Begin Main code section
  75. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  76. # Return when you want to exit on error
  77. #
  78. my ($Mylang, $Line, $MyError, $Result,$SectionName);
  79. my( $Sectionname,@ItemsList , @ItemsInSection, $nStart, $nEnd);
  80. my (@MuiWildCardList, $Items_No, $Index, $BackupName, $FileName);
  81. if (! &IsLGNActivated())
  82. {
  83. return 0;
  84. }
  85. if ( ! defined($lang))
  86. {
  87. $lang = $ENV{LANG};
  88. if (! defined($lang))
  89. {
  90. $lang="usa";
  91. }
  92. }
  93. $Mylang="\L$lang";
  94. if ( ($Mylang ne "usa" ) && ($Mylang ne "psu" ) )
  95. {
  96. return 0;
  97. }
  98. #
  99. # Check If CMF is enabled
  100. #
  101. $fNeedGenerateCMF=&IsCMFActivated();
  102. $nttree = $ENV{ "_NTPostBld" };
  103. $razpath= $ENV{ "RazzleToolPath" };
  104. $TempDir = $ENV{ "TMP" };
  105. $Logmsg::DEBUG = 0; # set to 1 to activate logging of dbgmsg's
  106. $LogFilename = $ENV{ "LOGFILE" };
  107. if ( ! defined( $LogFilename ) )
  108. {
  109. $TempDir = $ENV{ "TMP" };
  110. $LogFilename = "$TempDir\\$0.log";
  111. }
  112. $Neutral_LogDir = $nttree."\\build_logs\\LgNeutral";
  113. $MyError = 0;
  114. #
  115. # Check Language Neutral working directory
  116. #
  117. if ( ! -d $Neutral_LogDir)
  118. {
  119. system( "md $Neutral_LogDir");
  120. }
  121. unless (-d $Neutral_LogDir)
  122. {
  123. errmsg("Fatal: Directory $Neutral_LogDir does not exist");
  124. $MyError=1;
  125. }
  126. #
  127. # Check SFC INF File
  128. #
  129. if (! defined($INFPath))
  130. {
  131. $INFPath = $nttree."\\congeal_scripts\\sfcgen.inf";
  132. }
  133. if (! -e $INFPath)
  134. {
  135. errmsg("Fatal: SFC INF file: $INFPath doesn't exist");
  136. $MyError = 1;
  137. }
  138. if ($MyError != 0 )
  139. {
  140. exit(1);
  141. }
  142. unless ( open(INFILE, $INFPath) )
  143. {
  144. errmsg("Fatal: Can't open $INFPath");
  145. exit(1);
  146. }
  147. @ItemsList =<INFILE>;
  148. close(INFILE);
  149. $SectionName="FILELIST.HEADERFILES";
  150. if (!&ReadSection($SectionName,\@ItemsList,\@ItemsInSection,\$nStart,\$nEnd))
  151. {
  152. errmsg(" Can't Read $SectionName of $INFPath");
  153. exit(1);
  154. }
  155. #
  156. # Check if *.mui/*.cmf in the section
  157. #
  158. if ($fNeedGenerateCMF)
  159. {
  160. @MuiWildCardList=grep /\s*\*\.cmf/i , @ItemsInSection;
  161. }
  162. else
  163. {
  164. @MuiWildCardList=grep /\s*\*\.mui/i , @ItemsInSection;
  165. }
  166. $Items_No=scalar(@MuiWildCardList);
  167. #
  168. # Do nothing if items already exitsts
  169. #
  170. if ($Items_No != 0)
  171. {
  172. logmsg( " *.MUI/.CMF already in $INFPath, no action needed");
  173. exit(0);
  174. }
  175. #
  176. # Add *.mui to sfcgen.INF
  177. #
  178. # Backup the origional one.
  179. $BackupName = $Neutral_LogDir."sfcgen.inf.bak";
  180. if ( system ("copy/y $INFPath $BackupName") != 0 )
  181. {
  182. #errmsg(" Can't backup $INFPath to $BackupName");
  183. exit(1);
  184. }
  185. # Add the entry
  186. logmsg("INF: $INFPath");
  187. system("attrib -r $INFPath");
  188. #system("del /f $INFPath");
  189. #logmsg("Reset Readonly Mode for $INFPath");
  190. unless ( open(OUTFILE, ">$INFPath") )
  191. {
  192. errmsg(" Can not open output for $INFPath");
  193. exit(1);
  194. }
  195. $Index = -1;
  196. foreach $Line (@ItemsList)
  197. {
  198. chomp($Line);
  199. $Index++;
  200. if ($Index == ($nStart + 1) )
  201. {
  202. if ($fNeedGenerateCMF)
  203. {
  204. print ( OUTFILE "*.cmf\n" );
  205. }
  206. else
  207. {
  208. print ( OUTFILE "*.mui\n" );
  209. }
  210. }
  211. print (OUTFILE "$Line\n");
  212. }
  213. close (OUTFILE);
  214. logmsg ("add *.mui/.cmf to $INFPath successfully");
  215. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  216. # End Main code section
  217. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  218. }
  219. sub ReadSection
  220. {
  221. my ($Section, $pItemsList, $pItemsInSection, $pnStart, $pnEnd) = @_;
  222. my ($Index, $SectionStart, $SectionEnd, $Line, $Line_Org, $ReadFlag, $Result);
  223. $ReadFlag = "FALSE";
  224. $Index= -1;
  225. $SectionStart = -1;
  226. $SectionEnd = -1;
  227. $Result = 0;
  228. #
  229. # Read The section
  230. #
  231. foreach $Line_Org (@$pItemsList)
  232. {
  233. $Line = $Line_Org;
  234. chomp($Line);
  235. $Index++;
  236. if ( (length($Line) == 0) || (substr($Line,0,1) eq ";") || (substr($Line,0,1) eq "#") )
  237. {
  238. if ( $ReadFlag eq "TRUE" )
  239. {
  240. push (@$pItemsInSection, $Line_Org);
  241. }
  242. next;
  243. }
  244. if ( $Line =~ /^\[/ )
  245. {
  246. $ReadFlag = "FALSE";
  247. if ( $SectionStart != -1)
  248. {
  249. $SectionEnd = $Index-1;
  250. }
  251. }
  252. if ( $Line =~ /^\[$Section\]/ ) # pattern in $Section !!!
  253. {
  254. logmsg("Section Found");
  255. $ReadFlag = "TRUE";
  256. $SectionStart=$Index;
  257. }
  258. if ($ReadFlag eq "TRUE")
  259. {
  260. push(@$pItemsInSection, $Line_Org);
  261. }
  262. }
  263. if ( $SectionStart != -1)
  264. {
  265. if ( $SectionEnd == -1)
  266. {
  267. $SectionEnd = $Index;
  268. }
  269. $Result = 1;
  270. $$pnStart = $SectionStart;
  271. $$pnEnd = $SectionEnd;
  272. }
  273. return $Result;
  274. }