#!/usr/bin/perl

$True = 1;
$False = 0;

$WinDir = $ENV{'WINDIR'};


$Version = `ver`;
$Version=~s/(\t|\n|\n\n)//ig;
print $Version, "\n";

if($Version=~/NT/i){
    if($Version=~/5/){
        $VerNumber = 5;
        $DbFile = $WinDir . "\\wostest\\tools\\apptest\\scripts\\NT5WKS_DB\.txt";
        $Version=~s/(\t|\n|\n\n)//g;
    }
}

if($Version=~/NT/i){
    if($Version=~/4/){
        $VerNumber = 4;
        $DbFile = $WinDir . "\\wostest\\tools\\apptest\\scripts\\NT4WKS_DB\.txt";
        $Version=~s/(\t|\n|\n\n)//g;
    }
}

if($Version =~/1111|1212|1214|950/){
    print "Version equals all by itself ", $Version, "\n";
    $DbFile = $WinDir . "\\wostest\\tools\\apptest\\scripts\\OSR2_DB\.txt";
    $VerNumber = "OSR2";
    $Version=~s/(\t|\n|\n\n)//g;

if($Version =~/B/i){
    $DbFile = $WinDir . "\\wostest\\tools\\apptest\\scripts\\Win95_DB\.txt";
}
}
elsif($Version=~/1998|2/i){

$DbFile = $WinDir . "\\wostest\\tools\\apptest\\scripts\\Win98_DB\.txt";
    $VerNumber = "Win98";
    $Version=~s/(\t|\n|\n\n)//g;
}

$InFile1 = $DbFile;
$InFile2 = $WinDir . "\\wostest\\tools\\apptest\\factory\.txt";
print "Input File2 = ", $InFile2, " \n";
 
    
$OutFile = $WinDir . "\\wostest\\tools\\apptest\\pri1app\.txt"; 
print "***************  Just Before Open Files Occurs\n";
print "$WinDir *** $InFile1 *** $DbFile \n";
open IN1, "<$InFile1",        or die "There is an emergency going on\.\n   Could not open $InFile1 for Reading :\n $!";
open IN2, "<$InFile2",        or die "There is an emergency going on\.\n   Could not open $InFile2 for Reading :\n $!";
open OUT, ">$OutFile",        or die "There is an emergency going on\.\n   Could not open $OutFile for Reading :\n $!";
print "Parsing : ", $InFile1, "\n\n";
print "Parsing : ", $InFile2, "\n\n";



LINE: while (<IN1>) {
    chomp($_);
    push(@File1, $_);
}

LINE2: while (<IN2>){
    chomp($_);
    if($_=~/microsoft/i){next LINE2;}
    push(@File2, $_);
}

foreach(@File1){
    @DB_filename = split /\\/;
    foreach(@DB_filename){
        if($_=~/\.cpl|\.lnk|\.dun/i){
            chomp($_);
            push(@AllFoundFileNames, $_);
        }
    }
}

foreach(@File2){
    $TempFullPath = $_;
    @fac_all_filename = split /\\/;
    foreach(@fac_all_filename){
        if($_=~/\.cpl|\.lnk|\.dun/i){
            chomp($_);
            push(@FacFoundFileNames, $TempFullPath);
            
          
        }
    }
    
}

foreach(@FacFoundFileNames){
    $FoundOne = $True;
    $FirstFile = $_;
    foreach(@AllFoundFileNames){
        if($FirstFile=~$_){
            $FoundOne = $False;
        }
    }
    if($FoundOne){
        push(@thosethatifound, $_, "\n");
    }
}

foreach(@thosethatifound){
#     print $_, "\n";
     print OUT $_;

}
     print "Results saved to $OutFile \n";
