void GetIconInfo(const TDesC& FileName, RFs& Fs, RFile& File, RFileReadStream& s, RArray<TInt>& Offsets, int round)
{
	TBuf<50> c=_L("GetIconInfo round "); c.AppendNum(round);

	TInt table_offset=0;
	{
		TInt err=File.Open(Fs, FileName, EFileRead|EFileShareAny);
		if (err!=KErrNone) {
			err=File.Open(Fs, FileName, EFileRead);
		}
		User::LeaveIfError(err);
		RFile f0=File;
		s.Attach(f0, 0); 
		TInt uid=s.ReadUint32L();
		TUid file_uid={ uid };
		if (file_uid==KMultiBitmapRomImageUid) {
			table_offset=0x4;
		} else {
			uid=s.ReadUint32L(); // uid2
			uid=s.ReadUint32L(); // uid3
			uid=s.ReadUint32L(); // uid4 == checksum
			table_offset=s.ReadUint32L();
		}
	}

	TInt size=0; 
	{
		c=_L("GetIconInfo::2::"); c.AppendNum(table_offset);
		RFile f=File;
		s.Attach(f, table_offset);
		size=s.ReadUint32L();
		Offsets.Reset();
	}

/*
	MApp_context* ctx=GetContext();
	c=_L("offset::"); c.AppendNum(table_offset); c.Append(_L(" ")); 
	c.Append(_L("size::")); c.AppendNum(size); c.Append(_L(" i::0"));
*/
	int i=0;
	for (i=0; i<size; i++) {
		TInt offset=s.ReadUint32L();
		User::LeaveIfError(Offsets.Append(offset));
/*
		c=_L("offset::"); c.AppendNum(table_offset); c.Append(_L(" ")); 
		c.Append(_L("size::")); c.AppendNum(size); c.Append(_L(" i::")); c.AppendNum(i);
*/
	}
}
// -----------------------------------------------------------------------------
// CBSBrandHandler::VerifyVersionL()
// -----------------------------------------------------------------------------
//
void CBSBrandHandler::VerifyVersionL()
	{
	if( !iHandle )
		{
		User::Leave( KErrNotReady );
		}
	RFileReadStream stream;
	stream.Attach( *iHandle );
	CleanupClosePushL( stream );
	
	VerifyVersionL( stream );
	
	CleanupStack::PopAndDestroy(); // stream
	}
Beispiel #3
0
void CApaAppListServer::InternalizeNonNativeApplicationTypeArrayL()
	{
	RFile file;
	CleanupClosePushL(file);
	const TInt error=file.Open(iFs, iNonNativeApplicationTypeRegistry, EFileShareReadersOnly|EFileStream|EFileRead);
	if (error==KErrNone) // don't leave if the file can't be opened (because it doesn't exist, or because the directory we're looking for it in doesn't exist)
		{
		RFileReadStream sourceStream;
		sourceStream.Attach(file); // file gets closed by this call, but that's okay, we don't need it any more (sourceStream has its own copy of this RFile object that it owns)
		CleanupClosePushL(sourceStream);
		TCardinality arrayCount;
		arrayCount.InternalizeL(sourceStream);
		for (TInt i=0; i<TInt(arrayCount); ++i)
			{
			SNonNativeApplicationType nonNativeApplicationType;
			nonNativeApplicationType.iTypeUid.iUid=sourceStream.ReadUint32L();
			nonNativeApplicationType.iNativeExecutable=HBufC::NewLC(sourceStream, KMaxFileName);
			iNonNativeApplicationTypeArray.AppendL(nonNativeApplicationType);
			CleanupStack::Pop(nonNativeApplicationType.iNativeExecutable);
			}
		CleanupStack::PopAndDestroy(&sourceStream);
		}
	CleanupStack::PopAndDestroy(&file);
	}
EXPORT_C void LoadIcons(CArrayPtrFlat<CGulIcon> * aIconList, const TIconID* aIconDefs, 
			TInt aNbIcons, TInt aScale)
{
	CALLSTACKITEM_N(_CL(""), _CL("LoadIcons"));

	TFileName real; TFileName prev;
	CEikonEnv* env=CEikonEnv::Static();
	RFs& fs=env->FsSession();
	CWsScreenDevice* screen=env->ScreenDevice();
	RWsSession& ws=env->WsSession();
	RArray<TInt> Offsets; RFile File; bool file_is_open=false;
	CleanupClosePushL(Offsets);
	RFileReadStream s;
	int j=0;

	bool romfile=false;
	for (int i = 0; i<aNbIcons;i++)
	{
		TPtrC file((TText16*)aIconDefs[i].iMbmFile);
#ifdef __S60V3__
		if (file.FindF(_L("avkon"))==KErrNotFound) {
#endif
			
		if (prev.Compare(file)) {
#ifndef __S60V3__
			real=file;
#else
			TParse p; p.Set(file, 0, 0);
			real=_L("c:\\resource\\");
			real.Append(p.NameAndExt());				
				
#endif

#ifdef __WINS__
			real.Replace(0, 1, _L("z"));
#else
			if (! BaflUtils::FileExists(fs, real)) {
				real.Replace(0, 1, _L("e"));
			}
#endif
			prev=file;
			if (file_is_open) {
				s.Close();
				file_is_open=false;
			}
			if (real.Left(1).CompareF(_L("z"))==0) {
				romfile=true;
			} else {
				romfile=false;
				GetIconInfo(real, fs, File, s, Offsets, j);
				file_is_open=true;
			}
			++j;
		}

		auto_ptr<CWsBitmap> bitmap(new (ELeave) CWsBitmap(ws));
		if (!romfile) {
			RFile f1=File;
			s.Attach(f1, Offsets[aIconDefs[i].iBitmap]);	
			bitmap->InternalizeL(s);
		} else {
			TInt err=bitmap->Load(real, aIconDefs[i].iBitmap);
			if (err!=KErrNone) 
				User::Leave(err);
		}
		bitmap->SetSizeInTwips(screen);
#ifdef __S60V2__
		if (aScale>1) {
			auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
			ScaleFbsBitmapL(bitmap.get(), scaled.get(), aScale);
			bitmap=scaled;
		}
#endif
		
		auto_ptr<CWsBitmap> mask(NULL);
		if ( aIconDefs[i].iMask != KErrNotFound )
			{
				mask.reset(new (ELeave) CWsBitmap(ws));
				if (!romfile) {
					RFile f2=File;
					s.Attach(f2, Offsets[aIconDefs[i].iMask]);
					mask->InternalizeL(s);
				} else {
					User::LeaveIfError(mask->Load(real, aIconDefs[i].iMask));
				}
				mask->SetSizeInTwips(screen);
#ifdef __S60V2__
				if (aScale>1) {
					auto_ptr<CWsBitmap> scaled(new (ELeave) CWsBitmap(ws));
					ScaleFbsBitmapL(mask.get(), scaled.get(), aScale);
					mask=scaled;
				}
#endif
			}

		auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
		bitmap.release(); mask.release();
		aIconList->AppendL(icon.get()); icon.release();
#ifdef __S60V3__
		} else {
			auto_ptr<CFbsBitmap> bitmap(0);
			auto_ptr<CFbsBitmap> mask(0);
			if ( aIconDefs[i].iMask != KErrNotFound ) {
				CFbsBitmap *bitmapp=0, *maskp=0;
				AknIconUtils::CreateIconL(bitmapp, maskp, AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap, aIconDefs[i].iMask);
				bitmap.reset(bitmapp);
				mask.reset(maskp);
			} else {
				bitmap.reset(AknIconUtils::CreateIconL(AknIconUtils::AvkonIconFileName(), aIconDefs[i].iBitmap));
			}
			bitmap->SetSizeInTwips(screen);
			if (mask.get()) mask->SetSizeInTwips(screen);
			auto_ptr<CGulIcon> icon(CGulIcon::NewL(bitmap.get(), mask.get()));
			bitmap.release(); mask.release();
			aIconList->AppendL(icon.get()); icon.release();
		}
#endif
	}
	if (file_is_open) {
		s.Close();
	}
	CleanupStack::PopAndDestroy(); // Offsets
}
// -----------------------------------------------------------------------------
// CBSBrandHandler::ReadElementLC()
// -----------------------------------------------------------------------------
//
MBSElement* CBSBrandHandler::ReadElementLC( const TDesC8& aId, TBool aForceDefault /*= EFalse*/ )
	{
	TRACE( T_LIT( "CBSBrandHandler::ReadElementLC begin aId"));

	if( aForceDefault )
		{
		TRACE( T_LIT( "CBSBrandHandler::ReadElementLC default brand"));
		iStorageManager->BrandHandleL( *iApplicationId,
									   *iDefaultBrandId, iLanguage,
									   *iHandle,
									   iReserved );		
		}
	else
		{
		TInt err = -1;
		TRAP (err, iStorageManager->BrandHandleL( *iApplicationId,
									   *iBrandId, iLanguage,
									   *iHandle,
									   iReserved ));
		if (KErrNone != err)
			{
			iStorageManager->BrandHandleL( *iApplicationId,
										   *iDefaultBrandId, iLanguage,
										   *iHandle,
										   iReserved ); 	
			}
		}
	
	RFileReadStream stream;
	stream.Attach( *iHandle );
	CleanupClosePushL( stream );
	
	VerifyVersionL( stream );
	
	TInt count = stream.ReadInt16L();
	
	MBSElement* returnValue = NULL;

	for( TInt i = 0; i < count; i++ )
		{
		TRAPD( err, returnValue = ReadStreamL( aId, stream ) );
		
		if( err == KErrEof )
			{
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC EOF!") );
			// the id is not found in this file
			User::Leave( KErrNotFound );
			}
		if( returnValue )
			{
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC ELEMENT FOUND.. at position %d"), i);
			// we found what we are looking for
			break;
			}
		}
		
	CleanupStack::PopAndDestroy( &stream ); // stream	
	
	TBool popElementFromCleanupStack( EFalse );
	
	/* If retur value is not found and if its read the actual brand, then try in default brand as well. aForceDefault will decide that. */
	if( !returnValue && !aForceDefault)
		{
		TRACE( T_LIT( "CBSBrandHandler::ReadElementLC force default is true") );

		// the element was not found
		// try the default brand if it's not the same as wanted brand
		if( 0 != iBrandId->Compare( *iDefaultBrandId ) )
			{
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC calling READELEMENTLC again") );

			/* Call ReadElementLC wiht aForceDefault set to TRUE */
			returnValue = ReadElementLC( aId, ETrue );

			if ( returnValue )
			    {
				TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE IS FOUND!!!") );
			    popElementFromCleanupStack = ETrue;
			    }
			else
				{
				TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE IS NOT FOUND!!!") );
				CleanupStack :: Pop (returnValue);
				}
			}
		if( !returnValue )
			{
			TRACE( T_LIT( "CBSBrandHandler::ReadElementLC VALUE not FOUND LEAVING WITH -1 !!!") );
			User::Leave( KErrNotFound );			
			}
		}
	
	CleanupClosePushL( *returnValue );
    // since we make one function call to ReadElementLC in case the default 
	// brand id is used to retrieved the element, we have to pop one returnValue
	// pointer from CleanupStack (otherwise we have two identical pointers on 
	// the stack!!!)
	if ( popElementFromCleanupStack )
   		{
   	 	CleanupStack::Pop( returnValue );
    	}
	
	TRACE( T_LIT( "CBSBrandHandler::ReadElementLC end ") );
	return returnValue;
	}