|
1 # |
|
2 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # This package contains fuctions specific to data drive image generation |
|
16 # |
|
17 |
|
18 |
|
19 package datadriveimage; |
|
20 |
|
21 require Exporter; |
|
22 @ISA=qw(Exporter); |
|
23 @EXPORT=qw( |
|
24 createDirectory |
|
25 deleteDirectory |
|
26 checkInArray |
|
27 setPath |
|
28 locateStubsisfiles |
|
29 copyFilesToFolders |
|
30 checkForSisFile |
|
31 copyNonSisFiles |
|
32 invokeInterpretsis |
|
33 invokeReadImage |
|
34 compareArrays |
|
35 dumpDatadriveObydata |
|
36 TraverseDir |
|
37 writeDataToFile |
|
38 generate_datadriveheader |
|
39 checkForWhiteSpace |
|
40 reportError |
|
41 ); |
|
42 |
|
43 use strict; |
|
44 use File::Path; # Module to provide functions to remove or create directories in a convenient way. |
|
45 use File::Copy; # Module to provide functions to copy file(s) from source to destination. |
|
46 |
|
47 use Pathutl; |
|
48 use Cwd; # Module to provide functions for determining the pathname of the current working directory. |
|
49 |
|
50 # This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation, |
|
51 # specified by the user, if yes then it returns one, else zero |
|
52 sub checkForWhiteSpace |
|
53 { |
|
54 my ($dirLoc,$dirName) = @_; |
|
55 if( $dirLoc =~ m/ / ) |
|
56 { |
|
57 print "* Warning: $dirLoc contains whitespace, hence $dirName will be created in default location \n"; |
|
58 return 1; |
|
59 } |
|
60 else |
|
61 { |
|
62 return 0; |
|
63 } |
|
64 } |
|
65 |
|
66 |
|
67 # This function reports the appropriate meassage supplied to it |
|
68 # and does a exit if and only if keepgoing option is disabled. |
|
69 sub reportError |
|
70 { |
|
71 my( $message,$keepgoingOpt ) = @_; |
|
72 # print the specified meassage. |
|
73 print STDERR "$message \n"; |
|
74 # bail out, if keepgoing option is not set. |
|
75 exit(1) if (!$keepgoingOpt); |
|
76 } |
|
77 |
|
78 # generate header for final datadrive oby file. |
|
79 sub generate_datadriveheader |
|
80 { |
|
81 my ($idx,$datadriveimage) = @_; |
|
82 my $header; |
|
83 $header = "dataimagename=$$datadriveimage[$idx]{name}.img\n"; |
|
84 $header .= "dataimagefilesystem=$$datadriveimage[$idx]{fstype}\n"; |
|
85 |
|
86 # check whether the size of the image has been mentioned |
|
87 if(defined($$datadriveimage[$idx]{size})) |
|
88 { |
|
89 $header .= "dataimagesize=$$datadriveimage[$idx]{size}\n\n"; |
|
90 } |
|
91 return $header; |
|
92 } |
|
93 |
|
94 # Create the specified directory by making use of mkpath function |
|
95 # from File::Path module. |
|
96 sub createDirectory |
|
97 { |
|
98 my($dir) = @_; |
|
99 if( !-d $dir ) |
|
100 { |
|
101 mkpath($dir); |
|
102 if (! -e $dir) |
|
103 { |
|
104 print ("ERROR: Couldn't create $dir\n"); |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 # check if the given file is a reg file or ctl file or a txt file |
|
110 # if it is any of these files then return true else false. |
|
111 # This check is need since these three files or not valid not valid e32 file |
|
112 # and hence needs to be placed as an data file inside the image. |
|
113 sub checkRegCtlFiles |
|
114 { |
|
115 my ($fileName) = @_; |
|
116 |
|
117 # check whether the file has "reg","ctl" or "txt" extension. |
|
118 if( $fileName =~/\.(reg|ctl|txt)$/i ) |
|
119 { |
|
120 return 1; |
|
121 } |
|
122 else |
|
123 { |
|
124 return 0; |
|
125 } |
|
126 } |
|
127 |
|
128 # delete the given directory by making use of rmtree function |
|
129 # from File::Path module. |
|
130 sub deleteDirectory |
|
131 { |
|
132 my($dir,$verboseOpt) = @_; |
|
133 # check whether the directory exists. |
|
134 if( -d $dir ) |
|
135 { |
|
136 print("found $dir directory \n") if($verboseOpt); |
|
137 if(rmtree($dir)) |
|
138 { |
|
139 print("$dir directory deleted \n") if($verboseOpt); |
|
140 return 0; |
|
141 } |
|
142 else |
|
143 { |
|
144 print("$dir directory could'nt be deleted \n") if($verboseOpt); |
|
145 return 1; |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 # check for processed data drive image index. |
|
151 # if there is a match return one else return zero. |
|
152 # this check is done in order to ensure data drive image index is not repeated. |
|
153 sub checkInArray |
|
154 { |
|
155 my($array, $value) = @_; |
|
156 foreach my $aLine(@$array) |
|
157 { |
|
158 if( $aLine eq $value ) |
|
159 { |
|
160 return 0; |
|
161 } |
|
162 } |
|
163 return 1; |
|
164 } |
|
165 |
|
166 # set the path for the given directory. |
|
167 sub setPath |
|
168 { |
|
169 my($dirName) = @_; |
|
170 # get the working directory. |
|
171 my $curWorkingDir = getcwd; |
|
172 # substitute slash with double backward slash. |
|
173 $curWorkingDir =~ s/\//\\/g; |
|
174 #if $curWorkingDir already has trailing '\', don't include it again |
|
175 if( $curWorkingDir =~ /\\$/) |
|
176 { |
|
177 return $curWorkingDir.$dirName; |
|
178 } |
|
179 else |
|
180 { |
|
181 return $curWorkingDir."\\".$dirName; |
|
182 } |
|
183 } |
|
184 |
|
185 # create directory and copy respective file on to that directory. |
|
186 # is there is a problem while copying files from source to destination |
|
187 # then bail out if and only if keep going option is disabled. |
|
188 sub copyFilesToFolders |
|
189 { |
|
190 my ($source,$dest,$dir,$verboseOpt) = @_; |
|
191 $source =~ s/\"//g; # remove double quotes from the string. |
|
192 my $destFileName = ""; # name of the destination file. |
|
193 $dest =~ s/\"//g; # remove double quotes from the string. |
|
194 my $destDirectory = $dest; |
|
195 # strip the last substring to get destination file |
|
196 if ($dest=~/.*\\(\S+)/) |
|
197 { |
|
198 $destFileName = $1; |
|
199 } |
|
200 else |
|
201 { |
|
202 $destFileName = $dest; |
|
203 } |
|
204 #get the destination directory along with full path |
|
205 #when "[" and "]" appear in the file name we need add "\" before "[" or "]" |
|
206 #like this: [filename].exe translate to \[filename\].exe |
|
207 if($destFileName =~ /\[|\]/) |
|
208 { |
|
209 my $tempFileName = $destFileName; |
|
210 $tempFileName =~ s/(\[|\])/\\$1/g; |
|
211 $destDirectory =~ s/$tempFileName//; |
|
212 } |
|
213 else |
|
214 { |
|
215 $destDirectory =~ s/$destFileName//; |
|
216 } |
|
217 my $destfile = $dir."\\".$dest; |
|
218 my $createdir = $dir."\\".$destDirectory ; |
|
219 |
|
220 # create the specified directory. |
|
221 &createDirectory($createdir); |
|
222 if (!copy($source,$destfile)) |
|
223 { |
|
224 warn "warning : $source file could not found \n"; |
|
225 return 0; |
|
226 } |
|
227 else |
|
228 { |
|
229 print "$source copied to $destfile\n" if($verboseOpt); |
|
230 return $destfile; |
|
231 } |
|
232 } |
|
233 |
|
234 # Make a check for sisfile keyword by reading the specified iby/oby file, |
|
235 # if sisfile keyword is found then push the respective image on to the respective array |
|
236 # and return true. |
|
237 sub checkForSisFile |
|
238 { |
|
239 my($obyfile,$sisFileArray,$sisFilePrestent) = @_; |
|
240 # open the oby file in read only mode. |
|
241 open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
242 while (my $line =<DATA>) |
|
243 { |
|
244 if($line =~ /^\s*sisfile\s*=\s*(\S+)/i ) |
|
245 { |
|
246 # found a sis file. |
|
247 $$sisFilePrestent = 1; |
|
248 # push sis file on to stack. |
|
249 push(@$sisFileArray,$1); |
|
250 next; |
|
251 } |
|
252 } |
|
253 close(DATA); |
|
254 return $$sisFilePrestent; |
|
255 } |
|
256 |
|
257 # Make a check for zdriveimagename keyword by reading the specified iby/oby file, |
|
258 # if zdriveimagename keyword is found then push the respective image on to the respective array |
|
259 # and return true. |
|
260 sub checkForZDriveImageKeyword |
|
261 { |
|
262 #$ZDriveImageFilePresent |
|
263 my($obyfile,$ZDriveImageKeywordArray,$ImageFilePresent) = @_; |
|
264 # open the oby file in read only mode. |
|
265 open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
266 while (my $line =<DATA>) |
|
267 { |
|
268 if($line =~ /^\s*zdriveimagename\s*=\s*(\S+)/i ) |
|
269 { |
|
270 # found a Z Drive Image file. |
|
271 $$ImageFilePresent = 1; |
|
272 # push sis file on to stack. |
|
273 push(@$ZDriveImageKeywordArray,$1); |
|
274 next; |
|
275 } |
|
276 } |
|
277 close(DATA); |
|
278 return $$ImageFilePresent; |
|
279 } |
|
280 |
|
281 # copy all non-sis file(s) on to prototype data drive folder |
|
282 # which are mentioned under input data drive iby/oby file. |
|
283 sub copyNonSisFiles |
|
284 { |
|
285 my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_; |
|
286 open (OBEY ,$obyfile) or die($obyfile."\n"); |
|
287 while(my $line =<OBEY>) |
|
288 { |
|
289 if( $line =~ /^(file|data)\s*=\s*(\S+)\s+(\S+)/i ) |
|
290 { |
|
291 my $keyWord=$1; |
|
292 my $source=$2; |
|
293 my $dest=$3; |
|
294 |
|
295 if( $source !~ /(\S+):(\S+)/ ) |
|
296 { |
|
297 $source = Path_Drive().$2; |
|
298 } |
|
299 my $var = ©FilesToFolders( $source,$dest,$dir,$verboseOpt); |
|
300 if($var) |
|
301 { |
|
302 $var = $keyWord."=".$var; |
|
303 $line =~ s/^(\S+)=(\S+)/$var/; |
|
304 push(@$nonsisFileArray,$line); |
|
305 } |
|
306 else |
|
307 { |
|
308 exit(1)if(!$keepgoingOpt); |
|
309 } |
|
310 } |
|
311 elsif($line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
312 { |
|
313 my $oldFile = $dir.$1; # existing-file |
|
314 my $newFile = $dir.$2; # destination-file |
|
315 print"found rename keyword\nrenaming $oldFile to $newFile\n" if ($verboseOpt); |
|
316 if ( rename($oldFile, $newFile) ) |
|
317 { |
|
318 # push the line on to the stack. |
|
319 push(@$renameArray,$1."\t".$2."\n"); |
|
320 } |
|
321 else |
|
322 { |
|
323 &datadriveimage::reportError("* Warning : can't rename $oldFile to $newFile: $!",$keepgoingOpt); |
|
324 } |
|
325 } |
|
326 elsif($line =~ /^alias\s+(\S+)\s+(\S+)/i) |
|
327 { |
|
328 my $exFile = $dir.$1; # existing-file |
|
329 my $destFile = $dir.$2; # destination-file |
|
330 print"found alias keyword\n" if ($verboseOpt); |
|
331 if(!copy($exFile,$destFile)) |
|
332 { |
|
333 &datadriveimage::reportError("* warning : couldnt create alias of $1 to $2 ",$keepgoingOpt); |
|
334 } |
|
335 else |
|
336 { |
|
337 # push the line on to the stack. |
|
338 push(@$aliasArray,$1."\t".$2."\n"); |
|
339 } |
|
340 } |
|
341 elsif($line =~ /^hide\s+(\S+)/i) |
|
342 { |
|
343 print"found hide keyword\n" if ($verboseOpt); |
|
344 print "$1 is marked as hidden, hence will not be part of the image\n" if($verboseOpt); |
|
345 if( unlink($dir.$1) ) |
|
346 { |
|
347 # push the line on to the stack. |
|
348 push(@$hideArray,$1); |
|
349 } |
|
350 else |
|
351 { |
|
352 &datadriveimage::reportError("* Warning : Can't delete $1: $! ",$keepgoingOpt); |
|
353 } |
|
354 } |
|
355 } |
|
356 close(OBEY); |
|
357 } |
|
358 |
|
359 # invoke the INTERPRETSIS tool with appropriate parameters. |
|
360 sub invokeInterpretsis |
|
361 { |
|
362 my($sisFileArray,$dataDrivePath,$verboseOpt,$zDrivePath,$parafile,$keepgoingOpt,$interpretsisOptList) = @_; |
|
363 my $sisfile = ""; |
|
364 # default system drive letter is specified since interpretsis doesnt allow overloading of options unless default |
|
365 # options are specified. |
|
366 my $basicOption = "-d C: "; # default system drive letter |
|
367 my $command = "interpretsis "; |
|
368 my $vOption = "-w info" if ($verboseOpt); |
|
369 |
|
370 # do a check if the path has a white space. |
|
371 if( $dataDrivePath =~ m/ /) |
|
372 { |
|
373 $dataDrivePath = '"'.$dataDrivePath.'"'; |
|
374 } |
|
375 |
|
376 # find out size of the array |
|
377 my $sisarraysize = scalar(@$sisFileArray); |
|
378 for( my $i=0; $i<$sisarraysize; $i++ ) |
|
379 { |
|
380 if($sisfile ne "") |
|
381 { |
|
382 $sisfile = pop(@$sisFileArray).",".$sisfile; |
|
383 } |
|
384 else |
|
385 { |
|
386 $sisfile = pop(@$sisFileArray); |
|
387 } |
|
388 } |
|
389 |
|
390 # check whether the directory exists or not |
|
391 if( -d $zDrivePath ) |
|
392 { |
|
393 # do a check if the path has a white space. |
|
394 if( $zDrivePath =~ m/ /) |
|
395 { |
|
396 $zDrivePath = '"'.$zDrivePath.'"'; |
|
397 } |
|
398 $basicOption .= "-z $zDrivePath "; |
|
399 } |
|
400 |
|
401 $basicOption .= "-c $dataDrivePath -s $sisfile $vOption"; |
|
402 |
|
403 # if parameter file is specified then invoke the INTERPRETSIS |
|
404 # with the specified parameter file with "-p" option. |
|
405 if( defined($parafile) ) |
|
406 { |
|
407 # do a check if the path has a white space. |
|
408 if( $parafile =~ m/ /) |
|
409 { |
|
410 $parafile = '"'.$parafile.'"'; |
|
411 } |
|
412 $command .= "-p $parafile "; |
|
413 } |
|
414 # else invoke the INTERPRETSIS with default parameter file with "-p" option. |
|
415 else |
|
416 { |
|
417 # Truncate and open the parameter file for writing.. |
|
418 open( OPTDATA, "> parameterfile.txt" ) or die "can't open parameterfile.txt"; |
|
419 print OPTDATA $basicOption."\n"; |
|
420 close( OPTDATA ); |
|
421 $command .= "-p parameterfile.txt "; |
|
422 } |
|
423 |
|
424 if( $interpretsisOptList ) |
|
425 { |
|
426 # find out size of the array |
|
427 my $arraysize = scalar( @$interpretsisOptList ); |
|
428 for( my $i = 0; $i < $arraysize; $i++ ) |
|
429 { |
|
430 $command .= $$interpretsisOptList[$i]." "; |
|
431 } |
|
432 } |
|
433 |
|
434 print "* Executing $command\n" if ( $verboseOpt ); |
|
435 system ( $command ); |
|
436 |
|
437 if ($? != 0) |
|
438 { |
|
439 &datadriveimage::reportError("* ERROR: INTERPRETSIS failed",$keepgoingOpt); |
|
440 } |
|
441 } |
|
442 |
|
443 # invoke the READIMAGE tool with appropriate parameters. |
|
444 sub invokeReadImage |
|
445 { |
|
446 my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_; |
|
447 my $command = "readimage "; |
|
448 # check if log file has been supplied. |
|
449 if(defined($logFile)) |
|
450 { |
|
451 if( $logFile =~ m/ /) |
|
452 { |
|
453 $logFile = '"'.$logFile.'"'; |
|
454 } |
|
455 $command .= "-l $logFile "; |
|
456 } |
|
457 |
|
458 # do a check if the path has a white space. |
|
459 if( $loc =~ m/ /) |
|
460 { |
|
461 $loc = '"'.$loc.'"'; |
|
462 } |
|
463 $command .= "-z ".$loc." ".$imageName; |
|
464 print "* Executing $command\n" if ($verboseOpt); |
|
465 system ($command); |
|
466 if ($? != 0) |
|
467 { |
|
468 &datadriveimage::reportError("* ERROR: READIMAGE failed to read the image",$keepgoingOpt); |
|
469 return 0; |
|
470 } |
|
471 return 1; |
|
472 } |
|
473 |
|
474 # Each line from the OBY file is read and if any of the line contains "rename"/ "alias" keyword |
|
475 # then that corresponding line source and line destination is obtained and is passed to this function as one of the parameters. |
|
476 # This fuction compares given array with non-sis file(s) array, when an given line destination matches with the destination of an |
|
477 # element in the rename array/alias array(array holding list of file(s) that are renamed / made alias) then, |
|
478 # that respective element is removed from the rename array and a further check is made to see whether the given |
|
479 # line source matches with the destination of an element in the rename array/alias array.If a match is found then |
|
480 # a keyword check is done,if the keyword is "rename" then corresponding element's source and destination file is replaced |
|
481 # with given line destination file and if the keyword is "alias" then a new element will be added to non sis file array |
|
482 # with line destination file as the source and destination file. |
|
483 sub compareArrays |
|
484 { |
|
485 my ( $firstarray,$nonsisArray,$linesource,$linedest,$linekeyword ) = @_; |
|
486 # count of array element(s). |
|
487 my $firstArrayCount = 0; |
|
488 # source file. |
|
489 my $linesourceFile; |
|
490 # destination file. |
|
491 my $linedestFile; |
|
492 # get source file. |
|
493 |
|
494 # strip first occurrence of back slash |
|
495 $linesource =~ s/\\//; |
|
496 |
|
497 # get source file. |
|
498 if ($linesource =~ /.*\\(\S+)/ ) |
|
499 { |
|
500 $linesourceFile = $1; |
|
501 } |
|
502 # get destination file. |
|
503 if ($linedest =~ /.*\\(\S+)/ ) |
|
504 { |
|
505 $linedestFile = $1; |
|
506 } |
|
507 # iterate trough all |
|
508 foreach my $firstarrayEntry (@$firstarray) |
|
509 { |
|
510 if( $firstarrayEntry =~ /(\S+)\s+(\S+)/ ) |
|
511 { |
|
512 my $firstarrayEntrydest = $2; |
|
513 |
|
514 if( $linedest eq $firstarrayEntrydest ) |
|
515 { |
|
516 # remove the specified element from the array. |
|
517 splice(@$firstarray,$firstArrayCount,1); |
|
518 # initialize the nonsisFileListCount to zero. |
|
519 my $nonsisFileListCount = 0; |
|
520 foreach my $nonsisEntry ( @$nonsisArray ) |
|
521 { |
|
522 if( $nonsisEntry =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
523 { |
|
524 my $nonsisEntryDest = $3; |
|
525 # remove double quotes. |
|
526 $nonsisEntryDest =~ s/\"//g; |
|
527 my $nonsisEntryDestFile; |
|
528 if ($nonsisEntryDest =~ /.*\\(\S+)/ ) |
|
529 { |
|
530 $nonsisEntryDestFile = $1; |
|
531 } |
|
532 if( $nonsisEntryDest eq $linesource ) |
|
533 { |
|
534 if($linekeyword eq "rename") |
|
535 { |
|
536 # remove the specified element from the array. |
|
537 splice(@$nonsisArray,$nonsisFileListCount,1); |
|
538 $nonsisEntry =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
539 push(@$nonsisArray,$nonsisEntry); |
|
540 } |
|
541 elsif($linekeyword eq "alias") |
|
542 { |
|
543 my $newLine = $nonsisEntry; |
|
544 $newLine =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
545 push(@$nonsisArray,$newLine); |
|
546 } |
|
547 } |
|
548 } |
|
549 $nonsisFileListCount++; |
|
550 }#end of loop foreach my $newLine ( @nonsisArray ) |
|
551 } |
|
552 $firstArrayCount++; |
|
553 }#end of loop foreach my $newLine ( @firstarray) |
|
554 } |
|
555 } |
|
556 |
|
557 # Traverse the entire directory and log the folder contents on to a file. |
|
558 sub dumpDatadriveObydata |
|
559 { |
|
560 #assign a temporary name and extension to the new oby file. |
|
561 my $newobyfile = "temp.$$"; |
|
562 my ($datadir,$oldobyfile,$size,$nonsisFileArray,$renameArray,$aliasArray, |
|
563 $hideArray,$sisobyArray,$datadriveArray,$keepgoingOpt,$verboseOpt) = @_; |
|
564 # get the working directory. |
|
565 my $curWorkingDir = getcwd; |
|
566 # traverse the updated data drive directory structure. |
|
567 &TraverseDir($datadir,"",$sisobyArray,$datadir); |
|
568 # change the directrory to the Working directory. |
|
569 chdir($curWorkingDir); |
|
570 # copy non-sis file(s) on to prototype data drive folder. |
|
571 copyNonSisFiles($datadir,$oldobyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt); |
|
572 #open the oby file in read-only mode. |
|
573 open (OLDDATA, "< $oldobyfile") or die("* Can't open $oldobyfile\n"); |
|
574 # Truncate and open the new oby file for writing.. |
|
575 open(NEWDATA, "> $newobyfile") or die "can't open $newobyfile"; |
|
576 while (my $line =<OLDDATA>) |
|
577 { |
|
578 if( $line =~ /^hide\s+(\S+)/i) |
|
579 { |
|
580 my $lineToSearch = $1; |
|
581 my $hideListCount = 0; |
|
582 foreach my $newLine ( @$hideArray ) |
|
583 { |
|
584 if( $newLine eq $lineToSearch ) |
|
585 { |
|
586 splice(@$hideArray,$hideListCount,1); |
|
587 my $nonsisFileListCount = 0; |
|
588 foreach my $newLine ( @$nonsisFileArray ) |
|
589 { |
|
590 if( $newLine =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
591 { |
|
592 my $newLineKeyword = $1; |
|
593 my $newLinesource = $2; |
|
594 my $newLinedest = $3; |
|
595 $newLinedest =~ s/\"//g; |
|
596 $newLinedest = "\\".$newLinedest; |
|
597 if( $newLinedest eq $lineToSearch ) |
|
598 { |
|
599 # remove the specified element from the array. |
|
600 splice(@$nonsisFileArray,$nonsisFileListCount,1); |
|
601 } |
|
602 } |
|
603 # increment the non sis file list count. |
|
604 $nonsisFileListCount++; |
|
605 } |
|
606 } |
|
607 # increment the hide file list count. |
|
608 $hideListCount++; |
|
609 } |
|
610 } |
|
611 elsif( $line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
612 { |
|
613 my $linesource = $1 ; |
|
614 my $linedest = $2; |
|
615 my $linekeyword = "rename"; |
|
616 &compareArrays($renameArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
617 } |
|
618 elsif( $line =~ /^alias\s+(\S+)\s+(\S+)/i ) |
|
619 { |
|
620 my $linesource = $1 ; |
|
621 my $linedest = $2; |
|
622 my $linekeyword = "alias"; |
|
623 &compareArrays($aliasArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
624 } |
|
625 elsif( $line =~ /^(file|data)\s*=\s*/i || $line =~ /^\s*(zdriveimagename|sisfile)\s*=\s*/i ) |
|
626 { |
|
627 # skip to next line. |
|
628 next; |
|
629 } |
|
630 else |
|
631 { |
|
632 # push it on to the array. |
|
633 unshift(@$datadriveArray,$line); |
|
634 } |
|
635 next; |
|
636 } |
|
637 # close the old oby files. |
|
638 close(OLDDATA)or die "can't close $oldobyfile"; |
|
639 #write the array contents on to the file |
|
640 print"* Updating $oldobyfile - final OBY file\n"; |
|
641 &writeDataToFile( $datadriveArray ); |
|
642 &writeDataToFile( $sisobyArray ); |
|
643 &writeDataToFile( $nonsisFileArray ); |
|
644 # close the new oby file. |
|
645 close(NEWDATA)or die "can't close $newobyfile"; |
|
646 #rename the file. |
|
647 rename( $newobyfile, $oldobyfile )or die "can't rename $newobyfile to $oldobyfile: $!"; |
|
648 } |
|
649 |
|
650 |
|
651 # Traverse the entire given directory |
|
652 # push all the folder contents on to an array. |
|
653 sub TraverseDir |
|
654 { |
|
655 my($dir,$folderList,$sisFileContent,$rootdir) = @_; |
|
656 #check the specified directory |
|
657 chdir($dir) || die "Cannot chdir to $dir\n"; |
|
658 local(*DIR); |
|
659 opendir(DIR, ".");#open current directory. |
|
660 my $sourcedir; |
|
661 my $destdir; |
|
662 while (my $entry=readdir(DIR)) |
|
663 { |
|
664 #skip, parent directory and current directory. |
|
665 next if ($entry eq "." || $entry eq ".."); |
|
666 #check if it is a file |
|
667 if( -f $entry ) |
|
668 { |
|
669 my $sourcedir = $rootdir."\\".$folderList.$entry; |
|
670 my $destdir = "$folderList".$entry; |
|
671 my $sisSource; |
|
672 my $sisdestination; |
|
673 if(&checkRegCtlFiles($entry)) |
|
674 { |
|
675 # check for any whitespace |
|
676 if($sourcedir =~ m/ /) |
|
677 { |
|
678 # if yes, then append double quotes |
|
679 $sisSource = "data="."\"".$sourcedir."\""; |
|
680 } |
|
681 else |
|
682 { |
|
683 # else dont append any double quotes for destination |
|
684 $sisSource = "data=".$sourcedir; |
|
685 } |
|
686 # push the line on to the array. |
|
687 push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
688 } |
|
689 else |
|
690 { |
|
691 # check for any white space |
|
692 if($sourcedir =~ m/ /) |
|
693 { |
|
694 # if yes, then append double quotes |
|
695 $sisSource = "file="."\"".$sourcedir."\""; |
|
696 } |
|
697 else |
|
698 { |
|
699 # else dont append any double quotes for destination |
|
700 $sisSource = "file=".$sourcedir; |
|
701 } |
|
702 # push the line on to the array. |
|
703 push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
704 } |
|
705 } |
|
706 #else it's a directory |
|
707 else |
|
708 { |
|
709 &TraverseDir($entry,$folderList.$entry."\\",$sisFileContent,$rootdir); |
|
710 } |
|
711 } |
|
712 closedir(DIR); |
|
713 chdir(".."); |
|
714 } |
|
715 |
|
716 # write the data in to oby file by accessing appropriate array. |
|
717 sub writeDataToFile |
|
718 { |
|
719 my ($array) = @_; |
|
720 #get the array size. |
|
721 my $arraySize = scalar(@$array); |
|
722 for(my $i=0; $i<$arraySize ; $i++ ) |
|
723 { |
|
724 #pop out the element to the respective obey file. |
|
725 print NEWDATA pop(@$array)."\n"; |
|
726 } |
|
727 } |