smartinstaller/common/config.cpp
author Santosh V Patil <santosh.v.patil@nokia.com>
Wed, 30 Jun 2010 11:01:26 +0530
branchADM
changeset 48 364021cecc90
permissions -rw-r--r--
SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     1
/*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     8
*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    11
*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    12
* Contributors:
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    13
*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    14
* Description:
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    15
*     Implementation to read from the config file.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    16
*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    17
*
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    18
*/
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    19
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    20
#include "config.h"
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    21
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    22
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    23
// WriteIntToConfigFile
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    24
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    25
// Write the given TUint32 value and tag into the given file.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    26
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    27
// @return TInt normal Symbian error code or KErrNone if all went OK.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    28
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    29
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    30
TInt WriteIntToConfigFile( RFile& aFile, const TDesC& aTag, const TUint32 aValue )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    31
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    32
	const TInt valueLength = 10; //Length of TUint32
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    33
	TBufC<valueLength> value;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    34
	TPtr valuePtr = value.Des();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    35
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    36
	valuePtr.AppendNum(aValue);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    37
	TInt err = WriteToConfigFile( aFile, aTag, value );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    38
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    39
	return err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    40
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    41
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    43
// WriteToConfigFile
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    44
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    45
// Write the given value-tag pair into the given file.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    46
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    47
// @return TInt normal Symbian error code or KErrNone if all went OK.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    48
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    49
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    50
TInt WriteToConfigFile( RFile& aFile, const TDesC& aTag, const TDesC& aValue )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    51
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    52
	TFileText outTextFile;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    53
	outTextFile.Set(aFile);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    54
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    55
	HBufC* content = HBufC::New( aTag.Length() + aValue.Length());
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    56
	if(!content)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    57
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    58
		return KErrNoMemory;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    59
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    60
	CleanupStack::PushL(content);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    61
	TPtr ptr(content->Des());
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    62
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    63
	ptr.Copy(aTag);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    64
	ptr.Append(aValue);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    65
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    66
	TInt err = outTextFile.Write(ptr);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    67
	CleanupStack::PopAndDestroy(content);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    68
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    69
	if( err != KErrNone)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    70
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    71
		return err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    72
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    73
	return KErrNone;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    74
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    75
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    77
// EnsureNewLineAtEnd
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    78
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    79
// Add a newline character as a last character in the file.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    80
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    81
// @return TInt normal Symbian error code or KErrNone if all went OK.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    82
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    83
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    84
TInt EnsureNewLineAtEnd(RFile& aFile)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    85
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    86
	// Get last 2-bytes before EOF
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    87
	// to check for new line character
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    88
	TInt pos = -2;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    89
	TInt err = aFile.Seek(ESeekEnd, pos);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    90
	if(err != KErrNone)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    91
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    92
		return err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    93
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    94
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    95
	TBuf8<2> buf;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    96
	err = aFile.Read(buf);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    97
	if(err != KErrNone)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    98
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
    99
		return err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   100
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   101
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   102
	// Ascii value of new line character is 10
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   103
	if(buf[0] != 10 )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   104
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   105
		TFileText outTextFile;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   106
		outTextFile.Set(aFile);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   107
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   108
		// Write will append newline character
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   109
		err = outTextFile.Write(KNullDesC);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   110
		if( err != KErrNone)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   111
			{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   112
			return err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   113
			}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   114
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   115
	return KErrNone;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   116
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   117
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   118
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   119
// ReadConfigFile
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   120
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   121
// Reads the configuration file to aBuffer, aLineBuffer containing the pointers to lines.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   122
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   123
// @return TInt normal Symbian error code or KErrNone if all went OK.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   124
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   125
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   126
TInt ReadConfigFile(RFile& aFile, TDes& aBuffer, RArray< TPtrC >& aLineBuffer )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   127
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   128
	// Read text file into buffers
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   129
	TInt ret( KErrNone );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   130
	TFileText tf;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   131
	tf.Set( aFile );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   132
	aBuffer.SetMax();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   133
	TPtr ptr( aBuffer.MidTPtr( 0 ) );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   134
	TInt used( 0 );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   135
	do
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   136
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   137
		ret = tf.Read( ptr );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   138
		TInt len( ptr.Length() );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   139
		if ( ( ret == KErrNone || ret == KErrEof ) && len > 0 )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   140
			{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   141
			// Store non-empty text line
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   142
			TInt err( aLineBuffer.Append( ptr ) );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   143
			if ( err == KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   144
				{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   145
				ptr.SetMax();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   146
				ptr.Set( ptr.MidTPtr( len ) );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   147
				ptr.Zero();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   148
				used += len;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   149
				}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   150
			else
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   151
				{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   152
				ret = err;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   153
				}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   154
			}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   155
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   156
	while ( ret == KErrNone );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   157
	if ( ret == KErrEof )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   158
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   159
		// reached the end of file without any other error => this is OK
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   160
		ret = KErrNone;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   161
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   162
	aBuffer.SetLength( used );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   163
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   164
	return ret;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   165
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   166
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   167
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   168
// ReadConfigFile
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   169
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   170
// @return HBufC containg the read config file. aLineBuffer arrays pointing to lines.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   171
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   172
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   173
HBufC* ReadConfigFile( RFs& aFs, const TDesC& aFullPath, RArray< TPtrC >& aLineBuffer, TInt& aError )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   174
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   175
	RFile file;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   176
	aError = file.Open( aFs, aFullPath, EFileRead | EFileStreamText | EFileShareReadersOnly );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   177
	if ( aError != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   178
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   179
		return NULL;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   180
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   181
	TInt size( 0 );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   182
	aError = file.Size( size );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   183
	if ( aError != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   184
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   185
		file.Close();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   186
		return NULL;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   187
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   188
	// Get text size, create buffer for text and read text file
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   189
	HBufC* ret = HBufC::New( ( size + sizeof( TText ) - 1 ) / sizeof( TText ) );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   190
	if ( !ret )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   191
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   192
		aError = KErrNoMemory;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   193
		file.Close();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   194
		return NULL;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   195
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   196
	TPtr ptr( ret->Des() );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   197
	aError = ReadConfigFile( file, ptr, aLineBuffer );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   198
	file.Close();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   199
	if ( aError != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   200
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   201
		delete ret;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   202
		aLineBuffer.Reset();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   203
		return NULL;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   204
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   205
	return ret;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   206
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   207
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   208
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   209
// GetConfigValue
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   210
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   211
// Gets string specified by tag. For examples:
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   212
// Tag1=Value1  Tag1 = aTag, Value1 will be copied to aTag
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   213
// aError Normal Symbian error code or KErrNone if all went OK.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   214
// ---------------------------------------------------------------------------
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   215
//
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   216
TPtrC GetConfigValue( const TDesC& aTag, const RArray< TPtrC >& aLineBuffer, TInt& aError )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   217
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   218
	aError = KErrNotFound;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   219
	TPtrC ret( KNullDesC );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   220
	const TInt tagLen( aTag.Length() );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   221
	const TInt count( aLineBuffer.Count() );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   222
	for( TInt i( 0 ); i < count; ++i )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   223
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   224
		TPtrC line( aLineBuffer[ i ] );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   225
		if ( !line.Left( tagLen ).CompareF( aTag ) )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   226
			{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   227
			ret.Set( line.Mid( tagLen ) );
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   228
			aError = KErrNone;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   229
			break;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   230
			}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   231
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   232
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   233
	return ret;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   234
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   235
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   236
TInt CompareVersions(TVersion& version1,TVersion& version2)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   237
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   238
	// Compare the versions based on major,minor and build number.
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   239
	if((version1.iMajor == version2.iMajor)&&(version1.iMinor == version2.iMinor)&&(version1.iBuild == version2.iBuild))
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   240
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   241
		return EEqualVersion;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   242
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   243
	else if ((version1.iMajor > version2.iMajor) ||
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   244
			((version1.iMajor == version2.iMajor)&&(version1.iMinor > version2.iMinor)) ||
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   245
			((version1.iMajor == version2.iMajor)&&(version1.iMinor == version2.iMinor)&&(version1.iBuild >= version2.iBuild)))
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   246
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   247
		return EGreaterFirstVersion;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   248
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   249
	else
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   250
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   251
		return EGreaterSecondVersion;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   252
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   253
	}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   254
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   255
TBool SetVersion(const TDesC8& aVersionPtr, TVersion& aVer)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   256
	{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   257
	// Function will return EFalse if aVersionPtr is not a valid
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   258
	// version string
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   259
	TLex8 lex(aVersionPtr);
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   260
	TInt count = 0;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   261
	lex.SkipSpace();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   262
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   263
	// Get Major Version (max length 3)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   264
	const TInt maxMajorVersionLength = 3;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   265
	lex.Mark();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   266
	while ( (count<maxMajorVersionLength) && (lex.Peek() != '.') )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   267
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   268
		lex.Inc();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   269
		++count;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   270
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   271
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   272
	if (!(lex.Peek() == '.'))
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   273
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   274
		return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   275
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   276
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   277
	TLex8 lexToken(lex.MarkedToken());
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   278
	if ( lexToken.Val(aVer.iMajor) != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   279
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   280
		return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   281
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   282
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   283
	// Get Minor Version(max length 2)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   284
	const TInt maxMinorVersionLength = 2;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   285
	count = 0;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   286
	lex.Inc();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   287
	lex.Mark();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   288
	while ( (count<maxMinorVersionLength) && (lex.Peek() != '.') )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   289
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   290
		lex.Inc();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   291
		++count;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   292
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   293
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   294
	lexToken.Assign(lex.MarkedToken());
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   295
	if ( lexToken.Val(aVer.iMinor) != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   296
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   297
		return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   298
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   299
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   300
	// Check if Build Number exists,
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   301
	// otherwise return
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   302
	if (!(lex.Peek() == '.'))
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   303
		 {
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   304
		 lex.Mark();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   305
		 lex.SkipCharacters();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   306
		 if (lex.TokenLength() > 0)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   307
			 {
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   308
			 return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   309
			 }
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   310
		 else
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   311
			 {
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   312
			 aVer.iBuild = 0;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   313
			 return ETrue;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   314
			 }
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   315
		 }
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   316
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   317
	// Get Build Number(max length 5)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   318
	const TInt maxBuildNoLength = 5;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   319
	lex.Inc();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   320
	lex.Mark();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   321
	lex.SkipCharacters();
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   322
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   323
	if (lex.TokenLength() > maxBuildNoLength)
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   324
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   325
		return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   326
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   327
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   328
	lexToken.Assign(lex.MarkedToken());
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   329
	if ( lexToken.Val(aVer.iBuild) != KErrNone )
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   330
		{
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   331
		return EFalse;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   332
		}
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   333
	return ETrue;
364021cecc90 SmartInstaller contribution based on the Nokia Qt SDK 1.0 release
Santosh V Patil <santosh.v.patil@nokia.com>
parents:
diff changeset
   334
	}