|
1 #!perl |
|
2 # Copyright (c) 2007-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 "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 |
|
17 use strict; |
|
18 use FindBin; |
|
19 use File::Copy; |
|
20 |
|
21 # Figure out what user has asked us to do... |
|
22 |
|
23 my( $script_name ) = $0; |
|
24 my( $mode ) = $ARGV[0]; |
|
25 my( $backup ) = $ARGV[1]; |
|
26 my( $epocextra ) = $ARGV[2]; |
|
27 my( $wsiniextra ) = $ARGV[3]; |
|
28 |
|
29 my( $usage ) = <<EOF; |
|
30 |
|
31 This script will append or remove extra options to the epoc.ini and |
|
32 wsini.ini emulator configuration files. |
|
33 It is intended to be used before and after any emulator tests |
|
34 that require multiple emulator screens. |
|
35 |
|
36 Usage: |
|
37 |
|
38 $script_name help |
|
39 Displays this message. |
|
40 |
|
41 $script_name append $backup $epocextra $wsiniextra |
|
42 Makes back-up copies of the epoc.ini and wsini.ini config files to files |
|
43 prefixed with $backup and then appends the contents of $epocextra and |
|
44 $wsiniextra to the originals. Note that $backup must be unique or append |
|
45 will fail. |
|
46 |
|
47 $script_name restore $backup |
|
48 Moves the back-up copies of epoc.ini and wsini.ini to their original |
|
49 locations from files prefixed with $backup |
|
50 |
|
51 Notes: |
|
52 The wsini.ini file is a unicode text file encoded using UTF-16. The |
|
53 wsini.extra file MUST therefore be saved with the same encoding |
|
54 otherwise the resulting concatenated file will not work. (You don't need |
|
55 to worry about the extra BOM at the start of wsini.extra since this |
|
56 script takes care of removing it before appending the file) |
|
57 |
|
58 The original epoc.ini and wsini.ini files are NOT checked prior to the |
|
59 appending. If you have customised these files (especially with any |
|
60 multi-screen options) the resulting concatenated files may be invalid |
|
61 or cause the tests to fail. |
|
62 |
|
63 EOF |
|
64 |
|
65 if( ($mode eq 'help') || ( $mode eq '' ) ){ |
|
66 print $usage; |
|
67 exit; |
|
68 } |
|
69 elsif( ($mode ne 'append') && ($mode ne 'restore') ){ |
|
70 die "$script_name: ERROR: Invalid argument: \"$mode\". Must be either \"help\", \"append\" or \"restore\"\n".$usage; |
|
71 } |
|
72 |
|
73 ########################################## |
|
74 |
|
75 # Append $source to $dest. If $is_utf_16 the BOM marker at the start of $source will be |
|
76 # stripped off to ensure that the $dest remains a valid UTF-16 file. |
|
77 sub append_to_file{ |
|
78 my( $source, $dest, $is_utf_16 ) = @_; |
|
79 my( $line, $did_first ); |
|
80 $did_first = 0; |
|
81 |
|
82 open SOURCE, $source or die "$script_name: ERROR: Could not open $source ($!)\n"; |
|
83 open DEST, '>>', $dest or die "$script_name: ERROR: Could not open $dest ($!)\n"; |
|
84 |
|
85 if( $is_utf_16 ){ |
|
86 # since our old version of Perl does not have decent Unicode support |
|
87 # we'll use binary mode instead... |
|
88 binmode SOURCE; |
|
89 binmode DEST; |
|
90 |
|
91 while( read( SOURCE, $line, 1000 ) ){ |
|
92 if( !$did_first ){ |
|
93 # strip BOM (first two bytes) off first line, since it is being appended to an |
|
94 # existing UTF-16 file |
|
95 $line = substr( $line, 2 ); |
|
96 $did_first = 1; |
|
97 } |
|
98 print DEST $line; |
|
99 } |
|
100 } |
|
101 else{ |
|
102 # bog-standard ASCII |
|
103 while( $line = <SOURCE> ){ |
|
104 print DEST $line; |
|
105 } |
|
106 } |
|
107 |
|
108 close SOURCE; |
|
109 close DEST; |
|
110 } |
|
111 |
|
112 ########################################## |
|
113 # Begin main logic... |
|
114 |
|
115 # Figure out locations of INI files... |
|
116 my( $epoc_root, $epocini, $udeb_wsini, $urel_wsini, $extra_epocini, $extra_wsini, $copy_epocini, $copy_udeb_wsini, $copy_urel_wsini ); |
|
117 |
|
118 $epoc_root = $ENV{'EPOCROOT'}; |
|
119 $epoc_root =~ tr:\\:/:; # change to Linux-friendly forward-slashes (Windows Perl compensates for this automagically) |
|
120 $epoc_root =~ s/\/$//; # remove any trailing slash to avoid double slashes when the paths are appended below |
|
121 |
|
122 $epocini = $epoc_root.'/epoc32/data/epoc.ini'; |
|
123 #if this is defined we are running Mistral |
|
124 if($ENV{'EPOC_INI'}) {$epocini = $ENV{'EPOC_INI'};} |
|
125 |
|
126 $udeb_wsini = $epoc_root.'/epoc32/RELEASE/WINSCW/UDEB/Z/system/data/wsini.ini'; # this file is UTF-16 little-endian! |
|
127 $urel_wsini = $epoc_root.'/epoc32/RELEASE/WINSCW/UREL/Z/system/data/wsini.ini'; # this file is UTF-16 little-endian! |
|
128 |
|
129 my $emu_data_dir = $ENV{'EMULATOR_DATA_DIR'}; |
|
130 if($emu_data_dir) |
|
131 { |
|
132 #this is mistral so we will overload $urel_wsini with absolute location |
|
133 $urel_wsini = $emu_data_dir.'z\system\data\wsini.ini'; |
|
134 } |
|
135 |
|
136 $extra_epocini = $FindBin::Bin.$epocextra; # this file is ASCII |
|
137 $extra_wsini = $FindBin::Bin.$wsiniextra; # this file is UTF-16 little-endian! |
|
138 |
|
139 $copy_epocini = $FindBin::Bin.'/'.$backup.'_epoc.copy'; |
|
140 $copy_udeb_wsini = $FindBin::Bin.'/'.$backup.'_wsini_udeb.copy'; |
|
141 $copy_urel_wsini = $FindBin::Bin.'/'.$backup.'_wsini_urel.copy'; |
|
142 |
|
143 |
|
144 if( $mode eq 'append' ){ |
|
145 # Append mode: Append extra options to existing INI files |
|
146 |
|
147 # first make back-up of existing INI files |
|
148 # (without clobbering existing copies) |
|
149 if( -e $copy_epocini ){ |
|
150 die "$script_name: ERROR: Back-up of epoc.ini already exists at \"$copy_epocini\". Please run \"$script_name restore\" first.\n"; |
|
151 } |
|
152 else{ |
|
153 copy( $epocini, $copy_epocini ) or die "$script_name: ERROR: Could not copy $epocini ($!)\n"; |
|
154 } |
|
155 # now append extra bits to original INI files |
|
156 append_to_file( $extra_epocini, $epocini, 0 ); |
|
157 print "$script_name: NOTE: Extra settings have been appended to \"$epocini\". If you have customised this file and secondary display tests fail, please check for conflicting settings!\n"; |
|
158 |
|
159 ## UREL wsini.ini + mistral universal |
|
160 if( -e $copy_urel_wsini ){ |
|
161 die "$script_name: ERROR: Back-up of UREL wsini.ini already exists at \"$copy_urel_wsini\". Please run \"$script_name restore\" first.\n"; |
|
162 } |
|
163 else{ |
|
164 copy( $urel_wsini, $copy_urel_wsini ) or die "$script_name: ERROR: Could not copy $urel_wsini ($!)\n"; |
|
165 } |
|
166 #note mistral will provide absolute location dependant on running mode |
|
167 append_to_file( $extra_wsini, $urel_wsini, 1 ); |
|
168 print "$script_name: NOTE: Extra settings have been appended to \"$urel_wsini\". If you have customised this file and secondary display tests fail, please check for conflicting settings!\n"; |
|
169 |
|
170 |
|
171 #unless mistral in which case we dont bother keeping a backup of udeb as we adjust universal copy |
|
172 #under guise of UREL path |
|
173 if(!$emu_data_dir) |
|
174 { |
|
175 if( -e $copy_udeb_wsini ){ |
|
176 die "$script_name: ERROR: Back-up of UDEB wsini.ini already exists at \"$copy_udeb_wsini\". Please run \"$script_name restore\" first.\n"; |
|
177 } |
|
178 else{ |
|
179 copy( $udeb_wsini, $copy_udeb_wsini ) or die "$script_name: ERROR: Could not copy $udeb_wsini ($!)\n"; |
|
180 } |
|
181 # |
|
182 append_to_file( $extra_wsini, $udeb_wsini, 1 ); |
|
183 print "$script_name: NOTE: Extra settings have been appended to \"$udeb_wsini\". If you have customised this file and secondary display tests fail, please check for conflicting settings!\n"; |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 }else{ |
|
189 # Restore mode: Move copies of original INI files back to original locations |
|
190 |
|
191 move( $copy_epocini, $epocini ) && print "$script_name: NOTE: \"$epocini\" has been restored to previous version.\n" or warn "$script_name: Could not restore $epocini from $copy_epocini ($!)\n"; |
|
192 |
|
193 move( $copy_urel_wsini, $urel_wsini ) && print "$script_name: NOTE: \"$urel_wsini\" has been restored to previous version.\n" or warn "$script_name: Could not restore $urel_wsini from $copy_urel_wsini ($!)\n"; |
|
194 |
|
195 if(!$emu_data_dir) |
|
196 { |
|
197 move( $copy_udeb_wsini, $udeb_wsini ) && print "$script_name: NOTE: \"$udeb_wsini\" has been restored to previous version.\n" or warn "$script_name: Could not restore $udeb_wsini from $copy_udeb_wsini ($!)\n"; |
|
198 } |
|
199 } |