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.

342 lines
8.0 KiB

  1. package GetIniSetting;
  2. #
  3. # GetIniSetting.pm
  4. #
  5. # Just a utility to read the main.usa.ini file (or whatever branch / lang)
  6. # and return the requested information.
  7. #
  8. # Version 1.0 MikeCarl 07/21/00 Write initial module
  9. #
  10. use strict;
  11. use lib $ENV{ "RazzleToolPath" };
  12. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  13. use Logmsg;
  14. #
  15. # CheckIniFile
  16. #
  17. # Arguments: none
  18. #
  19. # Purpose: validates existence of the appropriate ini file
  20. #
  21. # Returns: true if found, undef otherwise
  22. #
  23. sub CheckIniFile
  24. {
  25. # declare locals
  26. my( $BranchName, $Language );
  27. $BranchName = $ENV{ "_BuildBranch" };
  28. $Language = $ENV{ "lang" };
  29. return &CheckIniFileEx( $BranchName, $Language );
  30. }
  31. #
  32. # CheckIniFileEx
  33. #
  34. # Arguments: $BranchName, $Language
  35. #
  36. # Purpose: validates existence of the appropriate ini file using branch and
  37. # language as passed
  38. #
  39. # Returns: true if found, undef otherwise
  40. #
  41. sub CheckIniFileEx
  42. {
  43. # get passed args
  44. my( $BranchName, $Language ) = @_;
  45. # declare locals
  46. my( $IniFileName );
  47. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  48. "$BranchName.$Language.ini";
  49. if ( ! -e $IniFileName ) {
  50. logmsg( "Ini file $IniFileName not found ..." );
  51. return;
  52. }
  53. logmsg( "Ini file $IniFileName found ..." );
  54. return 1;
  55. }
  56. #
  57. # CheckIniFileQuietEx
  58. #
  59. # Arguments: $BranchName, $Language
  60. #
  61. # Purpose: validates existence of the appropriate ini file using branch and
  62. # language as passed. the difference between this and CheckIniFileEx
  63. # is that we do not log to screen or log file.
  64. #
  65. # Returns: true if found, undef otherwise
  66. #
  67. sub CheckIniFileQuietEx
  68. {
  69. # get passed args
  70. my( $BranchName, $Language ) = @_;
  71. # declare locals
  72. my( $IniFileName );
  73. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  74. "$BranchName.$Language.ini";
  75. if ( ! -e $IniFileName ) { return; }
  76. return 1;
  77. }
  78. #
  79. # GetSetting
  80. #
  81. # Arguments: @FieldNames
  82. #
  83. # Purpose: reads the given field name from the appropriate branch / lang ini
  84. # file. this file is determined through the _BuildBranch and lang
  85. # environment variables. the FieldNames array holds the field and
  86. # subfields to be matched, i.e. ( 'ReleaseServers', 'X86FRE' )
  87. #
  88. # Returns: $FieldValue or undef
  89. #
  90. sub GetSetting
  91. {
  92. # get passed args
  93. my( @FieldNames ) = @_;
  94. # declare locals
  95. my( $BranchName, $Language );
  96. # set up ini file name
  97. $BranchName = $ENV{ "_BuildBranch" };
  98. $Language = $ENV{ "lang" };
  99. # call GetSettingEx with the newly gotten parameters
  100. return &GetSettingEx( $BranchName, $Language, @FieldNames );
  101. }
  102. #
  103. # GetSettingQuietEx
  104. #
  105. # Arguments: @FieldNames, $BranchName, $Language
  106. #
  107. # Purpose: reads the given field name from the appropriate branch / lang ini
  108. # file.
  109. #
  110. # Returns: $FieldValue or undef
  111. #
  112. sub GetSettingQuietEx
  113. {
  114. # get passed args
  115. my( $BranchName, $Language, @FieldNames ) = @_;
  116. # declare locals
  117. my( $IniFileName );
  118. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  119. "$BranchName.$Language.ini";
  120. # check variables
  121. if ( !$BranchName || !$Language || ( ! -e $IniFileName ) ) {
  122. # error, don't log as we're quiet
  123. return;
  124. }
  125. ParseFileQuiet( $BranchName, $Language, $IniFileName, @FieldNames );
  126. }
  127. sub ParseFileQuiet
  128. {
  129. # get passed args
  130. my( $BranchName, $Language, $IniFileName, @FieldNames ) = @_;
  131. # declare locals
  132. my( @IniFileLines, $Line );
  133. my( $ThisField, $ThisValue );
  134. my( $Item, $LongFieldName );
  135. # get the field names
  136. foreach $Item ( @FieldNames ) {
  137. if ( $LongFieldName ) {
  138. $LongFieldName .= "::$Item";
  139. } else {
  140. $LongFieldName = $Item;
  141. }
  142. }
  143. # open and read the file
  144. unless ( open( INFILE, $IniFileName ) ) {
  145. # error, don't log as we're quiet
  146. return;
  147. }
  148. @IniFileLines = <INFILE>;
  149. close( INFILE );
  150. # parse file for the requested field
  151. foreach $Line ( @IniFileLines ) {
  152. # remove \n and any trailing whitespace
  153. $Line =~ s/\s+$//;
  154. if ( $Line =~ /^\;/ ) { next; }
  155. #
  156. # now we want to see if there is #include statement, and if so
  157. # begin reading the other file
  158. #
  159. if ( $Line =~ /^\#include/i ) {
  160. # get the name of the file to include. by definition, it must be
  161. # in postbuildscripts also
  162. my( $Junk, $IncludeFile );
  163. ( $Junk, $IncludeFile ) = split( /\s+/, $Line, 2 );
  164. $IncludeFile = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  165. $IncludeFile;
  166. # print( "Include file is \'$IncludeFile\'\n" );
  167. my( $ReturnValue ) = &ParseFileQuiet( $BranchName, $Language,
  168. $IncludeFile, @FieldNames );
  169. if ( $ReturnValue ) {
  170. return( $ReturnValue );
  171. }
  172. # if we're here, we didn't find the field in the included file
  173. next;
  174. }
  175. ( $ThisField, $ThisValue ) = split( /\=/, $Line, 2 );
  176. # check if this is the requested field
  177. if ( defined $ThisField && $ThisField =~ /^\Q$LongFieldName\E$/i ) {
  178. # if so, return the associated value
  179. # dbgmsg( "Found value $ThisValue for field $ThisField" );
  180. return( $ThisValue );
  181. }
  182. }
  183. # we didn't find the requested field
  184. # note that we don't want to log an error here, caller can deal with that
  185. return;
  186. }
  187. #
  188. # GetSettingEx
  189. #
  190. # Arguments: @FieldNames, $BranchName, $Language
  191. #
  192. # Purpose: reads the given field name from the appropriate branch / lang ini
  193. # file.
  194. #
  195. # Returns: $FieldValue or undef
  196. #
  197. sub GetSettingEx
  198. {
  199. # get passed args
  200. my( $BranchName, $Language, @FieldNames ) = @_;
  201. # declare locals
  202. my( $IniFileName );
  203. $IniFileName = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  204. "$BranchName.$Language.ini";
  205. # check variables
  206. if ( !$BranchName || !$Language || ( ! -e $IniFileName ) ) {
  207. errmsg( "Failed to see ini file $IniFileName ..." );
  208. return;
  209. }
  210. ParseFile( $BranchName, $Language, $IniFileName, @FieldNames );
  211. }
  212. sub ParseFile
  213. {
  214. # get passed args
  215. my( $BranchName, $Language, $IniFileName, @FieldNames ) = @_;
  216. # declare locals
  217. my( @IniFileLines, $Line );
  218. my( $ThisField, $ThisValue );
  219. my( $Item, $LongFieldName );
  220. # get the field names
  221. foreach $Item ( @FieldNames ) {
  222. if ( $LongFieldName ) {
  223. $LongFieldName .= "::$Item";
  224. } else {
  225. $LongFieldName = $Item;
  226. }
  227. }
  228. # open and read the file
  229. unless ( open( INFILE, $IniFileName ) ) {
  230. errmsg( "Failed to open ini file $IniFileName for read ..." );
  231. return;
  232. }
  233. @IniFileLines = <INFILE>;
  234. close( INFILE );
  235. # parse file for the requested field
  236. foreach $Line ( @IniFileLines ) {
  237. # remove \n and any trailing whitespace
  238. $Line =~ s/\s+$//;
  239. if ( $Line =~ /^\;/ ) { next; }
  240. #
  241. # now we want to see if there is #include statement, and if so
  242. # begin reading the other file
  243. #
  244. if ( $Line =~ /^\#include/i ) {
  245. # get the name of the file to include. by definition, it must be
  246. # in postbuildscripts also
  247. my( $Junk, $IncludeFile );
  248. ( $Junk, $IncludeFile ) = split( /\s+/, $Line, 2 );
  249. $IncludeFile = $ENV{ "RazzleToolPath" } . "\\PostBuildScripts\\" .
  250. $IncludeFile;
  251. # print( "Include file is \'$IncludeFile\'\n" );
  252. my( $ReturnValue ) = &ParseFileQuiet( $BranchName, $Language,
  253. $IncludeFile, @FieldNames );
  254. if ( $ReturnValue ) {
  255. return( $ReturnValue );
  256. }
  257. # if we're here, we didn't find the field in the included file
  258. next;
  259. }
  260. ( $ThisField, $ThisValue ) = split( /\=/, $Line, 2 );
  261. # check if this is the requested field
  262. if ( $ThisField =~ /^\Q$LongFieldName\E$/i ) {
  263. # if so, return the associated value
  264. dbgmsg( "Found value $ThisValue for field $ThisField" );
  265. return( $ThisValue );
  266. }
  267. }
  268. # we didn't find the requested field
  269. # note that we don't want to log an error here, caller can deal with that
  270. return;
  271. }
  272. 1;