secureswitools/swisistools/source/interpretsislib/configmanager.cpp
changeset 0 ba25891c3a9e
child 24 5cc91383ab1e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     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 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 */
       
    17 
       
    18 
       
    19 #pragma warning (disable: 4786)
       
    20 
       
    21 // System includes
       
    22 #include <iostream>
       
    23 #include <fstream>
       
    24 #include <hal_data.h>
       
    25 #include <algorithm>
       
    26  
       
    27 
       
    28 // User includes
       
    29 #include "stringutils.h"
       
    30 #include "is_utils.h"
       
    31 #include "configmanager.h"
       
    32 
       
    33 // Enumerations
       
    34 enum TConfigAttributeFlag
       
    35     {
       
    36     EConfigFlagTypeNotSupported = 1,
       
    37     EConfigFlagTypeNumeric      = 2,
       
    38     EConfigFlagTypeBoolean      = 4,
       
    39     EConfigFlagTypeYesNo        = 8,
       
    40 	EConfigFlagTypeString		= 16
       
    41     };
       
    42 
       
    43 // Structures
       
    44 struct ConfigAttribute
       
    45 	{
       
    46 	const wchar_t* iName;
       
    47 	TUint32 iId;
       
    48     TUint32 iFlags;
       
    49 	};
       
    50 
       
    51 // Constants
       
    52 const std::string KConfigAttributeHexPrefix = "0x";
       
    53 const std::string KConfigAttributeValueTrue = "TRUE";
       
    54 const std::string KConfigAttributeValueFalse = "FALSE";
       
    55 const std::string KConfigAttributeValueYes = "YES";
       
    56 const std::string KConfigAttributeValueNo = "NO";
       
    57 
       
    58 const ConfigAttribute KConfigAttributes[] =
       
    59 	{
       
    60     // HAL entries
       
    61 	{L"MANUFACTURER",				HALData::EManufacturer,                 EConfigFlagTypeNumeric },
       
    62 	{L"MANUFACTURERHARDWAREREV",	HALData::EManufacturerHardwareRev,      EConfigFlagTypeNumeric },
       
    63 	{L"MANUFACTURERSOFTWAREREV",	HALData::EManufacturerSoftwareRev,      EConfigFlagTypeNumeric },
       
    64 	{L"MANUFACTURERSOFTWAREBUILD",	HALData::EManufacturerSoftwareBuild,    EConfigFlagTypeNumeric },
       
    65 	{L"MODEL",						HALData::EModel,                        EConfigFlagTypeNumeric },
       
    66 	{L"MACHINEUID",					HALData::EMachineUid,                   EConfigFlagTypeNumeric },
       
    67 	{L"DEVICEFAMILY",				HALData::EDeviceFamily,                 EConfigFlagTypeNumeric },
       
    68 	{L"DEVICEFAMILYREV",			HALData::EDeviceFamilyRev,              EConfigFlagTypeNumeric },
       
    69 	{L"CPU",						HALData::ECPU,                          EConfigFlagTypeNumeric },
       
    70 	{L"CPUARCH",					HALData::ECPUArch,                      EConfigFlagTypeNumeric },
       
    71 	{L"CPUABI",						HALData::ECPUABI,                       EConfigFlagTypeNumeric },
       
    72 	{L"CPUSPEED",					HALData::ECPUSpeed,                     EConfigFlagTypeNumeric },
       
    73 	{L"SYSTEMTICKPERIOD",			HALData::ESystemTickPeriod,             EConfigFlagTypeNumeric },
       
    74 	{L"MEMORYRAM",					HALData::EMemoryRAM,                    EConfigFlagTypeNumeric },
       
    75 	{L"MEMORYRAMFREE",				HALData::EMemoryRAMFree,                EConfigFlagTypeNumeric },
       
    76 	{L"MEMORYROM",					HALData::EMemoryROM,                    EConfigFlagTypeNumeric },
       
    77 	{L"MEMORYPAGESIZE",				HALData::EMemoryPageSize,               EConfigFlagTypeNumeric },
       
    78 	{L"POWERBACKUP",				HALData::EPowerBackup,                  EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    79 	{L"KEYBOARD",					HALData::EKeyboard,                     EConfigFlagTypeNumeric },
       
    80 	{L"KEYBOARDDEVICEKEYS",			HALData::EKeyboardDeviceKeys,           EConfigFlagTypeNumeric },
       
    81 	{L"KEYBOARDAPPKEYS",			HALData::EKeyboardAppKeys,              EConfigFlagTypeNumeric },
       
    82 	{L"KEYBOARDCLICK",				HALData::EKeyboardClick,                EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    83 	{L"KEYBOARDCLICKVOLUMEMAX",		HALData::EKeyboardClickVolumeMax,       EConfigFlagTypeNumeric },
       
    84 	{L"DISPLAYXPIXELS",				HALData::EDisplayXPixels,               EConfigFlagTypeNumeric },
       
    85 	{L"DISPLAYYPIXELS",				HALData::EDisplayYPixels,               EConfigFlagTypeNumeric },
       
    86 	{L"DISPLAYXTWIPS",				HALData::EDisplayXTwips,                EConfigFlagTypeNumeric },
       
    87 	{L"DISPLAYYTWIPS",				HALData::EDisplayYTwips,                EConfigFlagTypeNumeric },
       
    88 	{L"DISPLAYCOLORS",				HALData::EDisplayColors,                EConfigFlagTypeNumeric },
       
    89 	{L"DISPLAYCONTRASTMAX",			HALData::EDisplayContrastMax,           EConfigFlagTypeNumeric },
       
    90 	{L"BACKLIGHT",					HALData::EBacklight,                    EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    91 	{L"PEN",						HALData::EPen,                          EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    92 	{L"PENX",						HALData::EPenX,                         EConfigFlagTypeNumeric },
       
    93 	{L"PENY",						HALData::EPenY,                         EConfigFlagTypeNumeric },
       
    94 	{L"PENDISPLAYON",				HALData::EPenDisplayOn,                 EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    95 	{L"PENCLICK",					HALData::EPenClick,                     EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    96 	{L"PENCLICKVOLUMEMAX",			HALData::EPenClickVolumeMax,            EConfigFlagTypeNumeric },
       
    97 	{L"MOUSE",						HALData::EMouse,                        EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
    98 	{L"MOUSEX",						HALData::EMouseX,                       EConfigFlagTypeNumeric },
       
    99 	{L"MOUSEY",						HALData::EMouseY,                       EConfigFlagTypeNumeric },
       
   100 	{L"MOUSEBUTTONS",				HALData::EMouseButtons,                 EConfigFlagTypeNumeric },
       
   101 	{L"CASESWITCH",					HALData::ECaseSwitch,                   EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
   102 	{L"LEDS",						HALData::ELEDs,                         EConfigFlagTypeNumeric },
       
   103 	{L"INTEGRATEDPHONE",			HALData::EIntegratedPhone,              EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
   104 	{L"DISPLAYBRIGHTNESS",			HALData::EDisplayBrightness,            EConfigFlagTypeNumeric },
       
   105 	{L"DISPLAYBRIGHTNESSMAX",		HALData::EDisplayBrightnessMax,         EConfigFlagTypeNumeric },
       
   106 	{L"KEYBOARDBACKLIGHTSTATE",		HALData::EKeyboardBacklightState,       EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
   107 	{L"ACCESSORYPOWER",				HALData::EAccessoryPower,               EConfigFlagTypeNumeric | EConfigFlagTypeBoolean | EConfigFlagTypeYesNo },
       
   108 	{L"SYSTEMDRIVE",				HALData::ESystemDrive,                  EConfigFlagTypeNumeric },
       
   109 	{L"FPHARDWARE",					HALData::EHardwareFloatingPoint,        EConfigFlagTypeNumeric },
       
   110 	{L"NUMHALATTRIBUTES",			HALData::ENumHalAttributes,             EConfigFlagTypeNumeric },
       
   111 
       
   112     // Custom entries for Interpretsis only
       
   113 	{L"LANGUAGE",					KVariableLanguage,                      EConfigFlagTypeNumeric },
       
   114 	{L"DRIVE",						KVariableDrive,							EConfigFlagTypeString },
       
   115 	{L"DEVICE_SUPPORTED_LANGUAGE",	KVariableDevSupLng,						EConfigFlagTypeNumeric }
       
   116 	};
       
   117 
       
   118 
       
   119 ConfigManager::ConfigManager(const CParameterList& aParamList)
       
   120     {
       
   121 	const std::wstring& fileName = aParamList.ConfigFileName();
       
   122 
       
   123     if ( FileExists( fileName ) )
       
   124         {
       
   125     	std::string fName;
       
   126         fName = Ucs2ToUtf8( fileName );
       
   127         //
       
   128         std::ifstream stream;
       
   129 	    stream.open( fName.c_str(), std::ios::binary );
       
   130         //
       
   131         try
       
   132             {
       
   133             ReadFile( stream );
       
   134             stream.close();
       
   135             }
       
   136         catch( const ConfigManagerException& e )
       
   137             {
       
   138             stream.close();
       
   139             throw e;
       
   140             }
       
   141         }
       
   142 
       
   143 	// Add the Rom drive and System drive definition to the DriveMap
       
   144 	// So all the drives info. will be available from ConfigManager
       
   145 	AddRomAndSystemDrives(aParamList);
       
   146     }
       
   147 
       
   148 
       
   149 ConfigManager::~ConfigManager()
       
   150     {
       
   151 	// Clean up iDrives
       
   152 	for( DrivesMap::iterator it=iDrives.begin(); it != iDrives.end(); it++ )
       
   153         {
       
   154         DriveAttributes* entry = it->second;
       
   155 		delete entry;
       
   156         }
       
   157 	iDeviceSupportedLanguages.clear();
       
   158 	iMatchingSupportedLanguages.clear();
       
   159     }
       
   160 
       
   161 
       
   162 void ConfigManager::AddRomAndSystemDrives(const CParameterList& aParamList)
       
   163 	{
       
   164 	if ( aParamList.IsFlagSet(CParameterList::EFlagsZDriveSet)) 
       
   165 		{
       
   166 		CheckAndAddDrive('z', aParamList.RomDrivePath());
       
   167 		}
       
   168 
       
   169 	if ( IsTargetDrivePresent('z') )
       
   170 		{
       
   171 		if (aParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet) &&
       
   172 			aParamList.IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) == 0 )
       
   173 			{
       
   174 			// z drive is set via ROM/ROFS logs, otherwise, command parser would have throw an exception
       
   175 			std::stringstream err;
       
   176 			err << "Cannot specify both -r option in command line and define the directory "
       
   177 				<< "representing the ROM drive in config file";
       
   178 			throw ConfigManagerException( ConfigManagerException::ETypeDriveError, err.str());
       
   179 			}
       
   180 		}
       
   181 	else
       
   182 		{
       
   183 		if (!aParamList.IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet))
       
   184 			{
       
   185 			// z drive defiend by ROM/ROFS logs
       
   186 			if (aParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
       
   187 				{
       
   188 				CheckAndAddDrive('z', L"");
       
   189 				}
       
   190 			else
       
   191 				{
       
   192 				// z drive is not set via config.ini or by -z option
       
   193 				std::stringstream err;
       
   194 				err << "Missing -r option and the ROM drive representing directory is not defined; "
       
   195 					<< "Must specify one of them (BUT not both)";
       
   196 				throw ConfigManagerException( ConfigManagerException::ETypeDriveError, err.str());
       
   197 				}
       
   198 			}
       
   199 		}
       
   200 	
       
   201 	if (aParamList.IsFlagSet(CParameterList::EFlagsCDriveSet)) 
       
   202 		{
       
   203 		CheckAndAddDrive(aParamList.SystemDriveLetter(), aParamList.SystemDrivePath());
       
   204 		}
       
   205 
       
   206 	if ( !IsTargetDrivePresent(aParamList.SystemDriveLetter()) )
       
   207 		{
       
   208 		std::stringstream err;
       
   209 		err << "The directory representing the system drive is not defined";
       
   210 		throw ConfigManagerException( ConfigManagerException::ETypeDriveError, err.str());
       
   211 		}
       
   212 	}
       
   213 
       
   214 
       
   215 void ConfigManager::SetValue( TUint32 aKey, TUint32 aValue )
       
   216     {
       
   217     iValues[ aKey ] = aValue;
       
   218     }
       
   219 
       
   220 
       
   221 bool ConfigManager::ValueExists( TUint32 aKey ) const
       
   222     {
       
   223     ConfigurationMap::const_iterator it = iValues.find( aKey );
       
   224     bool found = ( it != iValues.end() );
       
   225     return found;
       
   226     }
       
   227 
       
   228 
       
   229 TUint32 ConfigManager::ValueById( TUint32 aKey ) const
       
   230     {
       
   231     assert( ValueExists( aKey ) );
       
   232     ConfigurationMap::const_iterator it = iValues.find( aKey );
       
   233     const TUint32 ret = it->second;
       
   234     return ret;
       
   235     }
       
   236 
       
   237 
       
   238 void ConfigManager::ReadFile( std::ifstream& aStream )
       
   239     {
       
   240     int lineNumber = 1;
       
   241     std::string line;
       
   242     //
       
   243     while( std::getline( aStream, line ) )
       
   244         {
       
   245         ProcessLine( line, lineNumber++ );
       
   246         }
       
   247     }
       
   248 
       
   249 
       
   250 void ConfigManager::ProcessLine( const std::string& aLine, int aLineNumber )
       
   251     {
       
   252 	std::string line = aLine;
       
   253 
       
   254     // Strip comments
       
   255 	std::string::size_type commentPos = line.find( "//" );
       
   256     if ( commentPos != std::string::npos )
       
   257         {
       
   258         line = line.substr( 0, commentPos );
       
   259         }
       
   260 
       
   261     if  ( line.length() )
       
   262         {
       
   263     	std::string::size_type breakPos = line.find( "=" );
       
   264         if ( breakPos != std::string::npos )
       
   265             {
       
   266         	std::string value = line.substr( breakPos + 1 );
       
   267             line = line.substr( 0, breakPos );
       
   268 
       
   269             // Trim & tidy up before the conversion phase
       
   270             line = StringUtils::TrimWhiteSpace( line );
       
   271             value = StringUtils::TrimWhiteSpace( value );
       
   272 
       
   273             if ( line.length() && value.length() )
       
   274                 {
       
   275                 ConvertLineData( line, value, aLineNumber );
       
   276                 }
       
   277             }
       
   278         }
       
   279     }
       
   280 
       
   281 std::vector<TInt>& ConfigManager::GetDeviceSupportedLanguages()
       
   282 	{
       
   283 		return iDeviceSupportedLanguages;
       
   284 	}
       
   285 
       
   286 void ConfigManager::ConvertLineData( const std::string& aKey, std::string& aValue, int aLineNumber )
       
   287     {
       
   288     const ConfigAttribute* attrib = AttributeByName( aKey );
       
   289     if ( attrib )
       
   290         {
       
   291         // Now try to convert the value string according to the attribute's
       
   292         // conversion specification.
       
   293         if ( attrib->iFlags & EConfigFlagTypeNotSupported )
       
   294             {
       
   295             throw ConfigManagerException( ConfigManagerException::ETypeKeywordNotSupported, 
       
   296                                           aKey,
       
   297                                           aValue,
       
   298                                           aLineNumber );
       
   299             }
       
   300         else
       
   301             {
       
   302             TUint32 num = 0;
       
   303 
       
   304             // First try numeric conversion, since this satsifies most of
       
   305             // the entries. Then try bool / yes / no
       
   306             if ( ( attrib->iFlags & EConfigFlagTypeNumeric ) && TryStringToNumeric( aValue, num ) )
       
   307                 {
       
   308             	if ( attrib->iId == KVariableDevSupLng )
       
   309             		{
       
   310             		if ( !AddDeviceSupportedLanguage(num))
       
   311             			{
       
   312     					throw ConfigManagerException( ConfigManagerException::ETypeDuplicateDefinition, 
       
   313     													aKey, aValue, aLineNumber );
       
   314     					}
       
   315                 	return;
       
   316             		}
       
   317 
       
   318                 }
       
   319             else if ( ( attrib->iFlags & EConfigFlagTypeBoolean ) && TryStringToBool( aValue, num ) )
       
   320                 {
       
   321                 }
       
   322             else if ( ( attrib->iFlags & EConfigFlagTypeYesNo ) && TryStringToYesNo( aValue, num ) )
       
   323                 {
       
   324                 }
       
   325 			else if ( ( attrib->iFlags & EConfigFlagTypeString ) && (attrib->iId == KVariableDrive) )
       
   326 				{
       
   327 	            DriveAttributes* newDrive = new DriveAttributes();
       
   328 				int driveLetter = ConvertToDriveAttributes(StringUtils::ToLower(aValue), newDrive);
       
   329 				
       
   330 				if (driveLetter == 0)
       
   331 					{
       
   332 					delete newDrive;
       
   333 					throw ConfigManagerException( ConfigManagerException::ETypeInvalidValueForKey, 
       
   334 													aKey, aValue, aLineNumber );
       
   335 					}
       
   336 				
       
   337 				if ( !IsDirectory(newDrive->iDir) )
       
   338 					{
       
   339 					delete newDrive;
       
   340 					throw ConfigManagerException( ConfigManagerException::ETypeInvalidDirectory, 
       
   341 													aKey, aValue, aLineNumber );
       
   342 					}
       
   343 
       
   344 				if (!AddDrive(newDrive, driveLetter))
       
   345 					{
       
   346 					delete newDrive;
       
   347 					throw ConfigManagerException( ConfigManagerException::ETypeDuplicateDefinition, 
       
   348 													aKey, aValue, aLineNumber );
       
   349 					}
       
   350 
       
   351 				return;
       
   352 				}
       
   353             else
       
   354                 {
       
   355                 throw ConfigManagerException( ConfigManagerException::ETypeInvalidValueForKey, 
       
   356                                               aKey,
       
   357                                               aValue,
       
   358                                               aLineNumber );
       
   359                 }
       
   360 
       
   361             // Assume okay if got here.
       
   362             if ( !ValueExists( attrib->iId ) )
       
   363                 {
       
   364                 SetValue( attrib->iId, num );
       
   365                 }
       
   366             else
       
   367                 {
       
   368                 throw ConfigManagerException( ConfigManagerException::ETypeDuplicateDefinition, 
       
   369                                               aKey,
       
   370                                               aValue,
       
   371                                               aLineNumber );
       
   372                 }
       
   373             }
       
   374         }
       
   375 	else
       
   376 		{ 
       
   377 	 	// DEF117196
       
   378 	 	// Config files can be created by the licensee from HAL HDA files. It is cumbersome if they 
       
   379 	 	// produce an error and halt if there is an attribute defined in the config file which is not 
       
   380 	 	// relevant to interpretsis.
       
   381 	 	// Instead a warning is produced.
       
   382 		std::ostringstream stream;
       
   383     	stream << "Unsupported keyword at line " << aLineNumber << " of ini file [" << aKey << " = " << aValue << "] ";
       
   384     	stream << std::endl;
       
   385     	std::wstring finalMessage = Utf8ToUcs2( stream.str() );
       
   386 		LWARN( finalMessage );
       
   387 		}
       
   388     }
       
   389 
       
   390 
       
   391 std::string ConfigManager::AttributeNameById( TUint32 aId )
       
   392     {
       
   393 	std::string ret = "Unknown/Unsupported attribute";
       
   394     //
       
   395     const int attributeCount = sizeof( KConfigAttributes ) / sizeof( ConfigAttribute );
       
   396 	for( int i=0; i<attributeCount; i++ )
       
   397 		{
       
   398 		if  ( KConfigAttributes[i].iId == aId )
       
   399 			{
       
   400 			std::wstring entry( KConfigAttributes[i].iName );
       
   401             ret = Ucs2ToUtf8( entry );
       
   402 			}
       
   403 		}
       
   404     //
       
   405     return ret;
       
   406     }
       
   407 
       
   408 
       
   409 const ConfigAttribute* ConfigManager::AttributeByName( const std::string& aName )
       
   410     {
       
   411 	std::string upperCased( aName );
       
   412     upperCased = StringUtils::ToUpper( upperCased );
       
   413     std::wstring searchFor;
       
   414     searchFor = Utf8ToUcs2( upperCased );
       
   415     //
       
   416     const int attributeCount = sizeof( KConfigAttributes ) / sizeof( ConfigAttribute );
       
   417     const ConfigAttribute* ret = NULL;
       
   418     //
       
   419 	for( int i=0; i<attributeCount; i++ )
       
   420 		{
       
   421 		if  ( KConfigAttributes[i].iName == searchFor )
       
   422 			{
       
   423 			ret = &KConfigAttributes[i];
       
   424 			break;
       
   425 			}
       
   426 		}
       
   427     //
       
   428     return ret;
       
   429     }
       
   430 
       
   431 
       
   432 bool ConfigManager::TryStringToNumeric( const std::string& aText, TUint32& aNumber )
       
   433     {
       
   434     bool convertedOk = false;
       
   435     //
       
   436     std::istringstream stringStream( aText );
       
   437 
       
   438     // Check for hex prefix
       
   439     if ( aText.length() > 2 && aText.substr( 0, 2 ) == KConfigAttributeHexPrefix )
       
   440         {
       
   441         // Skip 0x prefix
       
   442         stringStream.ignore( 2 );
       
   443         stringStream >> std::hex >> aNumber;
       
   444         convertedOk = ( !stringStream.fail() );
       
   445         }
       
   446     else
       
   447         {
       
   448         stringStream >> aNumber;
       
   449         convertedOk = ( !stringStream.fail() );
       
   450         }
       
   451     //
       
   452     return convertedOk;
       
   453     }
       
   454 
       
   455 
       
   456 bool ConfigManager::TryStringToBool( const std::string& aText, TUint32& aNumber )
       
   457     {
       
   458     bool convertedOk = false;
       
   459     //
       
   460     std::string text = StringUtils::ToUpper( aText );
       
   461     if ( text == KConfigAttributeValueTrue )
       
   462         {
       
   463         aNumber = true;
       
   464         convertedOk = true;
       
   465         }
       
   466     else if ( text == KConfigAttributeValueFalse )
       
   467         {
       
   468         aNumber = false;
       
   469         convertedOk = true;
       
   470         }
       
   471     //
       
   472     return convertedOk;
       
   473     }
       
   474 
       
   475 
       
   476 bool ConfigManager::TryStringToYesNo( const std::string& aText, TUint32& aNumber )
       
   477     {
       
   478     bool convertedOk = false;
       
   479     //
       
   480     std::string text = StringUtils::ToUpper( aText );
       
   481     if ( text == KConfigAttributeValueYes )
       
   482         {
       
   483         aNumber = true;
       
   484         convertedOk = true;
       
   485         }
       
   486     else if ( text == KConfigAttributeValueNo )
       
   487         {
       
   488         aNumber = false;
       
   489         convertedOk = true;
       
   490         }
       
   491     //
       
   492     return convertedOk;
       
   493     }
       
   494 
       
   495 
       
   496 int ConfigManager::ConvertToDriveAttributes( const std::string& aString, DriveAttributes* aDrive)
       
   497     {
       
   498 	std::string::const_iterator it = aString.begin();
       
   499 	std::string::const_iterator end = aString.end();
       
   500 	std::string::const_iterator currentPos = it;
       
   501 	int driveLetter = 0;
       
   502 
       
   503 	if (currentPos != end)
       
   504         {
       
   505 		std::string temp;
       
   506 
       
   507         currentPos = std::find(it, end, ' ');
       
   508 
       
   509 		if (currentPos == end)
       
   510 			{
       
   511 			return 0;
       
   512 			}
       
   513 
       
   514 		// Set the drive representation location
       
   515 		Utf8ToUcs2(std::string(it, (currentPos-it)), aDrive->iDir);
       
   516 			
       
   517 		temp =  StringUtils::TrimWhiteSpace( std::string(currentPos, end) );
       
   518 
       
   519 		it = temp.begin();
       
   520 		end = temp.end();
       
   521 
       
   522 		// Look for the next 'space' if found
       
   523 		currentPos = std::find(it, end, ' ');
       
   524 
       
   525 		if (currentPos - it != 1)
       
   526 			{
       
   527 			// The drive letter is more than one character
       
   528 			return 0;
       
   529 			}
       
   530 		
       
   531 		// Set the target drive letter
       
   532 		driveLetter = tolower(*it);
       
   533 
       
   534 		if (currentPos == end)
       
   535 			{
       
   536 			// The external attribute is not set, i.e. leave it as the default value.
       
   537 			return driveLetter;
       
   538 			}
       
   539 
       
   540 		temp =  StringUtils::TrimWhiteSpace( std::string(currentPos, end) );
       
   541 
       
   542 		// Set the external attribute to true
       
   543 		if (StringUtils::ToLower(temp) == "ext")
       
   544 			aDrive->iExternal = true;
       
   545       
       
   546 		return driveLetter;
       
   547 		}
       
   548 
       
   549 	return 0;
       
   550 	}
       
   551 
       
   552 
       
   553 std::wstring ConfigManager::GetLocalDrivePath(int aDrive)
       
   554 {
       
   555 	DrivesMap::const_iterator it = iDrives.find( aDrive );
       
   556 
       
   557 	if (it == iDrives.end())
       
   558 	{
       
   559 		std::stringstream err;
       
   560 		err << "Drive: " << aDrive << " not defined";
       
   561 		throw ConfigManagerException( ConfigManagerException::ETypeDriveError, err.str());
       
   562 	}
       
   563 
       
   564     return it->second->iDir;
       
   565 }
       
   566 
       
   567 
       
   568 bool ConfigManager::IsTargetDrivePresent(int aDrive) const
       
   569 {
       
   570 	DrivesMap::const_iterator it = iDrives.find( aDrive );
       
   571 
       
   572 	return (it != iDrives.end());
       
   573 }
       
   574 
       
   575 
       
   576 bool ConfigManager::IsTargetDriveExt(int aDrive) const
       
   577 {
       
   578 	DrivesMap::const_iterator it = iDrives.find( aDrive );
       
   579 
       
   580 	if (it == iDrives.end())
       
   581 	{
       
   582 		std::stringstream err;
       
   583 		err << "Drive: " << aDrive << " not defined";
       
   584 		throw ConfigManagerException( ConfigManagerException::ETypeDriveError, err.str());
       
   585 	}
       
   586 
       
   587 
       
   588     return it->second->iExternal;
       
   589 }
       
   590 
       
   591 
       
   592 bool ConfigManager::AddDrive(DriveAttributes* aDrive, const int aDriveLetter)
       
   593 {
       
   594 	DrivesMap::const_iterator it = iDrives.find( aDriveLetter );
       
   595 
       
   596 	if( it != iDrives.end())
       
   597 	{
       
   598 		// Drive already present
       
   599 		return false;
       
   600 	}
       
   601 
       
   602 	// Set the map value
       
   603 	iDrives[aDriveLetter] = aDrive;
       
   604 	return true;
       
   605 }
       
   606 
       
   607 
       
   608 void ConfigManager::CheckAndAddDrive(const int aDrive, const std::wstring& aDir,const bool aExternal)
       
   609 {
       
   610 	DrivesMap::iterator it = iDrives.find( aDrive );
       
   611 
       
   612 	if (it != iDrives.end())
       
   613 	{
       
   614 		char drive = aDrive;
       
   615 	 	std::stringstream warn;
       
   616 		warn << "Redefining drive: " << drive;
       
   617 		std::wstring finalMessage = Utf8ToUcs2( warn.str() );
       
   618 		LWARN( finalMessage + L" to " + aDir);
       
   619 
       
   620 		delete it->second;
       
   621 		iDrives.erase(it);
       
   622 	}
       
   623 
       
   624 	DriveAttributes* newDrive = new DriveAttributes();
       
   625 
       
   626 	newDrive->iDir = aDir;
       
   627 	newDrive->iExternal = aExternal;
       
   628 	
       
   629 	// Set the map value
       
   630 	iDrives[aDrive] = newDrive;
       
   631 }
       
   632 
       
   633 
       
   634 bool ConfigManager::AddDeviceSupportedLanguage(TInt langId)
       
   635 	{
       
   636  	std::vector<int>::const_iterator end = iDeviceSupportedLanguages.end();
       
   637 	for (std::vector<int>::const_iterator curr = iDeviceSupportedLanguages.begin(); curr != end; ++curr)
       
   638 		{
       
   639 			 if ( *curr == langId)
       
   640 			 {
       
   641 				 return false;
       
   642 			 }
       
   643 		}
       
   644 	iDeviceSupportedLanguages.push_back(langId);
       
   645 	return true;
       
   646 	}
       
   647 void ConfigManager::AddMatchingSupportedLanguages(TInt aMatchingSupportedLangauges)
       
   648 	{
       
   649  	std::vector<int>::const_iterator end = iMatchingSupportedLanguages.end();
       
   650 	for (std::vector<int>::const_iterator curr = iMatchingSupportedLanguages.begin(); curr != end; ++curr)
       
   651 		{
       
   652 			 if ( *curr == aMatchingSupportedLangauges)
       
   653 			 {
       
   654 				 return;
       
   655 			 }
       
   656 		}
       
   657 	iMatchingSupportedLanguages.push_back(aMatchingSupportedLangauges);
       
   658 	return;
       
   659 	}
       
   660 
       
   661 std::vector<TInt>& ConfigManager::GetMatchingSupportedLanguages() 
       
   662 	{
       
   663 		return iMatchingSupportedLanguages;
       
   664 	}
       
   665 ConfigManagerException::~ConfigManagerException()
       
   666     {
       
   667     }
       
   668 
       
   669 
       
   670 void ConfigManagerException::Display() const
       
   671     {
       
   672 	std::ostringstream stream;
       
   673     stream << "Configuration problem at line " << iLineNumber << " [" << iKey << " = " << iValue << "]: ";
       
   674     //
       
   675 	switch( iType )
       
   676 		{
       
   677 		case ETypeKeywordNotSupported:
       
   678 			stream << "KEY is not supported";
       
   679 			break;
       
   680 		case ETypeInvalidValueForKey:
       
   681 			stream << "\'" << iValue << "\'" << " is an invalid type or out of range";
       
   682 			break;
       
   683 		case ETypeDuplicateDefinition:
       
   684 			stream << "\'" << iKey << "\'" << "has already been defined previously in this configuration";
       
   685 			break;
       
   686 		case ETypeInvalidDirectory:
       
   687 			stream << "\'" << iValue << "\'" << " directory is not found";
       
   688 			break;
       
   689 		case ETypeDriveError:
       
   690 			LERROR( Utf8ToUcs2( iValue ) );
       
   691 			return;
       
   692 
       
   693 		default:
       
   694 			stream << "Unknown error";
       
   695 			break;
       
   696 		}
       
   697     //
       
   698     stream << std::endl;
       
   699     std::wstring finalMessage = Utf8ToUcs2( stream.str() );
       
   700     //
       
   701 	LERROR( finalMessage );
       
   702     }
       
   703