|
1 #!/usr/bin/perl -w |
|
2 |
|
3 # pluginScript.pl |
|
4 # |
|
5 # Controls the availability of cert store plugins on the emulator, for testing |
|
6 # purposes. |
|
7 |
|
8 $UsageMessage = <<"EOF"; |
|
9 usage: |
|
10 pluginScript disable PLUGIN |
|
11 Disable the specified plugin by moving it to a backup location |
|
12 pluginScript disable_all |
|
13 Disable all plugins |
|
14 pluginScript enable PLUGIN |
|
15 Enable the specified plugin by copying the backup to its original location |
|
16 pluginScript list PLATFORM BUILD |
|
17 List the currently enabled plugins for the specified platform and build |
|
18 (default is winscw udeb) |
|
19 EOF |
|
20 |
|
21 @plugins = ('filecertstore.dll', |
|
22 'tadditionalstores.dll', |
|
23 'tadditionalstoressoftware.dll', |
|
24 'wapcertstore.dll', |
|
25 'swicertstoreplugin.dll', |
|
26 'thwsimstores.dll', |
|
27 'thwuiccstores.dll', |
|
28 'thwwimstores.dll', |
|
29 'tDeviceImmutablestores.dll', |
|
30 'MIDP2CertStore.dll'); |
|
31 |
|
32 @platforms = ('wins', 'winscw'); |
|
33 |
|
34 @builds = ('udeb', 'urel'); |
|
35 |
|
36 $EpocRoot = $ENV{'EPOCROOT'} . "epoc32"; |
|
37 |
|
38 sub usage() |
|
39 { |
|
40 die $UsageMessage; |
|
41 } |
|
42 |
|
43 sub copyFile($$) |
|
44 { |
|
45 my ($from, $to) = @_; |
|
46 print "Copying $from -> $to\n"; |
|
47 die "Can't copy: $!" unless system("cmd", "/c", "copy", $from, $to) == 0; |
|
48 } |
|
49 |
|
50 sub deleteFile($) |
|
51 { |
|
52 my ($file) = @_; |
|
53 print "Deleting $file\n"; |
|
54 die "Can't delete '$file': $!" unless unlink $file; |
|
55 } |
|
56 |
|
57 sub ensureDir($) |
|
58 { |
|
59 my ($dir) = @_; |
|
60 if (! -d $dir) |
|
61 { |
|
62 print "Creating $dir\n"; |
|
63 die "Can't create dir '$dir': $!" unless mkdir $dir; |
|
64 } |
|
65 } |
|
66 |
|
67 sub isSecure($) |
|
68 { |
|
69 my ($plugin) = @_; |
|
70 $plugin =~ s/\.dll/.rsc/i; |
|
71 return -f "$EpocRoot\\data\\z\\resource\\plugins\\$plugin" |
|
72 } |
|
73 |
|
74 sub pluginDir($$) |
|
75 { |
|
76 my ($plugin, $path) = @_; |
|
77 |
|
78 if (isSecure($plugin)) |
|
79 { |
|
80 return "$path"; |
|
81 } |
|
82 else |
|
83 { |
|
84 return "$path\\z\\system\\libs\\plugins"; |
|
85 } |
|
86 } |
|
87 |
|
88 sub backupDir($$) |
|
89 { |
|
90 my ($plugin, $path) = @_; |
|
91 |
|
92 if (isSecure($plugin)) |
|
93 { |
|
94 return "$path\\plugins_backup"; |
|
95 } |
|
96 else |
|
97 { |
|
98 return "$path\\z\\system\\libs\\plugins_backup"; |
|
99 } |
|
100 } |
|
101 |
|
102 sub disable($) |
|
103 { |
|
104 my ($plugin) = @_; |
|
105 |
|
106 for my $platform (@platforms) |
|
107 { |
|
108 for my $build (@builds) |
|
109 { |
|
110 my $path = "$EpocRoot\\release\\$platform\\$build"; |
|
111 |
|
112 my $backupDir = backupDir($plugin, $path); |
|
113 my $pluginDir = pluginDir($plugin, $path); |
|
114 my $pluginFile = "$pluginDir\\$plugin"; |
|
115 my $backupFile = "$backupDir\\$plugin"; |
|
116 |
|
117 if (-f $pluginFile) |
|
118 { |
|
119 # Always copy, in case plugin has been rebuilt |
|
120 ensureDir($backupDir); |
|
121 copyFile($pluginFile, $backupDir); |
|
122 |
|
123 deleteFile($pluginFile); |
|
124 } |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 sub disableAll() |
|
130 { |
|
131 for my $plugin (@plugins) |
|
132 { |
|
133 disable($plugin) |
|
134 } |
|
135 } |
|
136 |
|
137 sub enable($) |
|
138 { |
|
139 my ($plugin) = @_; |
|
140 |
|
141 for my $platform (@platforms) |
|
142 { |
|
143 for my $build (@builds) |
|
144 { |
|
145 my $path = "$EpocRoot\\release\\$platform\\$build"; |
|
146 |
|
147 my $backupDir = backupDir($plugin, $path); |
|
148 my $pluginDir = pluginDir($plugin, $path); |
|
149 my $pluginFile = "$pluginDir\\$plugin"; |
|
150 my $backupFile = "$backupDir\\$plugin"; |
|
151 |
|
152 if (! -f $pluginFile && -f $backupFile) |
|
153 { |
|
154 copyFile($backupFile, $pluginDir); |
|
155 } |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 sub list($$) |
|
161 { |
|
162 my ($platform, $build) = @_; |
|
163 my $path = "$EpocRoot\\release\\$platform\\$build"; |
|
164 |
|
165 printf "%-32s %-12s %s\n", "Plugin:", "Type:", "Status:"; |
|
166 |
|
167 for my $plugin (@plugins) |
|
168 { |
|
169 my $secure = isSecure($plugin); |
|
170 my $enabled = 0; |
|
171 |
|
172 if ($secure) |
|
173 { |
|
174 $enabled = -f "$path\\$plugin"; |
|
175 } |
|
176 else |
|
177 { |
|
178 $enabled = -f "$path\\z\\system\\libs\\plugins\\$plugin"; |
|
179 } |
|
180 |
|
181 my $secureMess = $secure ? 'secure' : 'old-style'; |
|
182 my $enabledMess = $enabled ? 'enabled' : 'disabled'; |
|
183 |
|
184 printf "%-32s %-12s %s\n", $plugin, $secureMess, $enabledMess; |
|
185 } |
|
186 } |
|
187 |
|
188 sub main(@) |
|
189 { |
|
190 my $action = shift || usage(); |
|
191 if ($action eq 'backup_all') |
|
192 { |
|
193 backupAll(); |
|
194 } |
|
195 elsif ($action eq 'disable') |
|
196 { |
|
197 my $plugin = shift || usage(); |
|
198 usage() unless grep { $_ eq $plugin } @plugins; |
|
199 disable($plugin); |
|
200 } |
|
201 elsif ($action eq 'disable_all') |
|
202 { |
|
203 disableAll(); |
|
204 } |
|
205 elsif ($action eq 'enable') |
|
206 { |
|
207 my $plugin = shift || usage(); |
|
208 usage() unless grep { $_ eq $plugin } @plugins; |
|
209 enable($plugin); |
|
210 } |
|
211 elsif ($action eq 'list') |
|
212 { |
|
213 my $platform = shift || 'winscw'; |
|
214 my $build = shift || 'udeb'; |
|
215 usage() unless grep { $_ eq $platform } @platforms; |
|
216 usage() unless grep { $_ eq $build } @builds; |
|
217 list($platform, $build); |
|
218 } |
|
219 else |
|
220 { |
|
221 usage(); |
|
222 } |
|
223 } |
|
224 |
|
225 main(@ARGV); |