use XML::Simple;
use Data::Dumper;
sub copyFiles {
local ($xml, $config) = @_;
local @odr = $config->{Config};
local @files = $xml->{Files};
if (exists $xml->{Files}->{Include}->{path}) {
my $includepath = $xml->{Files}->{Include}->{path};
print "Info -- Including files from $includepath\n";
my $savedDir = `cd`;
$savedDir =~ s/\n//g;
chdir $originalDir; print "Info -- chdir to ".`cd`."\n" if ($verbose);
my $tmp = new XML::Simple;
my $includeXML = $tmp->XMLin($includepath);
chdir $savedDir;
print "Info -- chdir to ".`cd`."\n" if ($verbose);
local $i = 0;
while ($includeXML->{File}[$i]) { $files[0]->{File}[++$ $i++;
}
delete $files->{Include};
}
my ($PathFragment, $BuildDependentTag, $IgnoreTag, $FileStemFragment, $fromRoot, $toRoot);
my $bPathTags = (exists $xml->{Config}->{DebugArea}) && (exists $xml->{Config}->{ReleaseArea});
my $bFileStem = (exists $xml->{Config}->{FileStem});
if ($odr->{debug}->{def}) { $PathFragment = $xml->{Config}->{DebugArea}->{value};
$BuildDependentTag = $xml->{Config}->{DebugTag}->{value};
$IgnoreTag = $xml->{Config}->{ReleaseTag}->{value};
}
else { $PathFragment = $xml->{Config}->{ReleaseArea}->{value};
$BuildDependentTag = $xml->{Config}->{ReleaseTag}->{value};
$IgnoreTag = $xml->{Config}->{DebugTag}->{value};
}
my $AlwaysTag = $xml->{Config}->{AlwaysTag}->{value};
$FileStemFragment = $xml->{Config}->{FileStem}->{name};
$fromRoot = $xml->{Config}->{From}->{root};
$toRoot = $xml->{Config}->{To}->{root};
local $i = 0;
my $bOldDot = 1;
my $bDot = 0;
while ($files[0]->{File}[$i]) {
my ($name, $newname, $from, $to, $file);
$file = $files[0]->{File}->[$i];
$name = $file->{name};
if (exists $file->{newname}) {$newname = $file->{newname};}
else {$newname = $name;}
if ($name && (! exists $file->{ignore})) { $from = "$fromRoot\\$file->{from}\\$name";
$to = "$toRoot\\$file->{to}\\$newname";
if ( $bPathTags || $bFileStem || (index($from.$to, $IgnoreTag) <0) ) {
if ($bPathTags) { $from =~ s/$AlwaysTag/$PathFragment/g;
$to =~ s/$AlwaysTag/$PathFragment/g;
$from =~ s/$BuildDependentTag/$PathFragment/g;
$to =~ s/$BuildDependentTag/$PathFragment/g;
}
if ($bFileStem) { $from =~ s/%filestem%/$FileStemFragment/g;
$to =~ s/%filestem%/$FileStemFragment/g;
}
local $DebugFragment = ($odr->{debug}->{def}) ? "-DEBUG" : "";
$from =~ s/%\-DEBUG%/$DebugFragment/g;
$to =~ s/%\-DEBUG%/$DebugFragment/g;
$to =~ s/\*.*//; ## Truncate to path before any wildcard
my $bCopyOK = 1;
my $fromcheck = $from;
my $bRequired = ! (exists $file->{notrequired});
if ($name =~ /\*/) { $fromcheck =~ s/\*.*//;
if ($bRequired && (! -d $fromcheck)) {
if ($bDot) {print "\n";}
die "Fatal -- Can't find $fromcheck";
}
$bCopyOK = !system("echo D | xcopy /D /F /Y /S $from $to > a.tmp 2>NUL");
}
else { if ($bRequired && (! -e $fromcheck)) {
if ($bDot) {print "\n";}
die "Fatal -- Can't find $fromcheck";
}
$bCopyOK = !system("echo F | xcopy /D /F /Y $from $to > a.tmp 2>NUL");
}
if ($bCopyOK) { open(MYINPUTFILE, "<a.tmp");
my(@lines) = <MYINPUTFILE>;
foreach $line (@lines) {
$bDot = ($line =~ /^0/);
}
close(MYINPUTFILE);
if (!$bDot && $bOldDot) {print "\n";}
if ($bDot) {print "."; STDOUT->flush;}
else {print "$from copied to $to\n";}
$bOldDot = $bDot;
}
else { if (!exists $file->{notrequired}) {
if ($bDot) {print "\n";}
die "Fatal -- Copy of $from to $to failed";
}
} } }
$i++;
}
if ($bDot) {print "\n";}
}
return 1;