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