|
1 # |
|
2 # Copyright (c) 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 # |
|
16 #!/usr/bin/perl |
|
17 |
|
18 #use Encode; |
|
19 |
|
20 # open index file |
|
21 open INH,'<','\epoc32\winscw\c\system\cache\index.dat' or die "couldn't open index.dat"; |
|
22 binmode INH; |
|
23 |
|
24 my @missing_files; |
|
25 my @missing_urls; |
|
26 |
|
27 my @cache_uris; |
|
28 my @cache_files; |
|
29 |
|
30 my @dir_items = GetDirContents(); |
|
31 my @cache_content = ParseCacheIndex(); |
|
32 my @extra_files; |
|
33 GetExtraFiles(); |
|
34 |
|
35 $count = 0; |
|
36 print "\n\nMissing Items:\n"; |
|
37 foreach (@missing_files) { |
|
38 print "$_ - $missing_urls[$count++]\n"; |
|
39 } |
|
40 |
|
41 print "\n\nExtra Files:\n"; |
|
42 foreach (@extra_files) { |
|
43 print "$_\n"; |
|
44 } |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 sub GetDirContents |
|
50 { |
|
51 my @subdirectories = ( "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" ); |
|
52 my @diritems = (); |
|
53 $index=0; |
|
54 foreach (@subdirectories) |
|
55 { |
|
56 opendir DIRHANDLE,"\\epoc32\\winscw\\c\\system\\cache\\@subdirectories[$index++]" or die "couldn't open cache directory"; |
|
57 my @tmp = readdir DIRHANDLE; |
|
58 push @diritems, @tmp; |
|
59 } |
|
60 |
|
61 return @diritems; |
|
62 } |
|
63 |
|
64 sub ParseCacheIndex |
|
65 { |
|
66 $filenames; |
|
67 $numEntries = GetNumEntries(); |
|
68 |
|
69 print "Index contains $numEntries items\n"; |
|
70 |
|
71 while($numEntries) |
|
72 { |
|
73 @urifilenamearray = GetNextFilename(); |
|
74 print "@urifilenamearray[1] - @urifilenamearray[0]\n"; |
|
75 push @filenames, @urifilenamearray[0]; |
|
76 push @filenames, @urifilenamearray[1]; |
|
77 $numEntries--; |
|
78 CheckFilePresent(@urifilenamearray[1], @urifilenamearray[0]); |
|
79 push @cache_files, @urifilenamearray[1]; |
|
80 push @cache_urls, @urifilenamearray[0]; |
|
81 } |
|
82 |
|
83 return @filenames; |
|
84 } |
|
85 |
|
86 sub GetNumEntries |
|
87 { |
|
88 read (INH, $buffer, 4); #throw away version number |
|
89 read (INH, $buffer, 4); # read num of 16-bit chars in dir stub |
|
90 $charcount = unpack("l",$buffer); |
|
91 read (INH, $buffer, $charcount*2); #throw away dir stub |
|
92 read (INH, $buffer, 4); # read entry count |
|
93 $value = unpack("l",$buffer); |
|
94 return $value; |
|
95 } |
|
96 |
|
97 sub GetNextFilename |
|
98 { |
|
99 my @return = (); |
|
100 |
|
101 read (INH, $buffer, 4); |
|
102 # get URI |
|
103 $stringlen = unpack("l",$buffer); |
|
104 read (INH, $buffer, $stringlen); |
|
105 |
|
106 @return[0] = $buffer; |
|
107 # print "$stringlen chars in URI:\n$buffer\n"; |
|
108 |
|
109 # get unicode filename |
|
110 # read (INH, $buffer, 4); |
|
111 # $stringlen = unpack("l", $buffer); |
|
112 |
|
113 $stringlen = 8; |
|
114 my @filename_array = (); |
|
115 if($stringlen) |
|
116 { |
|
117 # convert $buffer from unicode to ascii |
|
118 while($stringlen) { |
|
119 read (INH, $buffer, 2); |
|
120 $string = unpack("a",$buffer); |
|
121 #print "$string"; |
|
122 push @filename_array, $string; |
|
123 $stringlen--; |
|
124 } |
|
125 } |
|
126 @return[1] = join '',@filename_array; |
|
127 #print "\n\n"; |
|
128 # gobble rest of item up to header data |
|
129 read (INH, $buffer, 24); |
|
130 |
|
131 read (INH, $buffer, 4); |
|
132 $stringlen = unpack("l",$buffer); |
|
133 read (INH, $buffer, $stringlen); # throw away header data. |
|
134 |
|
135 return @return; |
|
136 } |
|
137 |
|
138 sub CheckFilePresent() |
|
139 { |
|
140 my $filename = $_[0]; |
|
141 my $url = $_[1]; |
|
142 |
|
143 my $fqname = "\\epoc32\\winscw\\c\\system\\cache\\". (substr $filename, -1, 1) . "\\" . $filename; |
|
144 |
|
145 my $FILE; |
|
146 open FILE, $fqname or MissingItem($filename, $url); |
|
147 } |
|
148 |
|
149 sub MissingItem() |
|
150 { |
|
151 push @missing_files, $_[0]; |
|
152 push @missing_urls, $_[1]; |
|
153 } |
|
154 |
|
155 sub GetExtraFiles() |
|
156 { |
|
157 # dir_items contains list of all filenames in all directories. |
|
158 my $dirnum = -1; |
|
159 my @dirnames = ( "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" ); |
|
160 |
|
161 foreach $item (@dir_items) |
|
162 { |
|
163 my $match = 0; |
|
164 if($item eq '.') |
|
165 { |
|
166 $dirnum++; |
|
167 } |
|
168 elsif($item ne '..') # filter out directories |
|
169 { |
|
170 foreach (@cache_files) |
|
171 { |
|
172 $match = 1 if($_ eq $item); |
|
173 } |
|
174 if($match == 0) |
|
175 { |
|
176 my $fqname = "\\epoc32\\winscw\\c\\system\\cache\\".@dirnames[$dirnum]."\\".$item; |
|
177 push @extra_files, $fqname; |
|
178 } |
|
179 } |
|
180 } |
|
181 } |