| 1 |
#!/usr/bin/perl
|
| 2 |
|
| 3 |
|
| 4 |
if (scalar(@ARGV) != 2) {
|
| 5 |
&usage;
|
| 6 |
exit;
|
| 7 |
}
|
| 8 |
|
| 9 |
&header;
|
| 10 |
|
| 11 |
# remove a trailing /
|
| 12 |
$dirpath = $ARGV[0];
|
| 13 |
$dirpath =~ s!(.*)/$!$1!;
|
| 14 |
|
| 15 |
$dirpath2 = $ARGV[1];
|
| 16 |
$dirpath2 =~ s!(.*)/$!$1!;
|
| 17 |
|
| 18 |
$max_uid = -1;
|
| 19 |
|
| 20 |
opendir FILEDIR, $dirpath or die "Error opening filedir!\n";
|
| 21 |
|
| 22 |
while ($filename = readdir FILEDIR) {
|
| 23 |
if ($filename =~ m/^\./) { next; } #ignore . and ..
|
| 24 |
|
| 25 |
if ( ! (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
| 26 |
$atime,$mtime,$ctime,$blksize,$blocks) = stat $dirpath ."/". $filename )) {
|
| 27 |
print "Error stat-ing the file $pathdir/$filename!\n" ; next; }
|
| 28 |
|
| 29 |
$type = ($mode & 070000) >> 12;
|
| 30 |
|
| 31 |
if ($type != 0) {
|
| 32 |
print "File ". $dirpath ."/". $filename ." its not regular\n";
|
| 33 |
next;
|
| 34 |
}
|
| 35 |
convertfile($filename);
|
| 36 |
}
|
| 37 |
|
| 38 |
closedir FILEDIR;
|
| 39 |
|
| 40 |
sub convertfile {
|
| 41 |
my $filen = shift;
|
| 42 |
my ($tab, $col, $val);
|
| 43 |
|
| 44 |
open FILE, $dirpath ."/". $filen or die "Error opening file ". $dirpath ."/". $filen ."\n";
|
| 45 |
if (open FILEOUT, $dirpath2 ."/". $filen) {
|
| 46 |
die "Found existent file : ". $dirpath2 ."/". $filen ."!! Plese provide an empty output directory !!";
|
| 47 |
}
|
| 48 |
|
| 49 |
open FILEOUT, ">". $dirpath2 ."/". $filen or die "Error opening output file ". $dirpath2 ."/". $filen ."\n";
|
| 50 |
print "Converting file ". $filen ."... ";
|
| 51 |
|
| 52 |
while($line = <FILE>) {
|
| 53 |
if ($line =~ m/".*"=".*"/) {
|
| 54 |
|
| 55 |
$line =~ m/^"([A-Za-z0-9]+)\\\\(.*)"="(.*)"\n$/;
|
| 56 |
|
| 57 |
$tab = $1;
|
| 58 |
$col = $2;
|
| 59 |
$val = $3;
|
| 60 |
|
| 61 |
if ($tab =~ m/^team$/i) {
|
| 62 |
print FILEOUT "\"". $tab . "\\\\WAR3\\\\" . $col . "\"=\"" . $val ."\"\n";
|
| 63 |
next;
|
| 64 |
}
|
| 65 |
|
| 66 |
if ($tab =~ m/^record$/i) {
|
| 67 |
if ($col =~ m/^solo/i or $col =~ m/^team/i or $col =~ m/^ffa/i or
|
| 68 |
$col =~ m/^orcs/i or $col =~ m/^humans/i or $col =~ m/^nightelves/i or $col =~ m/^undead/i or $col =~ m/^random/i) {
|
| 69 |
print FILEOUT "\"". $tab . "\\\\WAR3\\\\" . $col . "\"=\"" . $val ."\"\n";
|
| 70 |
next;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
print FILEOUT $line;
|
| 75 |
}
|
| 76 |
}
|
| 77 |
close FILEOUT;
|
| 78 |
close FILE;
|
| 79 |
print "done\n";
|
| 80 |
}
|
| 81 |
|
| 82 |
sub header {
|
| 83 |
print "Account files WAR3 converting tool.\n";
|
| 84 |
print " Copyright (C) 2003 Mihai RUSU (dizzy\@roedu.net)\n";
|
| 85 |
print " People Versus People Gaming Network (www.pvpgn.org)\n\n";
|
| 86 |
}
|
| 87 |
|
| 88 |
sub usage {
|
| 89 |
&header;
|
| 90 |
print "Usage:\n\n\tconvert_w3.pl <inputdir> <outputdir>\n\n";
|
| 91 |
print "\t <inputdir>\t: directory with the input account files\n";
|
| 92 |
print "\t <outputdir>\t: directory where the output account files will reside\n";
|
| 93 |
}
|