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.

93 lines
2.1 KiB

  1. #####################################################
  2. # SLDMagic
  3. #
  4. # file1 is the non-strings portion of an .inf file (from WINDIFF)
  5. # file2 is the strings portion of a .inf file
  6. # outfile is the output file
  7. #
  8. # cleans these up and catenates them together IFF file1 is not empty
  9. #
  10. # Requires three(3) arguments
  11. #####################################################
  12. $argc = @ARGV;
  13. $PGM = "SLDMagic:";
  14. die "Usage: $PGM file1 file2 outfile\n" if ( $argc < 3 );
  15. $file1 = $ARGV[0];
  16. $file2 = $ARGV[1];
  17. $outfile = $ARGV[2];
  18. open(FILE1, "<$file1") || die "$PGM $file1 does not exist!\n";
  19. open(FILE2, "<$file2") || die "$PGM $file2 does not exist!\n";
  20. # Make the path of the output file if necessary
  21. if( $outfile =~ /\\/ ){
  22. $outpath = "";
  23. @outarray = split(/\\/, $outfile);
  24. pop @outarray;
  25. $first = 1;
  26. foreach $dir (@outarray){
  27. if( !$first ){
  28. $outpath = $outpath . '\\';
  29. } else {
  30. $first = 0;
  31. }
  32. $outpath = $outpath . $dir;
  33. }
  34. if (!(-d $outpath)) { system "mkdir $outpath" }
  35. }
  36. open(OUTFILE, ">$outfile") || die "$PGM Could not open $outfile!\n";
  37. # Most .inx files don't have [DefaultInstall]
  38. # Assume those that don't have [AddReg] as the name of the section to add
  39. $fDontAddDefaultInstall = 0;
  40. $fDontAddVersion = 0;
  41. $fDontAddAddReg = 0;
  42. $linenum = 0;
  43. while(<FILE1>){
  44. if ((s/^ //) || (s/^ <! //) || (s/^ !> //)){
  45. if (m/^\[DefaultInstall].*/){
  46. $fDontAddDefaultInstall = 1;
  47. }elsif (m/^\[Version].*/){
  48. $fDontAddVersion = 1;
  49. }elsif (m/^\[AddReg]/){
  50. $fDontAddAddReg = 1;
  51. }
  52. $strFile1[$linenum] = $_;
  53. $linenum++;
  54. }
  55. }
  56. close(FILE1);
  57. if($linenum > 0){
  58. if ($fDontAddVersion==0){
  59. print OUTFILE "[Version]\nSignature = \"\$Windows NT\$\"\n\n";
  60. }
  61. if ($fDontAddDefaultInstall==0){
  62. print OUTFILE "[DefaultInstall]\nAddReg=AddReg\n\n";
  63. }
  64. if ($fDontAddAddReg==0){
  65. print OUTFILE "[AddReg]\n";
  66. }
  67. $i = 0;
  68. while($i<$linenum){
  69. print OUTFILE $strFile1[$i];
  70. $i++;
  71. }
  72. while(<FILE2>){
  73. print OUTFILE $_;
  74. }
  75. }
  76. close(FILE2);
  77. close(OUTFILE);
  78. if($linenum==0){
  79. unlink $outfile
  80. }