Merged in Governor-Tarkin/swg-src (pull request #17)
[swg-src.git] / tools / printCustomizationVariables.pl
blob868607d03d39e395b525d2a4697f3f011df9cfdb
1 # ======================================================================
2 # printCustomizationVariables.pl
4 # Tool to print customization variables from a variety of different sources.
5 # ======================================================================
7 use Customization;
9 # ======================================================================
11 my $dumpFileName;
13 # ======================================================================
15 sub printUsage
17 print "usage:\n";
18 print "\t$0 -h\n";
19 print "\t$0 -1 <sql dump 1-liner format>\n";
20 print "\n";
21 print "Arguments:\n";
22 print "\t-h: print this help.\n";
23 print "\t-1: Oracle SELECT DUMP output for tangible_object.appearance_data\n";
24 print "\t where all data for a single appearance is concatenated to be\n";
25 print "\t on the same line.\n";
28 # ----------------------------------------------------------------------
30 sub processArgs
32 # Process each arg.
33 my $printUsage;
34 my $quit = 0;
36 while ((@_ > 0) && ($_[0] =~ s/^-//))
38 my $arg = $_[0];
40 if ($arg eq '1')
42 shift;
43 $dumpFileName = $_[0] if (defined($_[0]) && (length($_[0]) > 0));
45 elsif ($arg eq 'h')
47 $printUsage = 1;
48 $quit = 1;
50 else
52 print "unrecognized option [$_[0]].\n";
53 $printUsage = 1;
54 $quit = 1;
57 shift;
60 # Ensure we're doing something.
61 if (!defined($dumpFileName))
63 $printUsage = 1;
64 $quit = 1;
67 # Print help if requested.
68 printUsage if $printUsage;
70 # Quit if required.
71 exit(-1) if $quit;
74 # ----------------------------------------------------------------------
76 sub convertOracleDumpToString
78 my $oracleDumpString = shift;
79 my $newString = "";
81 # remove header info.
82 $oracleDumpString =~ s/^\s*(\d+)?.*:\s*//;
83 my $objectId = $1;
85 # print header info.
86 print "=====\n";
87 print "Object ID: ";
88 if (defined($objectId))
90 print $objectId . "\n";
92 else
94 print "<unknown>\n";
96 print "=====\n";
99 while (length($oracleDumpString) > 0)
101 if ($oracleDumpString =~ s/^(\d+)(\s*,\s*)?//)
103 $newString .= chr($1);
105 else
107 print STDERR "convertOracleDumpToString: ", length($oracleDumpString), " characters remain: [$oracleDumpString].\n";
108 return $newString;
112 return $newString;
115 # ----------------------------------------------------------------------
117 sub printCustomizationVariables
119 # Find where p4 maps the customization_id_manager.mif file.
120 # Assume current branch for now.
122 my $branch = $ENV{BRANCH} || 'current';
123 my $depotFile = '//depot/swg/current/dsrc/sku.0/sys.shared/compiled/game/customization/customization_id_manager.mif';
124 my $output = `p4 where //depot/swg/$branch/dsrc/sku.0/sys.shared/compiled/game/customization/customization_id_manager.mif`;
125 my $mifFileName;
127 if (defined($output))
129 my @whereParts = split(/\s+/, $output);
130 if (@whereParts == 3)
132 $mifFileName = $whereParts[2];
136 if (!defined(mifFileName))
138 print STDERR "Warning: p4 where did not return a 3-part response, defaulting mif file location.\n";
139 $mifFileName = 'd:/work/swg/current/sku.0/sys.shared/compiled/game/customization/customization_id_manager.mif';
142 Customization::initializeCustomization($mifFileName);
144 # For each line in 1-line dump file, print out variable data.
145 my $dumpFile;
146 open($dumpFile, '< ' . $dumpFileName) or die "failed to open dump file [$dumpFileName]: $!";
148 my $entry = 1;
150 while (<$dumpFile>)
152 chomp;
153 my $encodedString = convertOracleDumpToString($_);
155 # Convert encoded string into
156 my %variableInfoHash;
157 my $result = Customization::getVariableInfoFromNewString(%variableInfoHash, $encodedString);
158 if (!$result)
160 print "entry $entry: failed to convert, format invalid, skipping.\n";
162 else
164 Customization::dumpVariableInfo(%variableInfoHash);
167 # Increment loop.
168 ++$entry;
172 # ----------------------------------------------------------------------
173 # MAIN
174 # ----------------------------------------------------------------------
176 # Collect info from args.
177 processArgs(@ARGV);
179 # Print the customization data.
180 printCustomizationVariables() if defined($dumpFileName);