localisation/apparchitecture/apgrfx/APGICNFL.CPP
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <s32file.h>
       
    18 #include <s32ucmp.h>
       
    19 #include <bautils.h>
       
    20 #include <barsread.h>
       
    21 #include <barsc.h>
       
    22 #include <barsread2.h>
       
    23 #include <barsc2.h>
       
    24 #include <apfdef.h>
       
    25 #include "APGAIR.H"
       
    26 
       
    27 #ifdef _DEBUG
       
    28 #include "APGSTD.H" // panic codes
       
    29 #endif // _DEBUG
       
    30 
       
    31 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
    32 // the two #defines immediately below are #defined to "nothing" so that only the minimal set of functions that ought to be "removed" because of SYMBIAN_REMOVE_UI_FRAMEWORKS_V1 (but which are needed still because of UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER) are actually exported
       
    33 #define IMPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER
       
    34 #define EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER
       
    35 #endif // UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER
       
    36 
       
    37 #include "APGICNFL.H"
       
    38 
       
    39 #if !defined(EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER)
       
    40 // we're compiling a source file that doesn't define EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER, so give it it's default "value" of "EXPORT_C"
       
    41 #define EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER EXPORT_C
       
    42 #endif
       
    43 
       
    44 //
       
    45 // Try and reduce the bitmap mask depth to 1bpp (2 colours)
       
    46 //
       
    47 LOCAL_D CFbsBitmap* TryCompressMaskL(const CFbsBitmap& aMask)
       
    48 	{
       
    49 	CFbsBitmap* newMask=NULL;
       
    50 	if (aMask.DisplayMode()!=EGray2 && aMask.IsMonochrome())
       
    51 		{
       
    52 		newMask=new(ELeave) CFbsBitmap;
       
    53 		CleanupStack::PushL(newMask);
       
    54 		const TSize size=aMask.SizeInPixels();
       
    55 		User::LeaveIfError(newMask->Create(size,EGray2));
       
    56 		CFbsBitmapDevice* device=CFbsBitmapDevice::NewL(newMask);
       
    57 		CleanupStack::PushL(device);
       
    58 		CFbsBitGc* gc=NULL;
       
    59 		User::LeaveIfError(device->CreateContext(gc));
       
    60 		CleanupStack::PushL(gc);
       
    61 		TPoint origin(0,0);
       
    62 		gc->BitBlt(origin,&aMask);
       
    63 		CleanupStack::PopAndDestroy(2); // gc, device
       
    64 		CleanupStack::Pop(newMask);
       
    65 		}
       
    66 	return newMask;
       
    67 	}
       
    68 
       
    69 //
       
    70 // Class CApaMaskedBitmap
       
    71 //
       
    72 
       
    73 CApaMaskedBitmap::CApaMaskedBitmap()
       
    74 :CFbsBitmap()
       
    75 	{}
       
    76 
       
    77 EXPORT_C CApaMaskedBitmap::~CApaMaskedBitmap()
       
    78 /** Destructor.
       
    79 
       
    80 Frees resources owned by the object prior to its destruction. */
       
    81 	{
       
    82 	delete iMask;
       
    83 	}
       
    84 
       
    85 EXPORT_C CApaMaskedBitmap* CApaMaskedBitmap::NewLC()
       
    86 /** Creates a default application icon object.
       
    87 
       
    88 @return A pointer to the new application icon object. */
       
    89 	{
       
    90 	CApaMaskedBitmap* self=new(ELeave) CApaMaskedBitmap;
       
    91 	CleanupStack::PushL(self);
       
    92 	self->ConstructL();
       
    93 	return self;
       
    94 	}
       
    95 
       
    96 EXPORT_C CApaMaskedBitmap* CApaMaskedBitmap::NewL(const CApaMaskedBitmap* aSourceIcon)
       
    97 /** Creates a new application icon object, making a duplicate copy of an existing 
       
    98 application icon.
       
    99 
       
   100 @param aSourceIcon A pointer to an existing application icon.
       
   101 @return A pointer to the new application icon object. */
       
   102 	{
       
   103 	CApaMaskedBitmap* self=new(ELeave) CApaMaskedBitmap;
       
   104 	CleanupStack::PushL(self);
       
   105 	self->ConstructL();
       
   106 	User::LeaveIfError( self->iMask->Duplicate(aSourceIcon->Mask()->Handle()) );
       
   107 	User::LeaveIfError( self->Duplicate(aSourceIcon->Handle()) );
       
   108 	CleanupStack::Pop(self);
       
   109 	return self;
       
   110 	}
       
   111 
       
   112 void CApaMaskedBitmap::ConstructL()
       
   113 	{
       
   114 	__DECLARE_NAME(_S("CApaMaskedBitmap"));
       
   115 	if (!iFbs)
       
   116 		User::Leave(KErrCouldNotConnect);
       
   117 	iMask=new(ELeave) CFbsBitmap;
       
   118 	}
       
   119 
       
   120 EXPORT_C CFbsBitmap* CApaMaskedBitmap::Mask() const
       
   121 /** Gets the icon's mask.
       
   122 
       
   123 @return A pointer to the mask bitmap. */
       
   124 	{
       
   125 	return iMask;
       
   126 	}
       
   127 
       
   128 EXPORT_C void CApaMaskedBitmap::InternalizeL(RReadStream& aStream)
       
   129 /** Internalizes the application icon from the read stream.
       
   130 
       
   131 @param aStream The read stream. */
       
   132 	{
       
   133 	__ASSERT_DEBUG(iMask, Panic(EPanicNullPointer));
       
   134 	CFbsBitmap::InternalizeL(aStream);
       
   135 	aStream >> *iMask;
       
   136 
       
   137 	// Try to reduce the colour depth of the bitmap mask
       
   138 	CFbsBitmap* tempMask;
       
   139 	tempMask = TryCompressMaskL(*iMask);
       
   140 	// tempMask = NULL if iMask could not be reduced
       
   141 	if (tempMask != NULL)
       
   142 		{
       
   143 		delete iMask;
       
   144 		iMask = tempMask;
       
   145 		}
       
   146 	}
       
   147 
       
   148 void CApaMaskedBitmap::SetRomBitmapL(TUint8* aRomPointer)
       
   149 	{
       
   150 	__ASSERT_DEBUG(iMask, Panic(EPanicNullPointer));
       
   151 	TInt bitmapSize = 0;
       
   152 	CFbsBitmap::SetRomBitmapL(reinterpret_cast<CBitwiseBitmap*>(aRomPointer),bitmapSize);
       
   153 
       
   154 	aRomPointer += bitmapSize;
       
   155 
       
   156 	iMask->SetRomBitmapL(reinterpret_cast<CBitwiseBitmap*>(aRomPointer),bitmapSize);
       
   157 	}
       
   158 
       
   159 EXPORT_C void CApaMaskedBitmap::ExternalizeL(RWriteStream& aStream) const
       
   160 /** Externalises the application icon to the specified stream.
       
   161 
       
   162 @param aStream The write stream. */
       
   163 	{
       
   164 	__ASSERT_DEBUG(iMask, Panic(EPanicNullPointer));
       
   165 	CFbsBitmap::ExternalizeL(aStream);
       
   166 	aStream << *iMask;
       
   167 	}
       
   168 
       
   169 
       
   170 EXPORT_C void CApaMaskedBitmap::SetMaskBitmap(CFbsBitmap* aMask)
       
   171 /**
       
   172 Sets the icon's mask
       
   173 
       
   174 @publishedAll
       
   175 @released
       
   176 @param     aMask A pointer to the mask bitmap       
       
   177 */
       
   178 	{
       
   179 	delete iMask;
       
   180 	iMask = aMask;
       
   181 	}
       
   182 
       
   183 
       
   184 
       
   185 #if (defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER))
       
   186 
       
   187 
       
   188 
       
   189 //
       
   190 // Class CApaAIFCaption
       
   191 //
       
   192 
       
   193 CApaAIFCaption::~CApaAIFCaption()
       
   194 	{
       
   195 	delete iCaption;
       
   196 	}
       
   197 
       
   198 CApaAIFCaption* CApaAIFCaption::NewLC(TLanguage aLanguage,const TDesC& aCaption)
       
   199 	// static
       
   200 	{
       
   201 	CApaAIFCaption* self=new(ELeave) CApaAIFCaption;
       
   202 	CleanupStack::PushL(self);
       
   203 	self->ConstructL(aLanguage,aCaption);
       
   204 	return self;
       
   205 	}
       
   206 
       
   207 void CApaAIFCaption::ConstructL(TLanguage aLanguage,const TDesC& aCaption)
       
   208 	{
       
   209 	iLanguage=aLanguage;
       
   210     HBufC* newCaption=aCaption.AllocL();
       
   211 	delete(iCaption); // after the AllocL succeeds
       
   212 	iCaption=newCaption;
       
   213 	}
       
   214 
       
   215 TLanguage CApaAIFCaption::Language() const
       
   216 	{
       
   217 	return iLanguage;
       
   218 	}
       
   219 
       
   220 TApaAppCaption CApaAIFCaption::Caption() const
       
   221 	{
       
   222 	return *iCaption;
       
   223 	}
       
   224 
       
   225 CApaAIFCaption::CApaAIFCaption()
       
   226 	{
       
   227 	}
       
   228 
       
   229 void CApaAIFCaption::InternalizeL(RReadStream& aStream)
       
   230 	{
       
   231 	HBufC* newCaption=HBufC::NewL(aStream,KApaMaxAppCaption);
       
   232 	delete(iCaption);
       
   233 	iCaption=newCaption;
       
   234 	iLanguage=(TLanguage)aStream.ReadInt16L();
       
   235 	}
       
   236 
       
   237 void CApaAIFCaption::ExternalizeL(RWriteStream& aStream) const
       
   238 	{
       
   239 	aStream << *iCaption;
       
   240 	aStream.WriteInt16L(iLanguage);
       
   241 	}
       
   242 
       
   243 
       
   244 //
       
   245 // Class CApaAIFViewData
       
   246 //
       
   247 
       
   248 CApaAIFViewData::~CApaAIFViewData()
       
   249 	{
       
   250 	if (iCaptionArray)
       
   251 		iCaptionArray->ResetAndDestroy();
       
   252 	delete iCaptionArray;
       
   253 	if (iIconArray)
       
   254 		iIconArray->ResetAndDestroy();
       
   255 	delete iIconArray;
       
   256 	delete iIconIndexArray;
       
   257 	}
       
   258 
       
   259 CApaAIFViewData::CApaAIFViewData()
       
   260 	{}
       
   261 
       
   262 void CApaAIFViewData::ConstructL()
       
   263 	{
       
   264 	iCaptionArray=new(ELeave) CArrayPtrFlat<CApaAIFCaption>(4);
       
   265 	iIconArray=new(ELeave) CArrayPtrFlat<CApaMaskedBitmap>(4);
       
   266 	}
       
   267 
       
   268 CApaAIFViewData* CApaAIFViewData::NewLC()
       
   269 	// static
       
   270 	{
       
   271 	CApaAIFViewData* self=new(ELeave) CApaAIFViewData;
       
   272 	CleanupStack::PushL(self);
       
   273 	self->ConstructL();
       
   274 	return self;
       
   275 	}
       
   276 
       
   277 CApaAIFViewData* CApaAIFViewData::NewLC(const CApaAIFViewData& aSourceData)
       
   278 	{
       
   279 	CApaAIFViewData* self = CApaAIFViewData::NewLC();
       
   280 	self->ConstructL(aSourceData);
       
   281 	return self;
       
   282 	}
       
   283 
       
   284 void CApaAIFViewData::ConstructL(const CApaAIFViewData& aSourceData)
       
   285 	{
       
   286 	// Make a copy of aSourceData in this object
       
   287 	// N.B. this is not an atomic operation and if the function leaves
       
   288 	// there is no guarantee that this object will be in a valid state.
       
   289 	// Should only be called from CApaAIFViewData::NewLC(const CApaAIFViewData& aSourceData)
       
   290 	//
       
   291 	// Screen mode
       
   292 	iScreenMode = aSourceData.iScreenMode;
       
   293 	// Icon array
       
   294 	TInt count = (aSourceData.iIconArray ? aSourceData.iIconArray->Count() : 0);
       
   295 	TInt i;
       
   296 	for (i=0; i < count; i++)
       
   297 		{
       
   298 		// Get the icon from array and duplicate it
       
   299 		const CApaMaskedBitmap& srcIcon = (*aSourceData.iIconArray->At(i));
       
   300 		CApaMaskedBitmap* icon = CApaMaskedBitmap::NewLC();
       
   301 		User::LeaveIfError(icon->Duplicate(srcIcon.Handle()));
       
   302 
       
   303 		CFbsBitmap* mask = new(ELeave) CFbsBitmap();
       
   304 		CleanupStack::PushL(mask);
       
   305 		User::LeaveIfError(mask->Duplicate(srcIcon.Mask()->Handle()));
       
   306 		icon->SetMaskBitmap(mask);
       
   307 		CleanupStack::Pop(mask);
       
   308 
       
   309 		iIconArray->AppendL(icon);
       
   310 		CleanupStack::Pop(icon);
       
   311 		}
       
   312 	// Caption array
       
   313 	count = (aSourceData.iCaptionArray ? aSourceData.iCaptionArray->Count() : 0);
       
   314 	for (i=0; i < count; i++)
       
   315 		{
       
   316 		const CApaAIFCaption& srcCaption = (*aSourceData.iCaptionArray->At(i));
       
   317 		CApaAIFCaption* caption = CApaAIFCaption::NewLC(srcCaption.Language(), srcCaption.Caption());
       
   318 		iCaptionArray->AppendL(caption);
       
   319 		CleanupStack::Pop(caption);
       
   320 		}
       
   321 	// View UID
       
   322 	iViewUid = aSourceData.iViewUid;
       
   323 	// Icon index array
       
   324 	count = (aSourceData.iIconIndexArray ? aSourceData.iIconIndexArray->Count() : 0);
       
   325 	for (i=0; i < count; i++)
       
   326 		{
       
   327 		AddIconIndexL(aSourceData.iIconIndexArray->At(i));
       
   328 		}
       
   329 	}
       
   330 
       
   331 void CApaAIFViewData::LoadIconsL(const TDesC& aFileName, TUint aMbmOffset)
       
   332 	{
       
   333 	// This function is called when loading the AIF version 2 format
       
   334 	// When loading the RSC block, any view icons will have been added to iIconIndexArray as MBM indexes.
       
   335 	// This function loads the view icons from the MBM using these indexes.
       
   336 	__ASSERT_DEBUG(iIconArray->Count()==0,Panic(EDPanicArrayNotEmpty));
       
   337 	const TInt iconCount = (iIconIndexArray ? iIconIndexArray->Count() : 0);
       
   338 	for (TInt i=0; i < iconCount; i++)
       
   339 		{
       
   340 		const TInt mbmIndex = iIconIndexArray->At(i) * 2;	// Each icon is a mask and bitmap == 2 items in MBM
       
   341 		CApaMaskedBitmap* icon = CApaMaskedBitmap::NewLC();
       
   342 		CFbsBitmap* mask = new(ELeave) CFbsBitmap();
       
   343 		CleanupStack::PushL(mask);
       
   344 		User::LeaveIfError(icon->Load(aFileName, mbmIndex, ETrue, aMbmOffset));
       
   345 		User::LeaveIfError(mask->Load(aFileName, mbmIndex + 1, ETrue, aMbmOffset));
       
   346 		icon->SetMaskBitmap(mask);
       
   347 		CleanupStack::Pop(mask);
       
   348 		iIconArray->AppendL(icon);
       
   349 		CleanupStack::Pop(icon);
       
   350 		}
       
   351 	}
       
   352 
       
   353 void CApaAIFViewData::InternalizeL(RReadStream& aStream)
       
   354 	{
       
   355 	// Uid
       
   356 	iViewUid.iUid=aStream.ReadInt32L();
       
   357 	// Screen mode
       
   358 	iScreenMode=aStream.ReadInt32L();
       
   359 	// Captions
       
   360 	if (iCaptionArray)
       
   361 		iCaptionArray->ResetAndDestroy();
       
   362 	else
       
   363 		iCaptionArray=new(ELeave) CArrayPtrFlat<CApaAIFCaption>(1);
       
   364 	TCardinality card;
       
   365 	aStream>>card;
       
   366 	const TInt captionCount(card);
       
   367 	CApaAIFCaption* caption=NULL;
       
   368 	for (TInt ii=0;ii<captionCount;ii++)
       
   369 		{
       
   370 		caption=new(ELeave) CApaAIFCaption();
       
   371 		CleanupStack::PushL(caption);
       
   372 		aStream >> *caption;
       
   373 		iCaptionArray->AppendL(caption);
       
   374 		CleanupStack::Pop(caption);
       
   375 		}
       
   376 	// Icons
       
   377 	if (iIconArray)
       
   378 		iIconArray->ResetAndDestroy();
       
   379 	else
       
   380 		iIconArray=new(ELeave) CArrayPtrFlat<CApaMaskedBitmap>(2);
       
   381 	aStream>>card;
       
   382 	const TInt iconCount(card);
       
   383 	CApaMaskedBitmap* icon=NULL;
       
   384 	for (TInt jj=0;jj<iconCount;jj++)
       
   385 		{
       
   386 		icon=CApaMaskedBitmap::NewLC();
       
   387 		aStream >> *icon;
       
   388 		iIconArray->AppendL(icon);
       
   389 		CleanupStack::Pop(icon);
       
   390 		}
       
   391 	}
       
   392 
       
   393 void CApaAIFViewData::ExternalizeL(RWriteStream& aStream) const
       
   394 	{
       
   395 	// Uid
       
   396 	aStream.WriteInt32L(iViewUid.iUid);
       
   397 	// Screen Mode
       
   398 	aStream.WriteInt32L(iScreenMode);
       
   399 	// Captions
       
   400 	const TInt captionCount=iCaptionArray->Count();
       
   401 	aStream<<TCardinality(captionCount);
       
   402 	for (TInt ii=0;ii<captionCount;ii++)
       
   403 		{
       
   404 		aStream << *((*iCaptionArray)[ii]);
       
   405 		}
       
   406 	// Icons
       
   407 	const TInt iconCount=iIconArray->Count();
       
   408 	aStream<<TCardinality(iconCount);
       
   409 	for (TInt jj=0;jj<iconCount;jj++)
       
   410 		{
       
   411 		aStream << *((*iIconArray)[jj]);
       
   412 		}
       
   413 	}
       
   414 
       
   415 void CApaAIFViewData::SetScreenMode(TInt aScreenMode)
       
   416 	{
       
   417 	iScreenMode=aScreenMode;
       
   418 	}
       
   419 
       
   420 void CApaAIFViewData::AddCaptionL(TLanguage aLanguage,const TDesC& aCaption)
       
   421 	{
       
   422 	CApaAIFCaption* caption=CApaAIFCaption::NewLC(aLanguage,aCaption);
       
   423 	iCaptionArray->AppendL(caption);
       
   424 	CleanupStack::Pop(caption);
       
   425 	}
       
   426 
       
   427 void CApaAIFViewData::AddIconL(CApaMaskedBitmap& aIcon)
       
   428 	{
       
   429 	CApaMaskedBitmap* icon=CApaMaskedBitmap::NewL(&aIcon);
       
   430 	CleanupStack::PushL(icon);
       
   431 	iIconArray->AppendL(icon);
       
   432 	CleanupStack::Pop(icon);
       
   433 	}
       
   434 
       
   435 void CApaAIFViewData::AddIconIndexL(TInt aIndex)
       
   436 	{
       
   437 	if (!iIconIndexArray)
       
   438 		{
       
   439 		iIconIndexArray = new(ELeave) CArrayFixFlat<TInt>(4);
       
   440 		}
       
   441 	iIconIndexArray->AppendL(aIndex);
       
   442 	}
       
   443 
       
   444 void CApaAIFViewData::SetViewUid(TUid aUid)
       
   445 	{
       
   446 	iViewUid=aUid;
       
   447 	}
       
   448 
       
   449 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TApaAppCaption CApaAIFViewData::CaptionL(TLanguage aLanguage) const
       
   450 	{
       
   451 	RFs fs;
       
   452 	CleanupClosePushL(fs);
       
   453 	User::LeaveIfError(fs.Connect());
       
   454 	RArray<TLanguage> downgradePath;
       
   455 	CleanupClosePushL(downgradePath);
       
   456 	BaflUtils::GetDowngradePathL(fs,aLanguage,downgradePath);
       
   457 	TApaAppCaption result(KNullDesC);
       
   458 	const TInt languagecount=downgradePath.Count();
       
   459 	const TInt count=iCaptionArray->Count();
       
   460 	for (TInt j=0; j<languagecount; j++)
       
   461 		{
       
   462 		for (TInt ii=0;ii<count;ii++)
       
   463 			{
       
   464 			const CApaAIFCaption& caption=*(*iCaptionArray)[ii];
       
   465 			if (caption.Language()==downgradePath[j])
       
   466 				{
       
   467 				result=caption.Caption();
       
   468 				j=languagecount; // to exit outer loop
       
   469 				break;
       
   470 				}
       
   471 			}
       
   472 		}
       
   473 	CleanupStack::PopAndDestroy(2, &fs);
       
   474 	return result;
       
   475 	}
       
   476 
       
   477 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaMaskedBitmap* CApaAIFViewData::IconByIndexL(TInt aIndex) const
       
   478 	{
       
   479 	return (*iIconArray)[aIndex];
       
   480 	}
       
   481 
       
   482 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TInt CApaAIFViewData::NumberOfIcons() const
       
   483 	{
       
   484 	return (iIconIndexArray ? iIconIndexArray->Count() : iIconArray->Count());
       
   485 	}
       
   486 
       
   487 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TUid CApaAIFViewData::ViewUid() const
       
   488 	{
       
   489 	return iViewUid;
       
   490 	}
       
   491 
       
   492 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TInt CApaAIFViewData::ScreenMode() const
       
   493 	{
       
   494 	return iScreenMode;
       
   495 	}
       
   496 
       
   497 //
       
   498 // Class CApaAppInfoFile
       
   499 //
       
   500 
       
   501 CApaAppInfoFile::CApaAppInfoFile(RFs& aFs)
       
   502 :iFs(aFs)
       
   503 	{}
       
   504 
       
   505 void CApaAppInfoFile::TCaptionHeader::InternalizeL(RReadStream& aStream)
       
   506 	{
       
   507 	aStream >> iCaption;
       
   508 	iLanguage=(TLanguage)aStream.ReadInt16L();
       
   509 	}
       
   510 
       
   511 void CApaAppInfoFile::TCaptionHeader::ExternalizeL(RWriteStream& aStream) const
       
   512 	{
       
   513 	aStream	<< iCaption;
       
   514 	aStream.WriteInt16L(iLanguage);
       
   515 	}
       
   516 
       
   517 void CApaAppInfoFile::TIconHeader::InternalizeL(RReadStream& aStream)
       
   518 	{
       
   519 	aStream >> iIcon;
       
   520 	iIconSideInPixels=aStream.ReadInt16L();
       
   521 	}
       
   522 
       
   523 void CApaAppInfoFile::TIconHeader::ExternalizeL(RWriteStream& aStream) const
       
   524 	{
       
   525 	aStream	<< iIcon;
       
   526 	aStream.WriteInt16L(iIconSideInPixels);
       
   527 	}
       
   528 
       
   529 void CApaAppInfoFile::TDataTypeHeader::InternalizeL(RReadStream& aStream)
       
   530 	{
       
   531 	aStream >> iDataType;
       
   532 	iPriority=aStream.ReadInt16L();
       
   533 	}
       
   534 
       
   535 void CApaAppInfoFile::TDataTypeHeader::ExternalizeL(RWriteStream& aStream) const
       
   536 	{
       
   537 	aStream << iDataType;
       
   538 	aStream.WriteInt16L(iPriority);
       
   539 	}
       
   540 
       
   541 void CApaAppInfoFile::TViewDataHeader::InternalizeL(RReadStream& aStream)
       
   542 	{
       
   543 	aStream >> iViewData;
       
   544 	}
       
   545 
       
   546 void CApaAppInfoFile::TViewDataHeader::ExternalizeL(RWriteStream& aStream) const
       
   547 	{
       
   548 	aStream << iViewData;
       
   549 	}
       
   550 
       
   551 void CApaAppInfoFile::TFileOwnershipInfoHeader::InternalizeL(RReadStream& aStream)
       
   552 	{
       
   553 	aStream >> iOwnedFileName;
       
   554 	}
       
   555 
       
   556 void CApaAppInfoFile::TFileOwnershipInfoHeader::ExternalizeL(RWriteStream& aStream) const
       
   557 	{
       
   558 	aStream	<< iOwnedFileName;
       
   559 	}
       
   560 
       
   561 CApaAppInfoFile::~CApaAppInfoFile()
       
   562 	{
       
   563 	if (iCaptionHeaderArray)
       
   564 		{
       
   565 		const TInt maxIndex=iCaptionHeaderArray->Count() - 1;
       
   566 		for(TInt i=maxIndex; i>=0; i--)
       
   567 			{
       
   568 			const TSwizzle<HBufC>& caption = iCaptionHeaderArray->At(i).iCaption; 
       
   569 			if (caption.IsPtr())
       
   570 				{
       
   571 				delete caption.AsPtr();
       
   572 				iCaptionHeaderArray->Delete(i);
       
   573 				}
       
   574 			}
       
   575 		}
       
   576 	delete iCaptionHeaderArray;
       
   577 	delete iIconHeaderArray;
       
   578 	if (iDataTypeHeaderArray)
       
   579 		{
       
   580 		const TInt maxIndex=iDataTypeHeaderArray->Count() - 1;
       
   581 		for(TInt i=maxIndex; i>=0; i--)
       
   582 			{
       
   583 			const TSwizzle<TDataType>& dataType = iDataTypeHeaderArray->At(i).iDataType;
       
   584 			if (dataType.IsPtr())
       
   585 				{
       
   586 				delete dataType.AsPtr();
       
   587 				iDataTypeHeaderArray->Delete(i);
       
   588 				}
       
   589 			}
       
   590 		}
       
   591 	delete iDataTypeHeaderArray;
       
   592 	if (iViewDataHeaderArray)
       
   593 		{
       
   594 		const TInt maxIndex=iViewDataHeaderArray->Count() - 1;
       
   595 		for(TInt i=maxIndex; i>=0; i--)
       
   596 			{
       
   597 			const TSwizzle<CApaAIFViewData>& viewData = iViewDataHeaderArray->At(i).iViewData;
       
   598 			if (viewData.IsPtr())
       
   599 				{
       
   600 				delete viewData.AsPtr();
       
   601 				iViewDataHeaderArray->Delete(i);
       
   602 				}
       
   603 			}
       
   604 		}
       
   605 	delete iViewDataHeaderArray;
       
   606 	if (iFileOwnershipInfoHeaderArray)
       
   607 		{
       
   608 		const TInt maxIndex=iFileOwnershipInfoHeaderArray->Count() - 1;
       
   609 		for(TInt i=maxIndex; i>=0; i--)
       
   610 			{
       
   611 			const TSwizzle<HBufC>& fileName = iFileOwnershipInfoHeaderArray->At(i).iOwnedFileName;
       
   612 			if (fileName.IsPtr())
       
   613 				{
       
   614 				delete fileName.AsPtr();
       
   615 				iFileOwnershipInfoHeaderArray->Delete(i);
       
   616 				}
       
   617 			}
       
   618 		}
       
   619 	delete iFileOwnershipInfoHeaderArray;
       
   620 	delete iStore;
       
   621 	}
       
   622 
       
   623 void CApaAppInfoFile::ConstructL()
       
   624 	{
       
   625 	iCaptionHeaderArray=new(ELeave) CArrayFixFlat<TCaptionHeader>(4);
       
   626 	iIconHeaderArray=new(ELeave) CArrayFixFlat<TIconHeader>(4);
       
   627 	iDataTypeHeaderArray=new(ELeave) CArrayFixFlat<TDataTypeHeader>(4);
       
   628 	iViewDataHeaderArray=new(ELeave) CArrayFixFlat<TViewDataHeader>(4);
       
   629 	iFileOwnershipInfoHeaderArray=new(ELeave) CArrayFixFlat<TFileOwnershipInfoHeader>(4);
       
   630 	}
       
   631 
       
   632 //
       
   633 // Class CApaAppInfoFileReader
       
   634 //
       
   635 
       
   636 CApaAppInfoFileReader::CApaAppInfoFileReader(RFs& aFs)
       
   637 	:CApaAppInfoFile(aFs)
       
   638 	{}
       
   639 
       
   640 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaAppInfoFileReader::~CApaAppInfoFileReader()
       
   641 /** Destructor.
       
   642 
       
   643 Destroys all resources owned by the aif file reader. */
       
   644 	{
       
   645 	delete iDefaultCaption;
       
   646 	delete iAifFileName;
       
   647 	}
       
   648 
       
   649 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaAppInfoFileReader* CApaAppInfoFileReader::NewLC(RFs& aFs, const TDesC& aFileName,TUid aUid)
       
   650 /** Allocates and constructs the aif file reader and internalises the contents 
       
   651 of the specified aif file.
       
   652 
       
   653 @param aFs Connected session with the file server.
       
   654 @param aFileName The full path and (language-neutral) filename of the aif file.
       
   655 @param aApplicationUid The application's UID. If you specify a value other 
       
   656 than KNullUid, the aif file must have this value as its third (most derived) 
       
   657 UID.
       
   658 @leave KErrCorrupt The UID specified is incorrect, or if KNullUid was specified, 
       
   659 the aif file's second UID was not KUidAppInfoFile.
       
   660 @return Pointer to the newly constructed and initialised aif file reader. The 
       
   661 object is left on the cleanup stack. */
       
   662 	{
       
   663 	CApaAppInfoFileReader* self=new(ELeave) CApaAppInfoFileReader(aFs);
       
   664 	CleanupStack::PushL(self);
       
   665 	self->ConstructL(aFileName,aUid);
       
   666 	return self;
       
   667 	}
       
   668 
       
   669 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaAppInfoFileReader* CApaAppInfoFileReader::NewL(RFs& aFs, const TDesC& aFileName,TUid aUid)
       
   670 /** Allocates and constructs the aif file reader and internalises the contents 
       
   671 of the specified aif file.
       
   672 
       
   673 @param aFs Connected session with the file server.
       
   674 @param aFileName The full path and (language-neutral) filename of the aif file.
       
   675 @param aApplicationUid The application's UID. If you specify a value other 
       
   676 than KNullUid, the aif file must have this as its third (most derived) UID.
       
   677 @leave KErrCorrupt The UID specified is incorrect, or if KNullUid was specified, 
       
   678 the aif file's second UID was not KUidAppInfoFile.
       
   679 @return Pointer to the newly constructed and initialised aif file reader. The 
       
   680 object is popped from the cleanup stack. */
       
   681 	{
       
   682 	CApaAppInfoFileReader* self=CApaAppInfoFileReader::NewLC(aFs, aFileName,aUid);
       
   683 	CleanupStack::Pop(self);
       
   684 	return self;
       
   685 	}
       
   686 
       
   687 void CApaAppInfoFileReader::ConstructL(const TDesC& aFileName,TUid aMostDerivedUid)
       
   688 	{
       
   689 	__DECLARE_NAME(_S("CApaAppInfoFileReader"));
       
   690 	CApaAppInfoFile::ConstructL();
       
   691 	TParse parse;
       
   692 	User::LeaveIfError(parse.Set(aFileName,NULL,NULL));
       
   693 	iDefaultCaption=parse.Name().AllocL();
       
   694 	TFileName localFileName;
       
   695 	localFileName.Copy(aFileName);
       
   696 	BaflUtils::NearestLanguageFile(iFs,localFileName);
       
   697 	iRomPointer=iFs.IsFileInRom(localFileName);
       
   698 
       
   699 	iAifFileName = localFileName.AllocL();
       
   700 
       
   701 	// Get the file type
       
   702 	TEntry entry;
       
   703 	User::LeaveIfError(iFs.Entry(localFileName, entry));
       
   704 	if (!entry.IsTypeValid())
       
   705 		{
       
   706 		// Invalid UID
       
   707 		User::Leave(KErrCorrupt);
       
   708 		}
       
   709 
       
   710 	// Determine the type of AIF file
       
   711 	const TUidType& type = entry.iType;
       
   712 	if ((
       
   713 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
   714 		type[1] == KUidInterimFormatFileForJavaMIDletInstaller
       
   715 #endif
       
   716 		) && (aMostDerivedUid == KNullUid || type[2] == aMostDerivedUid))
       
   717 		{
       
   718 		// Read old AIF format file
       
   719 		CFileStore* store = CFileStore::OpenL(iFs,localFileName,EFileRead|EFileShareReadersOnly);
       
   720 		iStore = store;
       
   721 		RStoreReadStream inStream;
       
   722 		inStream.OpenLC(*store,store->Root());
       
   723 		InternalizeL(inStream);
       
   724 		CleanupStack::PopAndDestroy(&inStream);
       
   725 		}
       
   726 	else
       
   727 		{
       
   728 		// it's the wrong file!!!!!
       
   729 		User::Leave(KErrCorrupt);
       
   730 		}
       
   731 	}
       
   732 
       
   733 void CApaAppInfoFileReader::LoadAifFileVersionTwoL(const TDesC& aFileName, TUid aMostDerivedUid)
       
   734 	{
       
   735 	// Version 2 AIF format:
       
   736 	//
       
   737 	//  +--------------------- - - -------- - - ---+
       
   738 	//  |  UID  | RSC len | RSC block |  MBM block |
       
   739 	//  +--------------------- - - -------- - - ---+
       
   740 	//
       
   741 	// UID = 4 bytes (incl. checksum)
       
   742 	// RSC len = 4 bytes
       
   743 	// RSC block = RSC len bytes + padding to make MBM block 4-byte aligned
       
   744 	// MBM block = remainder of file, 4-byte aligned
       
   745 	//
       
   746 	// Read 16-bit block for length of RSC file
       
   747 	RFile file;
       
   748 	User::LeaveIfError(file.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly));
       
   749 	CleanupClosePushL(file);
       
   750 	TInt aifHeaderOffset = 16;	// skip over UID and checksum
       
   751 	User::LeaveIfError(file.Seek(ESeekStart, aifHeaderOffset));
       
   752 	TBuf8<4> buffer;
       
   753 	User::LeaveIfError(file.Read(buffer));
       
   754 	const TInt rscLength = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
       
   755 	TInt fileSize = 0;
       
   756 	User::LeaveIfError(file.Size(fileSize));
       
   757 	CleanupStack::PopAndDestroy(&file);
       
   758 
       
   759 	// Open RSC file using offset
       
   760 	RResourceFile resFile;
       
   761 	resFile.OpenL(iFs, aFileName, aifHeaderOffset + 4, rscLength);
       
   762 	CleanupClosePushL(resFile);
       
   763 
       
   764 	// Read the first resource (AIF_DATA struct)
       
   765 	HBufC8* resource = resFile.AllocReadLC(1);
       
   766 
       
   767 	TResourceReader reader;
       
   768 	reader.SetBuffer(resource);
       
   769 
       
   770 	// Read app UID
       
   771 	const TInt uid = reader.ReadInt32();
       
   772 	if ((aMostDerivedUid != KNullUid) && (uid != aMostDerivedUid.iUid))
       
   773 		{
       
   774 		User::Leave(KErrCorrupt);
       
   775 		}
       
   776 	// Num icons
       
   777 	const TInt numIcons = reader.ReadInt16();
       
   778 
       
   779 	// Caption array
       
   780 	const TInt captionArraySize = reader.ReadInt16();
       
   781 	TInt i;
       
   782 	for (i=0; i < captionArraySize; i++)
       
   783 		{
       
   784 		TCaptionHeader header;
       
   785 		header.iLanguage = static_cast<TLanguage>(reader.ReadInt16());
       
   786 		TPtrC caption = reader.ReadTPtrC();
       
   787 		header.iCaption = caption.AllocLC();
       
   788 		iCaptionHeaderArray->AppendL(header);
       
   789 		CleanupStack::Pop(header.iCaption);
       
   790 		}
       
   791 
       
   792 	// Read capability flags
       
   793 	iCapability.iAppIsHidden = reader.ReadInt8();
       
   794 	iCapability.iEmbeddability = static_cast<TApaAppCapability::TEmbeddability>(reader.ReadInt8());
       
   795 	iCapability.iSupportsNewFile = reader.ReadInt8();
       
   796 	iCapability.iLaunchInBackground = reader.ReadInt8();
       
   797 
       
   798 	// Group name
       
   799 	iCapability.iGroupName = reader.ReadTPtrC();
       
   800 
       
   801 	// Datatype list
       
   802 	const TInt dataTypeArraySize = reader.ReadInt16();
       
   803 	for (i=0; i < dataTypeArraySize; i++)
       
   804 		{
       
   805 		TDataTypeHeader dataTypeHeader;
       
   806 		dataTypeHeader.iPriority = (TDataTypePriority)reader.ReadInt16();
       
   807 		TPtrC8 dataTypePtr = reader.ReadTPtrC8();
       
   808 		TDataType* dataType = new(ELeave) TDataType(dataTypePtr);
       
   809 		CleanupStack::PushL(dataType);
       
   810 		dataTypeHeader.iDataType = dataType;
       
   811 		iDataTypeHeaderArray->AppendL(dataTypeHeader);
       
   812 		CleanupStack::Pop(dataType);
       
   813 		}
       
   814 
       
   815 	// Read MBM block
       
   816 	iMbmOffset = aifHeaderOffset + 4 + rscLength;
       
   817 	// Calculate any padding after the RSC (MBM block must be 4-byte aligned)
       
   818 	TInt mbmPadding = (rscLength % 4);
       
   819 	if (mbmPadding)
       
   820 		mbmPadding = 4 - mbmPadding;
       
   821 	iMbmOffset += mbmPadding;
       
   822 	TInt iconIndex = 0;
       
   823 	if (fileSize > iMbmOffset)
       
   824 		{
       
   825 		// Populate the icon array
       
   826 		AddIconHeadersL(aFileName, iMbmOffset, numIcons);
       
   827 		iconIndex += numIcons;
       
   828 		}
       
   829 
       
   830 	// View list
       
   831 	const TInt viewListArraySize = reader.ReadInt16();
       
   832 	for (i=0; i < viewListArraySize; i++)
       
   833 		{
       
   834 		CApaAIFViewData* viewData = CApaAIFViewData::NewLC();
       
   835 		viewData->SetViewUid(TUid::Uid(reader.ReadInt32()));	// Read UID
       
   836 		viewData->SetScreenMode(reader.ReadInt32());			// Read screenmode
       
   837 		TInt numViewIcons = reader.ReadInt16();					// Read num icons
       
   838 		TInt j = 0;
       
   839 		for ( ; j < numViewIcons; j++)
       
   840 			{
       
   841 			viewData->AddIconIndexL(iconIndex);
       
   842 			iconIndex++;
       
   843 			}
       
   844 		// Read caption array
       
   845 		const TInt viewCaptArraySize = reader.ReadInt16();
       
   846 		for (j=0; j < viewCaptArraySize; j++)
       
   847 			{
       
   848 			TLanguage langCode = static_cast<TLanguage>(reader.ReadInt16());
       
   849 			TPtrC caption = reader.ReadTPtrC();
       
   850 			viewData->AddCaptionL(langCode, caption);
       
   851 			}
       
   852 		TViewDataHeader header;
       
   853 		header.iViewData = viewData;
       
   854 		iViewDataHeaderArray->AppendL(header);
       
   855 		CleanupStack::Pop(viewData);
       
   856 		}
       
   857 
       
   858 	// File ownership list
       
   859 	const TInt fileOwnershipArraySize = reader.ReadInt16();
       
   860 	for (i=0; i < fileOwnershipArraySize; i++)
       
   861 		{
       
   862 		// Filename
       
   863 		TFileOwnershipInfoHeader ownership;
       
   864 		TPtrC fileNamePtr = reader.ReadTPtrC();
       
   865 		ownership.iOwnedFileName = fileNamePtr.AllocLC();
       
   866 		iFileOwnershipInfoHeaderArray->AppendL(ownership);
       
   867 		CleanupStack::Pop(ownership.iOwnedFileName);
       
   868 		}
       
   869 	CleanupStack::PopAndDestroy(2, &resFile);
       
   870 	}
       
   871 
       
   872 void CApaAppInfoFileReader::AddIconHeadersL(const TDesC& aFileName, TInt32 aFileOffset, TInt aNumIcons)
       
   873 	{
       
   874 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap();
       
   875 	CleanupStack::PushL(bmp);
       
   876 	for (TInt i=0; i < aNumIcons; i++)
       
   877 		{
       
   878 		User::LeaveIfError(bmp->Load(aFileName, i * 2, ETrue, aFileOffset));
       
   879 		TSize iconSize = bmp->SizeInPixels();
       
   880 		TIconHeader header;
       
   881 		header.iIcon = NULL;
       
   882 		header.iIconMain = NULL;
       
   883 		header.iIconMask = NULL;
       
   884 		header.iIconSideInPixels = iconSize.iWidth;
       
   885 		iIconHeaderArray->AppendL(header);
       
   886 		}
       
   887 	CleanupStack::PopAndDestroy(bmp);
       
   888 	}
       
   889 
       
   890 void CApaAppInfoFileReader::InternalizeL(RReadStream& aStream)
       
   891 	{
       
   892 	aStream>> *iCaptionHeaderArray;		// Internalizes the headers only
       
   893 	aStream>> *iIconHeaderArray;
       
   894 	aStream>> iCapability;
       
   895 	TInt version=EAifVersionOriginal;
       
   896 	TRAP_IGNORE(version=aStream.ReadInt32L());
       
   897 	if (version<EAifVersionAddsDataType)
       
   898 		return;
       
   899 	aStream>> *iDataTypeHeaderArray;
       
   900 	if (version<EAifVersionAddsViewData)
       
   901 		return;
       
   902 	aStream>> *iViewDataHeaderArray;
       
   903 	if (version<EAifVersionAddsFileOwnershipInfo)
       
   904 		return;
       
   905 	aStream>> *iFileOwnershipInfoHeaderArray;
       
   906 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
   907 	if (version<EAifVersionAddsJavaMIDletInfo)
       
   908 		return;
       
   909 	iJavaMIDletInfo_AmsAuthId=aStream.ReadUint32L();
       
   910 	iJavaMIDletInfo_MIDlet=aStream.ReadInt32L();
       
   911 #endif
       
   912 	}
       
   913 
       
   914 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TApaAppCaption CApaAppInfoFileReader::CaptionL(TLanguage aLanguage)
       
   915 // Find language id and return matching caption, loaded from file.
       
   916 // Does not allocate storage for the caption so there's no need to delete the array elements.
       
   917 /** Searches for the most appropriate caption in the aif file for the language 
       
   918 specified.
       
   919 
       
   920 If a caption in the specified language is not found, the function searches 
       
   921 for the best alternative using the language downgrade path.
       
   922 
       
   923 If there are no captions at all in the aif file, a default caption is used 
       
   924 (the aif filename).
       
   925 
       
   926 @param aLanguage The language of the required caption.
       
   927 @return The application's caption. */
       
   928 	{
       
   929 	RFs fs;
       
   930 	CleanupClosePushL(fs);
       
   931 	User::LeaveIfError(fs.Connect());
       
   932 	RArray<TLanguage> downgradePath;
       
   933 	CleanupClosePushL(downgradePath);
       
   934 	BaflUtils::GetDowngradePathL(fs,aLanguage,downgradePath);
       
   935 	TApaAppCaption result(*iDefaultCaption);
       
   936 	const TInt count=iCaptionHeaderArray->Count();
       
   937 	if (count>0)
       
   938 		{
       
   939 		const TInt languageCount=downgradePath.Count();
       
   940 		TInt captionIndex=KErrNotFound;
       
   941 		for (TInt j=0; j<languageCount; j++)
       
   942 			{
       
   943 			for (TInt i=0;i<count;i++)
       
   944 				{		
       
   945 				if ((*iCaptionHeaderArray)[i].iLanguage==downgradePath[j])
       
   946 					{
       
   947 					captionIndex=i;
       
   948 					j=languageCount;//to exit outer loop
       
   949 					break;
       
   950 					}
       
   951 				}
       
   952 			}
       
   953 		TCaptionHeader pCaptionHeader;
       
   954 		if (captionIndex!=KErrNotFound)
       
   955 			{
       
   956 			pCaptionHeader=(*iCaptionHeaderArray)[captionIndex];
       
   957 			}
       
   958 		else		// use caption for the first language specified in the aif file
       
   959 					// since we don't have anything more suitable
       
   960 			{ 		
       
   961 			pCaptionHeader=(*iCaptionHeaderArray)[0];
       
   962 			}
       
   963 
       
   964 		if (iStore)
       
   965 			{
       
   966 			RStoreReadStream inStream;
       
   967 			inStream.OpenLC(*iStore,pCaptionHeader.iCaption.AsId());
       
   968 			inStream >> result;
       
   969 			CleanupStack::PopAndDestroy(&inStream);
       
   970 			}
       
   971 		else
       
   972 			{
       
   973 			__ASSERT_DEBUG(pCaptionHeader.iCaption.IsPtr(), Panic(EPanicNoCaption));
       
   974 			result = *(pCaptionHeader.iCaption);
       
   975 			}
       
   976 		downgradePath.Reset();
       
   977 		}
       
   978 	CleanupStack::PopAndDestroy(2, &fs);
       
   979 	return result;
       
   980 	}
       
   981 
       
   982 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileReader::StretchDrawL(CFbsBitmap* aSource,CFbsBitmap* aTarget,TSize aSizeInPixels)
       
   983 /** Creates a new bitmap based on another, stretched or compressed to the specified 
       
   984 size.
       
   985 
       
   986 @param aSource The source bitmap to copy.
       
   987 @param aTarget The target bitmap. On return, this is set to be a copy of aSource, 
       
   988 but stretched or compressed to the specified size.
       
   989 @param aSizeInPixels The required size for the target bitmap. */
       
   990 	{
       
   991 	User::LeaveIfError(aTarget->Create(aSizeInPixels,aSource->DisplayMode()));
       
   992 	CFbsBitmapDevice* bitDev=CFbsBitmapDevice::NewL(aTarget);
       
   993 	CleanupStack::PushL(bitDev);
       
   994 	CFbsBitGc* gc;
       
   995 	User::LeaveIfError(bitDev->CreateContext((CGraphicsContext*&)gc));
       
   996 	gc->DrawBitmap(TRect(aSizeInPixels),aSource);
       
   997 	delete gc;
       
   998 	CleanupStack::PopAndDestroy(bitDev);
       
   999 	}
       
  1000 
       
  1001 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER TInt CApaAppInfoFileReader::NumberOfBitmaps() const
       
  1002 /** Returns the number of icons in the aif file.
       
  1003 
       
  1004 @return The number of icons in the aif file. */
       
  1005 	{
       
  1006 	return iIconHeaderArray->Count();
       
  1007 	}
       
  1008 
       
  1009 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaMaskedBitmap* CApaAppInfoFileReader::CreateMaskedBitmapByIndexLC(TInt aIndex)
       
  1010 	{
       
  1011 	const TInt count=iIconHeaderArray->Count();
       
  1012 	if (count<=aIndex) // panic?
       
  1013 		User::Leave(KErrNotFound);
       
  1014 	//
       
  1015 	CApaMaskedBitmap* icon=CApaMaskedBitmap::NewLC();
       
  1016 	if (iStore)
       
  1017 		{
       
  1018 		RStoreReadStream inStream;
       
  1019 		inStream.OpenLC(*iStore,(*iIconHeaderArray)[aIndex].iIcon.AsId());
       
  1020 		MStreamBuf* src=inStream.Source();
       
  1021 		__ASSERT_DEBUG(src, Panic(EPanicNullPointer));
       
  1022 		const TUid uid = TUid::Uid(inStream.ReadInt32L());
       
  1023 		src->SeekL(MStreamBuf::ERead,-4);
       
  1024 		if (uid==KCBitwiseBitmapUid)
       
  1025 			{
       
  1026 			TUint32* fileOffsetPtr=(TUint32*) src;
       
  1027 			fileOffsetPtr+=4;
       
  1028 			icon->SetRomBitmapL(iRomPointer+(*fileOffsetPtr));
       
  1029 			}
       
  1030 		else
       
  1031 			{
       
  1032 			inStream >> *icon;
       
  1033 			}
       
  1034 		CleanupStack::PopAndDestroy(&inStream);
       
  1035 		}
       
  1036 	else
       
  1037 		{
       
  1038 		CFbsBitmap* mask = new(ELeave) CFbsBitmap();
       
  1039 		CleanupStack::PushL(mask);
       
  1040 		TInt mbmIndex = aIndex * 2;		// we need to map 'icon index' to 'mbm index' (bmp + mask)
       
  1041 		__ASSERT_DEBUG(iAifFileName, Panic(EPanicNullPointer));
       
  1042 		User::LeaveIfError(icon->Load(*iAifFileName, mbmIndex, ETrue, iMbmOffset));
       
  1043 		User::LeaveIfError(mask->Load(*iAifFileName, mbmIndex + 1, ETrue, iMbmOffset));
       
  1044 		icon->SetMaskBitmap(mask);
       
  1045 		CleanupStack::Pop(mask);
       
  1046 		}
       
  1047 	//
       
  1048 	return icon;
       
  1049 	}
       
  1050 
       
  1051 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaMaskedBitmap* CApaAppInfoFileReader::CreateMaskedBitmapL(TInt aIconSideInPixels)
       
  1052 //
       
  1053 // Use CreateMaskedBitmapByIndexLC. To access a bitmap by size use RApaLsSession APIs.
       
  1054 //
       
  1055 /** Creates a new masked bitmap based on the one in the aif file whose size is 
       
  1056 closest to the size specified.
       
  1057 
       
  1058 If all bitmaps in the file are larger than the size specified, the new bitmap 
       
  1059 is based on the smallest and is shrunk to the specified size.
       
  1060 
       
  1061 @deprecated
       
  1062 @param aIconSideInPixels The maximum width and height in pixels of the bitmap. 
       
  1063 The new bitmap will be this size, or smaller.
       
  1064 @leave KErrNotFound There are no bitmaps in the file.
       
  1065 @return Pointer to the new bitmap. The caller takes ownership. */
       
  1066 	{
       
  1067 	__ASSERT_DEBUG(iIconHeaderArray, Panic(EPanicNullPointer));
       
  1068 	const TInt count=iIconHeaderArray->Count();
       
  1069 	if (count==0)
       
  1070 		User::Leave(KErrNotFound);
       
  1071 	//
       
  1072 	TInt closest=0;
       
  1073 	TInt smallest=0;
       
  1074 	TInt minSoFar=KMaxTInt;
       
  1075 	TInt smallestSoFar=KMaxTInt;
       
  1076 	TInt delta=0;
       
  1077 	for (TInt i=0;i<count;i++)
       
  1078 		{
       
  1079 		TIconHeader* pIconHeader=(&(*iIconHeaderArray)[i]);
       
  1080 		delta = aIconSideInPixels-pIconHeader->iIconSideInPixels; // Abs()
       
  1081 		if (pIconHeader->iIconSideInPixels<smallestSoFar)
       
  1082 			{ // the smallest is used if they're all too big
       
  1083 			smallest = i;
       
  1084 			smallestSoFar = pIconHeader->iIconSideInPixels;
       
  1085 			}
       
  1086 		if (delta>=0 && delta<minSoFar)
       
  1087 			{
       
  1088 			minSoFar=delta;
       
  1089 			closest=i;
       
  1090 			if (delta==0)
       
  1091 				break;
       
  1092 			}
       
  1093 		}
       
  1094 	//
       
  1095 	if (minSoFar==KMaxTInt)
       
  1096 		closest = smallest;
       
  1097 	//
       
  1098 	CApaMaskedBitmap* icon = CreateMaskedBitmapByIndexLC(closest);
       
  1099 	//
       
  1100 	if (minSoFar==KMaxTInt)
       
  1101 		{// all the icons are too big - squash down the smallest
       
  1102 		CApaMaskedBitmap* newIcon=CApaMaskedBitmap::NewLC();
       
  1103 		TSize iconSize(aIconSideInPixels,aIconSideInPixels);
       
  1104 		StretchDrawL(icon,newIcon,iconSize);
       
  1105 		StretchDrawL(icon->Mask(),newIcon->Mask(),iconSize);
       
  1106 		CleanupStack::Pop(newIcon);
       
  1107 		CleanupStack::PopAndDestroy(icon);
       
  1108 		return newIcon;
       
  1109 		}
       
  1110 	CleanupStack::Pop(icon);
       
  1111 	return icon;
       
  1112 	}
       
  1113 
       
  1114 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileReader::Capability(TDes8& aInfo)const
       
  1115 /** Gets the capability information read from the aif file.
       
  1116 
       
  1117 @param aInfo A TApaAppCapabilityBuf object. On return, this contains the application's 
       
  1118 capabilities. */
       
  1119 	{
       
  1120 	TApaAppCapabilityBuf buf(iCapability);
       
  1121 	TApaAppCapability::CopyCapability(aInfo,buf);
       
  1122 	}
       
  1123 
       
  1124 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileReader::DataTypesSupportedL(CArrayFix<TDataTypeWithPriority>& aTypeList) const
       
  1125 /** Gets the MIME types supported by the application, and their priorities. 
       
  1126 
       
  1127 @param aTypeList An empty array. On return, this contains the MIME type priorities 
       
  1128 read from the aif file. MIME type priorities determine which application is 
       
  1129 launched to display a particular document.
       
  1130 @panic APGRFX 29 The aTypeList array is not empty when calling the function. 
       
  1131 Debug builds only.
       
  1132 @panic APGRFX 33 The internal array holding the MIME type information is uninitialised. 
       
  1133 Debug builds only. */
       
  1134 	{
       
  1135 	__ASSERT_DEBUG(aTypeList.Count()==0,Panic(EDPanicArrayNotEmpty));
       
  1136 	__ASSERT_DEBUG(iDataTypeHeaderArray,Panic(EDPanicInvalidDataTypeArray));
       
  1137 	TInt count=iDataTypeHeaderArray->Count();
       
  1138 	for (TInt i=0; i<count; i++)
       
  1139 		{
       
  1140 		const TDataTypeHeader& header=(*iDataTypeHeaderArray)[i];
       
  1141 		if (iStore)
       
  1142 			{
       
  1143 			RStoreReadStream inStream;
       
  1144 			inStream.OpenLC(*iStore,header.iDataType.AsId());
       
  1145 			TDataType dataType;
       
  1146 			inStream >> dataType;
       
  1147 			aTypeList.AppendL(TDataTypeWithPriority(dataType,header.iPriority));
       
  1148 			CleanupStack::PopAndDestroy(&inStream);
       
  1149 			}
       
  1150 		else
       
  1151 			{
       
  1152 			aTypeList.AppendL(TDataTypeWithPriority(*(header.iDataType), header.iPriority));
       
  1153 			}
       
  1154 		}
       
  1155 	}
       
  1156 
       
  1157 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileReader::GetViewsL(CArrayPtr<CApaAIFViewData>& aViewList) const
       
  1158 /** Gets the application view data contained in the aif file.
       
  1159 
       
  1160 The view data is an array of view UIDs and their associated captions and icons.
       
  1161 
       
  1162 @internalComponent
       
  1163 @param aViewList An empty array. On return, this contains the view data read 
       
  1164 from the aif file. If the file does not contain any application view data, 
       
  1165 this array will be empty on return.
       
  1166 @panic APGRFX 29 The aViewList array is not empty when calling the function. 
       
  1167 Debug builds only.
       
  1168 @panic APGRFX 34 The internal array holding the view data is uninitialised. 
       
  1169 Debug builds only. */
       
  1170 	{
       
  1171 	__ASSERT_DEBUG(aViewList.Count()==0,Panic(EDPanicArrayNotEmpty));
       
  1172 	__ASSERT_DEBUG(iViewDataHeaderArray,Panic(EDPanicInvalidViewArray));
       
  1173 	TInt count=iViewDataHeaderArray->Count();
       
  1174 	for (TInt i=0; i<count; i++)
       
  1175 		{
       
  1176 		const TViewDataHeader& header=(*iViewDataHeaderArray)[i];
       
  1177 		if (iStore)
       
  1178 			{
       
  1179 			CApaAIFViewData* viewData=CApaAIFViewData::NewLC();
       
  1180 			RStoreReadStream inStream;
       
  1181 			inStream.OpenLC(*iStore,header.iViewData.AsId());
       
  1182 			inStream >> *viewData;
       
  1183 			aViewList.AppendL(viewData);
       
  1184 			CleanupStack::PopAndDestroy(&inStream);
       
  1185 			CleanupStack::Pop(viewData);
       
  1186 			}
       
  1187 		else
       
  1188 			{
       
  1189 			// Load any icons for the view
       
  1190 			// Have to create a copy here as the old AIF format (above) gives external ownership
       
  1191 			// of CApaAIFViewData items in aViewList.
       
  1192 			CApaAIFViewData* headerViewData = header.iViewData.AsPtr();
       
  1193 			CApaAIFViewData* viewData = CApaAIFViewData::NewLC(*headerViewData);
       
  1194 			viewData->LoadIconsL(*iAifFileName, iMbmOffset);
       
  1195 			aViewList.AppendL(viewData);
       
  1196 			CleanupStack::Pop(viewData);
       
  1197 			}
       
  1198 		}
       
  1199 	}
       
  1200 
       
  1201 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileReader::GetOwnedFilesL(CDesCArray& aOwnedFilesList) const
       
  1202 /** Gets a list of the files that the application has claimed ownership of in the 
       
  1203 aif file.
       
  1204 
       
  1205 @param aOwnedFilesList An empty array. On return, this contains the names 
       
  1206 of the files identified as being owned by the application.
       
  1207 @panic APGRFX 29 The aOwnedFilesList array is not empty when calling the function. 
       
  1208 Debug builds only.
       
  1209 @panic APGRFX 35 The internal array holding the owned files list is uninitialised. 
       
  1210 Debug builds only. */
       
  1211 	{
       
  1212 	__ASSERT_DEBUG(aOwnedFilesList.Count()==0,Panic(EDPanicArrayNotEmpty));
       
  1213 	__ASSERT_DEBUG(iFileOwnershipInfoHeaderArray,Panic(EDPanicInvalidFileOwnershipArray));
       
  1214 	const TInt count=iFileOwnershipInfoHeaderArray->Count();
       
  1215 	for (TInt ii=0; ii<count; ii++)
       
  1216 		{
       
  1217 		const TFileOwnershipInfoHeader& header=(*iFileOwnershipInfoHeaderArray)[ii];
       
  1218 		if (iStore)
       
  1219 			{
       
  1220 			TFileName fileName;
       
  1221 			RStoreReadStream inStream;
       
  1222 			inStream.OpenLC(*iStore,header.iOwnedFileName.AsId());
       
  1223 			inStream >> fileName;
       
  1224 			aOwnedFilesList.AppendL(fileName);
       
  1225 			CleanupStack::PopAndDestroy(&inStream);
       
  1226 			}
       
  1227 		else
       
  1228 			{
       
  1229 			aOwnedFilesList.AppendL(*(header.iOwnedFileName));
       
  1230 			}
       
  1231 		}
       
  1232 	}
       
  1233 
       
  1234 
       
  1235 //
       
  1236 // Class CApaAppInfoFileWriter
       
  1237 //
       
  1238 
       
  1239 CApaAppInfoFileWriter::CApaAppInfoFileWriter(RFs& aFs)
       
  1240 	:CApaAppInfoFile(aFs)
       
  1241 	{}
       
  1242 
       
  1243 EXPORT_C CApaAppInfoFileWriter::~CApaAppInfoFileWriter()
       
  1244 // Must delete caption and icon pointers that have been set in AddCaptionL and AddIconL
       
  1245 	{
       
  1246 	if (iCaptionHeaderArray)
       
  1247 		{
       
  1248 		const TInt maxIndex=iCaptionHeaderArray->Count() - 1;
       
  1249 		for(TInt i=maxIndex; i>=0; i--)
       
  1250 			{
       
  1251 			const TCaptionHeader& pCaption=(*iCaptionHeaderArray)[i];
       
  1252 			if (pCaption.iCaption.IsPtr())
       
  1253 				{
       
  1254 				delete pCaption.iCaption.AsPtr();
       
  1255 				iCaptionHeaderArray->Delete(i);
       
  1256 				}
       
  1257 			}
       
  1258 		}
       
  1259 	if (iIconHeaderArray)
       
  1260 		{
       
  1261 		const TInt maxIndex=iIconHeaderArray->Count() - 1;
       
  1262 		for(TInt i=maxIndex; i>=0; i--)
       
  1263 			{
       
  1264 			const TIconHeader& pIcon=(*iIconHeaderArray)[i];
       
  1265 			if (pIcon.iIcon.IsPtr())
       
  1266 				{
       
  1267 				delete pIcon.iIcon.AsPtr();
       
  1268 				iIconHeaderArray->Delete(i);
       
  1269 				}
       
  1270 			}
       
  1271 		}
       
  1272 	if (iDataTypeHeaderArray)
       
  1273 		{
       
  1274 		const TInt maxIndex=iDataTypeHeaderArray->Count() - 1;
       
  1275 		for(TInt i=maxIndex; i>=0; i--)
       
  1276 			{
       
  1277 			const TDataTypeHeader& pData=(*iDataTypeHeaderArray)[i];
       
  1278 			if (pData.iDataType.IsPtr())
       
  1279 				{
       
  1280 				delete pData.iDataType.AsPtr();
       
  1281 				iDataTypeHeaderArray->Delete(i);
       
  1282 				}
       
  1283 			}
       
  1284 		}
       
  1285 	if (iViewDataHeaderArray)
       
  1286 		{
       
  1287 		const TInt maxIndex=iViewDataHeaderArray->Count() - 1;
       
  1288 		for(TInt i=maxIndex; i>=0; i--)
       
  1289 			{
       
  1290 			const TViewDataHeader& pView=(*iViewDataHeaderArray)[i];
       
  1291 			if (pView.iViewData.IsPtr())
       
  1292 				{
       
  1293 				delete pView.iViewData.AsPtr();
       
  1294 				iViewDataHeaderArray->Delete(i);
       
  1295 				}
       
  1296 			}
       
  1297 		}
       
  1298 	if (iFileOwnershipInfoHeaderArray)
       
  1299 		{
       
  1300 		const TInt maxIndex=iFileOwnershipInfoHeaderArray->Count() - 1;
       
  1301 		for(TInt i=maxIndex; i>=0; i--)
       
  1302 			{
       
  1303 			const TFileOwnershipInfoHeader& pView=(*iFileOwnershipInfoHeaderArray)[i];
       
  1304 			if (pView.iOwnedFileName.IsPtr())
       
  1305 				{
       
  1306 				delete pView.iOwnedFileName.AsPtr();
       
  1307 				iFileOwnershipInfoHeaderArray->Delete(i);
       
  1308 				}
       
  1309 			}
       
  1310 		}
       
  1311 	delete iMap;		// Must delete before iStore
       
  1312 	}
       
  1313 
       
  1314 // CApaResourceFileWriterBase::MDataSink
       
  1315 
       
  1316 void CApaResourceFileWriterBase::MDataSink::WriteBufferL(const TDesC8& aBuffer)
       
  1317 	{
       
  1318 	if (aBuffer.Length()>0)
       
  1319 		{
       
  1320 		if (iBufferSinkForCompressedUnicodeFormat!=NULL)
       
  1321 			{
       
  1322 			WriteInCompressedUnicodeFormatL(aBuffer.Length(), aBuffer, EFalse);
       
  1323 			}
       
  1324 		else
       
  1325 			{
       
  1326 			DoWriteBufferL(aBuffer);
       
  1327 			iNumberOfBytesWhenUncompressed+=aBuffer.Length();
       
  1328 			}
       
  1329 		}
       
  1330 	}
       
  1331 
       
  1332 void CApaResourceFileWriterBase::MDataSink::WriteCompressedUnicodeRunL(TInt aNumberOfBytesWhenUncompressed, const TDesC8& aTextAsCompressedUnicode)
       
  1333 	{
       
  1334 	WriteInCompressedUnicodeFormatL(aNumberOfBytesWhenUncompressed, aTextAsCompressedUnicode, ETrue);
       
  1335 	}
       
  1336 
       
  1337 void CApaResourceFileWriterBase::MDataSink::WriteInCompressedUnicodeFormatL(TInt aNumberOfBytesWhenUncompressed, const TDesC8& aData, TBool aCompressedUnicode)
       
  1338 	{
       
  1339 	__ASSERT_DEBUG(iBufferSinkForCompressedUnicodeFormat!=NULL, Panic(EPanicWrongResourceFormat1));
       
  1340 	const TInt dataLength=aData.Length();
       
  1341 	__ASSERT_DEBUG(((dataLength==0) && ((aNumberOfBytesWhenUncompressed==0) || (aNumberOfBytesWhenUncompressed==1))) ||
       
  1342 				   ((dataLength>0) && (aNumberOfBytesWhenUncompressed>0)), Panic(EPanicBadCompressedUnicodeRun));
       
  1343 	if (dataLength>0)
       
  1344 		{
       
  1345 		if ((iNumberOfBytesWhenUncompressed==0) && (iBufferSinkForCompressedUnicodeFormat->iNumberOfBytesWhenUncompressed==0))
       
  1346 			{
       
  1347 			if (aCompressedUnicode)
       
  1348 				{
       
  1349 				iFlags|=EFlag_InCompressedUnicodeRun;
       
  1350 				}
       
  1351 			else
       
  1352 				{
       
  1353 				iFlags&=~EFlag_InCompressedUnicodeRun;
       
  1354 				}
       
  1355 			}
       
  1356 		else if ((iFlags&EFlag_InCompressedUnicodeRun)^(aCompressedUnicode? EFlag_InCompressedUnicodeRun: 0)) // if we're changing the state of the EFlag_InCompressedUnicodeRun flag
       
  1357 			{
       
  1358 			FlushL(EFalse);
       
  1359 			iFlags^=EFlag_InCompressedUnicodeRun; // toggle the EFlag_InCompressedUnicodeRun flag
       
  1360 			}
       
  1361 		static_cast<MDataSink*>(iBufferSinkForCompressedUnicodeFormat)->DoWriteBufferL(aData);
       
  1362 		}
       
  1363 	iBufferSinkForCompressedUnicodeFormat->iNumberOfBytesWhenUncompressed+=aNumberOfBytesWhenUncompressed;
       
  1364 	}
       
  1365 
       
  1366 TInt CApaResourceFileWriterBase::MDataSink::NumberOfBytesWhenUncompressed() const
       
  1367 	{
       
  1368 	TInt numberOfBytesWhenUncompressed=iNumberOfBytesWhenUncompressed;
       
  1369 	if (iBufferSinkForCompressedUnicodeFormat!=NULL)
       
  1370 		{
       
  1371 		numberOfBytesWhenUncompressed+=iBufferSinkForCompressedUnicodeFormat->iNumberOfBytesWhenUncompressed;
       
  1372 		}
       
  1373 	return numberOfBytesWhenUncompressed;
       
  1374 	}
       
  1375 
       
  1376 CApaResourceFileWriterBase::MDataSink::MDataSink(RBufferSink* aBufferSinkForCompressedUnicodeFormat)
       
  1377 	:iNumberOfBytesWhenUncompressed(0),
       
  1378 	 iFlags(0),
       
  1379 	 iBufferSinkForCompressedUnicodeFormat(aBufferSinkForCompressedUnicodeFormat)
       
  1380 	{
       
  1381 	}
       
  1382 
       
  1383 void CApaResourceFileWriterBase::MDataSink::FlushL(TBool aFinalFlush)
       
  1384 	{
       
  1385 	if (iBufferSinkForCompressedUnicodeFormat!=NULL)
       
  1386 		{
       
  1387 		RBuf8 run;
       
  1388 		CleanupClosePushL(run);
       
  1389 		TInt numberOfBytesInRunWhenUncompressed=0;
       
  1390 		iBufferSinkForCompressedUnicodeFormat->FlushAndGetAndResetL(numberOfBytesInRunWhenUncompressed, run);
       
  1391 		if (numberOfBytesInRunWhenUncompressed>0)
       
  1392 			{
       
  1393 			if ((iNumberOfBytesWhenUncompressed==0) && ((iFlags&EFlag_InCompressedUnicodeRun)==0))
       
  1394 				{
       
  1395 				WriteRunLengthL(0); // insert initial zero-length run-length as we're not starting with compressed Unicode
       
  1396 				}
       
  1397 			__ASSERT_DEBUG(run.Length()>0, Panic(EPanicBadRunLength));
       
  1398 			WriteRunLengthL(run.Length());
       
  1399 			DoWriteBufferL(run);
       
  1400 			iNumberOfBytesWhenUncompressed+=numberOfBytesInRunWhenUncompressed;
       
  1401 			}
       
  1402 		CleanupStack::PopAndDestroy(&run);
       
  1403 		if (aFinalFlush && (iNumberOfBytesWhenUncompressed==0))
       
  1404 			{
       
  1405 			WriteRunLengthL(0); // write a zero-length run-length as the resource is completely empty
       
  1406 			}
       
  1407 		}
       
  1408 	}
       
  1409 
       
  1410 void CApaResourceFileWriterBase::MDataSink::Reset(TInt& aNumberOfBytesWhenUncompressed)
       
  1411 	{
       
  1412 	aNumberOfBytesWhenUncompressed=iNumberOfBytesWhenUncompressed;
       
  1413 	iNumberOfBytesWhenUncompressed=0;
       
  1414 	iFlags=0;
       
  1415 	}
       
  1416 
       
  1417 void CApaResourceFileWriterBase::MDataSink::WriteRunLengthL(TInt aRunLength)
       
  1418 	{
       
  1419 	__ASSERT_DEBUG((aRunLength&~0x7fff)==0, Panic(EPanicBadRunLengthParameter));
       
  1420 	__ASSERT_DEBUG(CompressedUnicodeFormat(), Panic(EPanicWrongResourceFormat2));
       
  1421 	TBuf8<2> buffer;
       
  1422 	if (aRunLength&~0x7f)
       
  1423 		{
       
  1424 		buffer.Append((aRunLength>>8)|0x80);
       
  1425 		}
       
  1426 	buffer.Append(aRunLength&0xff);
       
  1427 	DoWriteBufferL(buffer); // must call DoWriteBufferL here (not WriteBufferL) so that iNumberOfBytesWhenUncompressed is not altered
       
  1428 	}
       
  1429 
       
  1430 // CApaResourceFileWriterBase::RBufferSink
       
  1431 
       
  1432 CApaResourceFileWriterBase::RBufferSink::RBufferSink(RBufferSink* aBufferSinkForCompressedUnicodeFormat)
       
  1433 	:MDataSink(aBufferSinkForCompressedUnicodeFormat)
       
  1434 	{
       
  1435 	}
       
  1436 
       
  1437 void CApaResourceFileWriterBase::RBufferSink::ConstructLC()
       
  1438 	{
       
  1439 	iBuffer.CreateL(20);
       
  1440 	CleanupClosePushL(*this);
       
  1441 	}
       
  1442 
       
  1443 void CApaResourceFileWriterBase::RBufferSink::Close()
       
  1444 	{
       
  1445 	iBuffer.Close();
       
  1446 	}
       
  1447 
       
  1448 void CApaResourceFileWriterBase::RBufferSink::FlushAndGetAndResetL(TInt& aNumberOfBytesWhenUncompressed, RBuf8& aBuffer)
       
  1449 	{
       
  1450 	FlushL(ETrue);
       
  1451 	iBuffer.Swap(aBuffer);
       
  1452 	Reset(aNumberOfBytesWhenUncompressed);
       
  1453 	}
       
  1454 
       
  1455 void CApaResourceFileWriterBase::RBufferSink::DoWriteBufferL(const TDesC8& aBuffer)
       
  1456 	{
       
  1457 	if (iBuffer.MaxLength()-iBuffer.Length()<aBuffer.Length())
       
  1458 		{
       
  1459 		iBuffer.ReAllocL(iBuffer.Length()+aBuffer.Length()+20);
       
  1460 		}
       
  1461 	iBuffer.Append(aBuffer);
       
  1462 	}
       
  1463 
       
  1464 // CApaResourceFileWriterBase
       
  1465 
       
  1466 CApaResourceFileWriterBase::CApaResourceFileWriterBase()
       
  1467 	{
       
  1468 	}
       
  1469 
       
  1470 void CApaResourceFileWriterBase::DoGenerateFileContentsL(RBuf8& aBuffer, TUid aUid2, TUid aUid3) const
       
  1471 	{
       
  1472 	TInt mainResourceSizeInBytesWhenUncompressed=0;
       
  1473 	RBuf8 mainResourceInFormatContainingCompressedUnicode;
       
  1474 	MainResourceInCompiledFormatLC(mainResourceSizeInBytesWhenUncompressed, mainResourceInFormatContainingCompressedUnicode, ETrue);
       
  1475 	TInt temp=0;
       
  1476 	RBuf8 mainResourceInFormatNotContainingCompressedUnicode;
       
  1477 	MainResourceInCompiledFormatLC(temp, mainResourceInFormatNotContainingCompressedUnicode, EFalse);
       
  1478 	__ASSERT_DEBUG(temp==mainResourceSizeInBytesWhenUncompressed, Panic(EPanicInconsistentResourceSizeInBytes));
       
  1479 	TBool mainResourceInCompressedUnicodeFormat=ETrue;
       
  1480 	TPtrC8 mainResourceInSmallestFormat(mainResourceInFormatContainingCompressedUnicode);
       
  1481 	if (mainResourceInSmallestFormat.Length()>=mainResourceInFormatNotContainingCompressedUnicode.Length())
       
  1482 		{
       
  1483 		mainResourceInCompressedUnicodeFormat=EFalse;
       
  1484 		mainResourceInSmallestFormat.Set(mainResourceInFormatNotContainingCompressedUnicode);
       
  1485 		}
       
  1486 	TBool secondResourceInCompressedUnicodeFormat=EFalse;
       
  1487 	const TDesC8* const secondResource=SecondResourceL(secondResourceInCompressedUnicodeFormat);
       
  1488 	RBufferSink bufferSink(NULL);
       
  1489 	bufferSink.ConstructLC();
       
  1490 
       
  1491 	WriteUidTypeL(bufferSink, aUid2, aUid3);
       
  1492 	WriteUint8L(bufferSink, 0); // flags
       
  1493 	WriteLittleEndianUint16L(bufferSink, (secondResource==NULL)? mainResourceSizeInBytesWhenUncompressed: Max(mainResourceSizeInBytesWhenUncompressed, secondResource->Length())); // the size in bytes of the largest resource in the file when uncompressed
       
  1494 	TUint bitArray=0; // bit-array (one per top-level resource) indicating whether each top-level resource contains compressed unicode or not
       
  1495 	if (mainResourceInCompressedUnicodeFormat)
       
  1496 		{
       
  1497 		bitArray|=0x01;
       
  1498 		}
       
  1499 	if (secondResourceInCompressedUnicodeFormat)
       
  1500 		{
       
  1501 		bitArray|=0x02;
       
  1502 		}
       
  1503 	WriteUint8L(bufferSink, bitArray);
       
  1504 	WriteBufferL(bufferSink, mainResourceInSmallestFormat);
       
  1505 	if (secondResource!=NULL)
       
  1506 		{
       
  1507 		WriteBufferL(bufferSink, *secondResource);
       
  1508 		}
       
  1509 	TInt filePosition=16+1+2+1;
       
  1510 	WriteLittleEndianUint16L(bufferSink, filePosition);
       
  1511 	filePosition+=mainResourceInSmallestFormat.Length();
       
  1512 	WriteLittleEndianUint16L(bufferSink, filePosition);
       
  1513 	if (secondResource!=NULL)
       
  1514 		{
       
  1515 		filePosition+=secondResource->Length();
       
  1516 		WriteLittleEndianUint16L(bufferSink, filePosition);
       
  1517 		}
       
  1518 	TInt notUsed;
       
  1519 	bufferSink.FlushAndGetAndResetL(notUsed, aBuffer);
       
  1520 
       
  1521 	CleanupStack::PopAndDestroy(3, &mainResourceInFormatContainingCompressedUnicode);
       
  1522 	}
       
  1523 
       
  1524 void CApaResourceFileWriterBase::WriteUidTypeL(MDataSink& aDataSink, TUid aUid2, TUid aUid3) const
       
  1525 	{
       
  1526 	aDataSink.WriteBufferL(TCheckedUid(TUidType(TUid::Uid(0x101f4a6b), aUid2, aUid3)).Des());
       
  1527 	}
       
  1528 
       
  1529 void CApaResourceFileWriterBase::WriteTextL(MDataSink& aDataSink, const TDesC& aText) const
       
  1530 	{
       
  1531 	// LTEXT
       
  1532 
       
  1533 	WriteUint8L(aDataSink, aText.Length());
       
  1534 	if (!aDataSink.CompressedUnicodeFormat())
       
  1535 		{
       
  1536 		if ((aDataSink.NumberOfBytesWhenUncompressed()%2)!=0)
       
  1537 			{
       
  1538 			WriteUint8L(aDataSink, 0xab);
       
  1539 			}
       
  1540 		const TInt lengthOfTextInBytes=aText.Size();
       
  1541 		WriteBufferL(aDataSink, TPtrC8(reinterpret_cast<const TUint8*>(aText.Ptr()), lengthOfTextInBytes));
       
  1542 		}
       
  1543 	else
       
  1544 		{
       
  1545 		TInt numberOfBytesWhenUncompressed=aText.Size();
       
  1546 		if ((aDataSink.NumberOfBytesWhenUncompressed()%2)!=0)
       
  1547 			{
       
  1548 			++numberOfBytesWhenUncompressed; // for the padding-byte 0xab when it's uncompressed
       
  1549 			}
       
  1550 		HBufC8* const textAsCompressedUnicode=AsCompressedUnicodeLC(aText);
       
  1551 		aDataSink.WriteCompressedUnicodeRunL(numberOfBytesWhenUncompressed, *textAsCompressedUnicode);
       
  1552 		CleanupStack::PopAndDestroy(textAsCompressedUnicode);
       
  1553 		}
       
  1554 	}
       
  1555 
       
  1556 void CApaResourceFileWriterBase::WriteText8L(MDataSink& aDataSink, const TDesC8& aText8) const
       
  1557 	{
       
  1558 	// LTEXT8
       
  1559 
       
  1560 	WriteUint8L(aDataSink, aText8.Length());
       
  1561 	WriteBufferL(aDataSink, aText8);
       
  1562 	}
       
  1563 
       
  1564 void CApaResourceFileWriterBase::WriteUint8L(MDataSink& aDataSink, TUint aUint8) const
       
  1565 	{
       
  1566 	TBuf8<1> buffer;
       
  1567 	buffer.Append(aUint8&0xff);
       
  1568 	aDataSink.WriteBufferL(buffer);
       
  1569 	}
       
  1570 
       
  1571 void CApaResourceFileWriterBase::WriteLittleEndianUint16L(MDataSink& aDataSink, TUint aUint16) const
       
  1572 	{
       
  1573 	TBuf8<2> buffer;
       
  1574 	buffer.Append(aUint16&0xff);
       
  1575 	buffer.Append((aUint16>>8)&0xff);
       
  1576 	aDataSink.WriteBufferL(buffer);
       
  1577 	}
       
  1578 
       
  1579 void CApaResourceFileWriterBase::WriteLittleEndianUint32L(MDataSink& aDataSink, TUint aUint32) const
       
  1580 	{
       
  1581 	TBuf8<4> buffer;
       
  1582 	buffer.Append(aUint32&0xff);
       
  1583 	buffer.Append((aUint32>>8)&0xff);
       
  1584 	buffer.Append((aUint32>>16)&0xff);
       
  1585 	buffer.Append((aUint32>>24)&0xff);
       
  1586 	aDataSink.WriteBufferL(buffer);
       
  1587 	}
       
  1588 
       
  1589 void CApaResourceFileWriterBase::WriteBufferL(MDataSink& aDataSink, const TDesC8& aBuffer) const
       
  1590 	{
       
  1591 	aDataSink.WriteBufferL(aBuffer);
       
  1592 	}
       
  1593 
       
  1594 HBufC8* CApaResourceFileWriterBase::AsCompressedUnicodeLC(const TDesC& aUncompressedUnicode)
       
  1595 	{
       
  1596 	TUnicodeCompressor unicodeCompressor;
       
  1597 	TMemoryUnicodeSource decompressedUnicode1(aUncompressedUnicode.Ptr());
       
  1598 	TMemoryUnicodeSource decompressedUnicode2(aUncompressedUnicode.Ptr());
       
  1599 	
       
  1600 	// Create a buffer big enough to hold all the compressed output
       
  1601 	TInt compressedUnicodeSizeInBytes = TUnicodeCompressor::CompressedSizeL(decompressedUnicode1, aUncompressedUnicode.Length());
       
  1602 	HBufC8* const compressedUnicodeBuffer=HBufC8::NewLC(compressedUnicodeSizeInBytes);
       
  1603 	TUint8* const compressedUnicodeBuffer_asBytePointer=const_cast<TUint8*>(compressedUnicodeBuffer->Ptr());
       
  1604 	
       
  1605 	// Compress the Unicode string
       
  1606 	TInt numberOfInputElementsConsumed = 0;
       
  1607 	TInt numberOfOutputBytes = 0;
       
  1608 	unicodeCompressor.CompressL(compressedUnicodeBuffer_asBytePointer, decompressedUnicode2, compressedUnicodeSizeInBytes, aUncompressedUnicode.Length(), &numberOfOutputBytes, &numberOfInputElementsConsumed);
       
  1609 	TInt temp = 0;
       
  1610 	unicodeCompressor.FlushL(compressedUnicodeBuffer_asBytePointer, compressedUnicodeSizeInBytes, temp);
       
  1611 	numberOfOutputBytes+=temp;
       
  1612 	TPtr8 compressedUnicodeBuffer_asWritable(compressedUnicodeBuffer->Des());
       
  1613 	compressedUnicodeBuffer_asWritable.SetLength(numberOfOutputBytes);
       
  1614 	return compressedUnicodeBuffer;
       
  1615 	}
       
  1616 
       
  1617 void CApaResourceFileWriterBase::MainResourceInCompiledFormatLC(TInt& aMainResourceSizeInBytesWhenUncompressed, RBuf8& aBuffer, TBool aCompressedUnicodeFormat) const
       
  1618 	{
       
  1619 	CleanupClosePushL(aBuffer);
       
  1620 	RBufferSink bufferSinkForCompressedUnicodeFormat(NULL);
       
  1621 	if (aCompressedUnicodeFormat)
       
  1622 		{
       
  1623 		bufferSinkForCompressedUnicodeFormat.ConstructLC();
       
  1624 		}
       
  1625 	RBufferSink bufferSink(aCompressedUnicodeFormat? &bufferSinkForCompressedUnicodeFormat: NULL);
       
  1626 	bufferSink.ConstructLC();
       
  1627 	MainResourceInCompiledFormatL(bufferSink);
       
  1628 	bufferSink.FlushAndGetAndResetL(aMainResourceSizeInBytesWhenUncompressed, aBuffer);
       
  1629 	CleanupStack::PopAndDestroy(&bufferSink);
       
  1630 	if (aCompressedUnicodeFormat)
       
  1631 		{
       
  1632 		CleanupStack::PopAndDestroy(&bufferSinkForCompressedUnicodeFormat);
       
  1633 		}
       
  1634 	}
       
  1635 
       
  1636 // CApaRegistrationResourceFileWriter
       
  1637 
       
  1638 /** 
       
  1639 Creates a new CApaRegistrationResourceFileWriter instance.
       
  1640 
       
  1641 @param aAppUid The UID of the application.
       
  1642 @param aAppFile The name and extension of the file to generate.
       
  1643 @param aAttributes The attributes of the application. See the TApaAppCapability class for more details.
       
  1644 @return A pointer to the new CApaRegistrationResourceFileWriter instance.
       
  1645 
       
  1646 @publishedPartner
       
  1647 @released
       
  1648 */
       
  1649 EXPORT_C CApaRegistrationResourceFileWriter* CApaRegistrationResourceFileWriter::NewL(TUid aAppUid, const TDesC& aAppFile, TUint aAttributes)
       
  1650 // aAppFile does not need to have the drive set
       
  1651 	{ // static
       
  1652 	CApaRegistrationResourceFileWriter* const self=new(ELeave) CApaRegistrationResourceFileWriter(aAppUid, aAttributes);
       
  1653 	CleanupStack::PushL(self);
       
  1654 	self->ConstructL(aAppFile);
       
  1655 	CleanupStack::Pop(self);
       
  1656 	return self;
       
  1657 	}
       
  1658 
       
  1659 /** 
       
  1660 The destructor for the CApaRegistrationResourceFileWriter class.
       
  1661 
       
  1662 @publishedPartner
       
  1663 @released
       
  1664 */
       
  1665 EXPORT_C CApaRegistrationResourceFileWriter::~CApaRegistrationResourceFileWriter()
       
  1666 	{
       
  1667 	delete iAppFile;
       
  1668 	delete iLocalisableResourceFile;
       
  1669 	delete iGroupName;
       
  1670 	delete iOpaqueData;
       
  1671 
       
  1672 	TInt i;
       
  1673 	for (i=iDataTypeList.Count()-1; i>=0; --i)
       
  1674 		{
       
  1675 		delete iDataTypeList[i].iType;
       
  1676 		}
       
  1677 	iDataTypeList.Close();
       
  1678 
       
  1679 	for (i=iFileOwnershipList.Count()-1; i>=0; --i)
       
  1680 		{
       
  1681 		delete iFileOwnershipList[i].iFileName;
       
  1682 		}
       
  1683 	iFileOwnershipList.Close();
       
  1684 	}
       
  1685 
       
  1686 TUid CApaRegistrationResourceFileWriter::AppUid() const
       
  1687 /** @internalComponent */
       
  1688 	{
       
  1689 	return iAppUid;
       
  1690 	}
       
  1691 
       
  1692 void CApaRegistrationResourceFileWriter::GenerateFileContentsL(RBuf8& aBuffer) const
       
  1693 /** @internalComponent */
       
  1694 	{
       
  1695 	DoGenerateFileContentsL(aBuffer, KUidAppRegistrationFile, iAppUid);
       
  1696 	}
       
  1697 
       
  1698 void CApaRegistrationResourceFileWriter::SetLocalisableResourceFileL(const TDesC& aLocalisableResourceFile)
       
  1699 /** @internalComponent */
       
  1700 	{
       
  1701 	HBufC* const localisableResourceFile=aLocalisableResourceFile.AllocL();
       
  1702 	delete iLocalisableResourceFile;
       
  1703 	iLocalisableResourceFile=localisableResourceFile;
       
  1704 	}
       
  1705 
       
  1706 /** 
       
  1707 Sets or clears the hidden attribute. The usual purpose of the hidden attribute is to 
       
  1708 decide if the application should appear in the task list or not but this could vary between
       
  1709 products.
       
  1710 
       
  1711 @param aAppIsHidden The value of the hidden flag.
       
  1712 
       
  1713 @publishedPartner
       
  1714 @released
       
  1715 */
       
  1716 EXPORT_C void CApaRegistrationResourceFileWriter::SetAppIsHiddenL(TBool aAppIsHidden)
       
  1717 	{
       
  1718 	iAppIsHidden=aAppIsHidden? 1: 0;
       
  1719 	}
       
  1720 
       
  1721 /** 
       
  1722 Sets the embeddability attribute. See the TApaAppCapability::TEmbeddability class for more details.
       
  1723 
       
  1724 @param aEmbeddability The value of the embeddability flags.
       
  1725 
       
  1726 @publishedPartner
       
  1727 @released
       
  1728 */
       
  1729 EXPORT_C void CApaRegistrationResourceFileWriter::SetEmbeddabilityL(TApaAppCapability::TEmbeddability aEmbeddability)
       
  1730 	{
       
  1731 	iEmbeddability=aEmbeddability;
       
  1732 	}
       
  1733 
       
  1734 /** 
       
  1735 Specifies if the application supports the creation of a new file or not.
       
  1736 
       
  1737 @param aSupportsNewFile ETrue to specify that the application supports the creation of a new file.
       
  1738 
       
  1739 @publishedPartner
       
  1740 @released
       
  1741 */
       
  1742 EXPORT_C void CApaRegistrationResourceFileWriter::SetSupportsNewFileL(TBool aSupportsNewFile)
       
  1743 	{
       
  1744 	iSupportsNewFile=aSupportsNewFile? 1: 0;
       
  1745 	}
       
  1746 
       
  1747 /** 
       
  1748 Specifies if the application must be launched in the background.
       
  1749 
       
  1750 @param aLaunchInBackground ETrue if the application must be launched in the background, EFalse otherwise.
       
  1751 
       
  1752 @publishedPartner
       
  1753 @released
       
  1754 */
       
  1755 EXPORT_C void CApaRegistrationResourceFileWriter::SetLaunchInBackgroundL(TBool aLaunchInBackground)
       
  1756 	{
       
  1757 	iLaunchInBackground=aLaunchInBackground;
       
  1758 	}
       
  1759 
       
  1760 /** 
       
  1761 Sets the name of the application group.
       
  1762 
       
  1763 @param aGroupName The name of the application group.
       
  1764 
       
  1765 @publishedPartner
       
  1766 @released
       
  1767 */
       
  1768 EXPORT_C void CApaRegistrationResourceFileWriter::SetGroupNameL(const TDesC& aGroupName)
       
  1769 	{
       
  1770 	HBufC* const groupName=aGroupName.AllocL();
       
  1771 	delete iGroupName;
       
  1772 	iGroupName=groupName;
       
  1773 	}
       
  1774 
       
  1775 /** 
       
  1776 Sets the default screen number. This can be used to specify the preferred screen on devices
       
  1777 that support more than one screen.
       
  1778 
       
  1779 @param aDefaultScreenNumber The name of the default screen.
       
  1780 
       
  1781 @publishedPartner
       
  1782 @released
       
  1783 */
       
  1784 EXPORT_C void CApaRegistrationResourceFileWriter::SetDefaultScreenNumberL(TInt aDefaultScreenNumber)
       
  1785 	{
       
  1786 	iDefaultScreenNumber=aDefaultScreenNumber;
       
  1787 	}
       
  1788 
       
  1789 /** 
       
  1790 Sets the opaque data. The opaque data is some data that is specific to the type of application.
       
  1791 
       
  1792 @publishedPartner
       
  1793 @released
       
  1794 */
       
  1795 EXPORT_C void CApaRegistrationResourceFileWriter::SetOpaqueDataL(const TDesC8& aOpaqueData)
       
  1796 	{
       
  1797 	HBufC8* const opaqueData=aOpaqueData.AllocL();
       
  1798 	delete iOpaqueData;
       
  1799 	iOpaqueData=opaqueData;
       
  1800 	}
       
  1801 
       
  1802 /** 
       
  1803 Adds a datatype to the list of datatypes that the application can handle.
       
  1804 
       
  1805 @param aPriority The priority.
       
  1806 @param aType The datatype.
       
  1807 
       
  1808 @publishedPartner
       
  1809 @released
       
  1810 */
       
  1811 EXPORT_C void CApaRegistrationResourceFileWriter::AddDataTypeL(TInt aPriority, const TDesC8& aType)
       
  1812 	{
       
  1813 	SDataType dataType;
       
  1814 	dataType.iPriority=aPriority;
       
  1815 	dataType.iType=aType.AllocLC();
       
  1816 	iDataTypeList.AppendL(dataType);
       
  1817 	CleanupStack::Pop(dataType.iType);
       
  1818 	}
       
  1819 
       
  1820 /** 
       
  1821 Adds a file to the list of files owned by the CApaRegistrationResourceFileWriter instances. These files
       
  1822 are deleted if an error occurs whil registering the new applications.
       
  1823 
       
  1824 @param aFileName The name of the file.
       
  1825 
       
  1826 @publishedPartner
       
  1827 @released
       
  1828 */
       
  1829 EXPORT_C void CApaRegistrationResourceFileWriter::AddFileOwnershipInfoL(const TDesC& aFileName)
       
  1830 	{
       
  1831 	SFileOwnershipInfo fileOwnershipInfo;
       
  1832 	fileOwnershipInfo.iFileName=aFileName.AllocLC();
       
  1833 	iFileOwnershipList.AppendL(fileOwnershipInfo);
       
  1834 	CleanupStack::Pop(fileOwnershipInfo.iFileName);
       
  1835 	}
       
  1836 
       
  1837 CApaRegistrationResourceFileWriter::CApaRegistrationResourceFileWriter(TUid aAppUid, TUint aAttributes)
       
  1838 	:iAppUid(aAppUid),
       
  1839 	 iAppFile(NULL),
       
  1840 	 iAttributes(aAttributes),
       
  1841 	 iLocalisableResourceFile(NULL),
       
  1842 	 iAppIsHidden(0),
       
  1843 	 iEmbeddability(TApaAppCapability::ENotEmbeddable),
       
  1844 	 iSupportsNewFile(0),
       
  1845 	 iLaunchInBackground(0),
       
  1846 	 iGroupName(NULL),
       
  1847 	 iDefaultScreenNumber(0),
       
  1848 	 iOpaqueData(NULL)
       
  1849 	{
       
  1850 	}
       
  1851 
       
  1852 void CApaRegistrationResourceFileWriter::ConstructL(const TDesC& aAppFile)
       
  1853 	{
       
  1854 	iAppFile=aAppFile.AllocL();
       
  1855 	iLocalisableResourceFile=NULL;
       
  1856 	}
       
  1857 
       
  1858 void CApaRegistrationResourceFileWriter::WriteDataTypeL(MDataSink& aDataSink, const SDataType& aDataType) const
       
  1859 	{
       
  1860 	// DATATYPE
       
  1861 
       
  1862 	// LONG priority
       
  1863 	WriteLittleEndianUint32L(aDataSink, aDataType.iPriority);
       
  1864 
       
  1865 	// LTEXT8 type(KMaxDataTypeLength)
       
  1866 	WriteText8L(aDataSink, *aDataType.iType);
       
  1867 	}
       
  1868 
       
  1869 void CApaRegistrationResourceFileWriter::WriteFileOwnershipInfoL(MDataSink& aDataSink, const SFileOwnershipInfo& aFileOwnershipInfo) const
       
  1870 	{
       
  1871 	// FILE_OWNERSHIP_INFO
       
  1872 
       
  1873 	// LTEXT file_name(KMaxFileNameLength)
       
  1874 	WriteTextL(aDataSink, *aFileOwnershipInfo.iFileName);
       
  1875 	}
       
  1876 
       
  1877 void CApaRegistrationResourceFileWriter::MainResourceInCompiledFormatL(MDataSink& aDataSink) const
       
  1878 	{
       
  1879 	// APP_REGISTRATION_INFO
       
  1880 
       
  1881 	// LONG reserved_long = 0
       
  1882 	WriteLittleEndianUint32L(aDataSink, 0);
       
  1883 
       
  1884 	// LLINK reserved_llink = 0
       
  1885 	WriteLittleEndianUint32L(aDataSink, 0);
       
  1886 	__ASSERT_DEBUG(iAppFile, Panic(EPanicNullPointer));
       
  1887 	// LTEXT app_file(KMaxFileNameLength) = ""
       
  1888 	WriteTextL(aDataSink, *iAppFile);
       
  1889 
       
  1890 	// LONG attributes = 0
       
  1891 	WriteLittleEndianUint32L(aDataSink, iAttributes);
       
  1892 
       
  1893 	// LTEXT localisable_resource_file(KMaxFileNameLength) = ""
       
  1894 	TPtrC localisableResourceFile(KNullDesC);
       
  1895 	if (iLocalisableResourceFile!=NULL)
       
  1896 		{
       
  1897 		localisableResourceFile.Set(*iLocalisableResourceFile);
       
  1898 		}
       
  1899 	WriteTextL(aDataSink, localisableResourceFile);
       
  1900 
       
  1901 	// LONG localisable_resource_id = 1
       
  1902 	WriteLittleEndianUint32L(aDataSink, 1);
       
  1903 
       
  1904 	// BYTE hidden = KAppNotHidden
       
  1905 	WriteUint8L(aDataSink, iAppIsHidden);
       
  1906 
       
  1907 	// BYTE embeddability = KAppNotEmbeddable
       
  1908 	WriteUint8L(aDataSink, iEmbeddability);
       
  1909 
       
  1910 	// BYTE newfile = KAppDoesNotSupportNewFile
       
  1911 	WriteUint8L(aDataSink, iSupportsNewFile);
       
  1912 
       
  1913 	// BYTE launch = KAppLaunchInForeground
       
  1914 	WriteUint8L(aDataSink, iLaunchInBackground);
       
  1915 
       
  1916 	// LTEXT group_name(KAppMaxGroupName) = ""
       
  1917 	TPtrC groupName(KNullDesC);
       
  1918 	if (iGroupName!=NULL)
       
  1919 		{
       
  1920 		groupName.Set(*iGroupName);
       
  1921 		}
       
  1922 	WriteTextL(aDataSink, groupName);
       
  1923 
       
  1924 	// BYTE default_screen_number = 0
       
  1925 	WriteUint8L(aDataSink, iDefaultScreenNumber);
       
  1926 
       
  1927 	// LEN WORD STRUCT datatype_list[]
       
  1928 	TInt i;
       
  1929 	const TInt numberOfDataTypes=iDataTypeList.Count();
       
  1930 	WriteLittleEndianUint16L(aDataSink, numberOfDataTypes);
       
  1931 	for (i=0; i<numberOfDataTypes; ++i)
       
  1932 		{
       
  1933 		WriteDataTypeL(aDataSink, iDataTypeList[i]);
       
  1934 		}
       
  1935 
       
  1936 	// LEN WORD STRUCT file_ownership_list[]
       
  1937 	const TInt numberOfOwnershipItems=iFileOwnershipList.Count();
       
  1938 	WriteLittleEndianUint16L(aDataSink, numberOfOwnershipItems);
       
  1939 	for (i=0; i<numberOfOwnershipItems; ++i)
       
  1940 		{
       
  1941 		WriteFileOwnershipInfoL(aDataSink, iFileOwnershipList[i]);
       
  1942 		}
       
  1943 
       
  1944 	// LEN WORD STRUCT service_list[]
       
  1945 	WriteLittleEndianUint16L(aDataSink, 0);
       
  1946 
       
  1947 	// LLINK opaque_data = 0
       
  1948 	WriteLittleEndianUint32L(aDataSink, (iOpaqueData!=NULL)? 2: 0);
       
  1949 	}
       
  1950 
       
  1951 const TDesC8* CApaRegistrationResourceFileWriter::SecondResourceL(TBool& aSecondResourceInCompressedUnicodeFormat) const
       
  1952 	{
       
  1953 	aSecondResourceInCompressedUnicodeFormat=EFalse;
       
  1954 	return iOpaqueData;
       
  1955 	}
       
  1956 
       
  1957 // CApaLocalisableResourceFileWriter
       
  1958 
       
  1959 EXPORT_C CApaLocalisableResourceFileWriter* CApaLocalisableResourceFileWriter::NewL(const TDesC& aShortCaption, const TDesC& aCaption, TInt aNumberOfIcons, const TDesC& aGroupName)
       
  1960 	{ // static
       
  1961 	CApaLocalisableResourceFileWriter* const self=new(ELeave) CApaLocalisableResourceFileWriter(aNumberOfIcons);
       
  1962 	CleanupStack::PushL(self);
       
  1963 	self->ConstructL(aShortCaption, aCaption, aGroupName);
       
  1964 	CleanupStack::Pop(self);
       
  1965 	return self;
       
  1966 	}
       
  1967 
       
  1968 EXPORT_C CApaLocalisableResourceFileWriter::~CApaLocalisableResourceFileWriter()
       
  1969 	{
       
  1970 	delete iShortCaption;
       
  1971 	delete iCaptionAndIcon.iCaption;
       
  1972 	delete iCaptionAndIcon.iIconFile;
       
  1973 	delete iGroupName;
       
  1974 	}
       
  1975 
       
  1976 void CApaLocalisableResourceFileWriter::GenerateFileContentsL(RBuf8& aBuffer) const
       
  1977 /** @internalComponent */
       
  1978 	{
       
  1979 	DoGenerateFileContentsL(aBuffer, TUid::Null(), TUid::Null());
       
  1980 	}
       
  1981 
       
  1982 void CApaLocalisableResourceFileWriter::SetIconFileL(const TDesC& aIconFile)
       
  1983 /** @internalComponent */
       
  1984 	{
       
  1985 	HBufC* const iconFile=aIconFile.AllocL();
       
  1986 	delete iCaptionAndIcon.iIconFile;
       
  1987 	iCaptionAndIcon.iIconFile=iconFile;
       
  1988 	}
       
  1989 
       
  1990 CApaLocalisableResourceFileWriter::CApaLocalisableResourceFileWriter(TInt aNumberOfIcons)
       
  1991 	:iShortCaption(NULL),
       
  1992 	 iGroupName(NULL)
       
  1993 	{
       
  1994 	iCaptionAndIcon.iCaption=NULL;
       
  1995 	iCaptionAndIcon.iNumberOfIcons=aNumberOfIcons;
       
  1996 	iCaptionAndIcon.iIconFile=NULL;
       
  1997 	}
       
  1998 
       
  1999 void CApaLocalisableResourceFileWriter::ConstructL(const TDesC& aShortCaption, const TDesC& aCaption, const TDesC& aGroupName)
       
  2000 	{
       
  2001 	iShortCaption=aShortCaption.AllocL();
       
  2002 	iCaptionAndIcon.iCaption=aCaption.AllocL();
       
  2003 	iCaptionAndIcon.iIconFile=NULL;
       
  2004 	iGroupName=aGroupName.AllocL();
       
  2005 	}
       
  2006 
       
  2007 void CApaLocalisableResourceFileWriter::WriteCaptionAndIconInfoL(MDataSink& aDataSink, const SCaptionAndIconInfo& aCaptionAndIcon) const
       
  2008 	{
       
  2009 	// CAPTION_AND_ICON_INFO
       
  2010 
       
  2011 	// LONG reserved_long = 0
       
  2012 	WriteLittleEndianUint32L(aDataSink, 0);
       
  2013 
       
  2014 	// LLINK reserved_llink = 0
       
  2015 	WriteLittleEndianUint32L(aDataSink, 0);
       
  2016 
       
  2017 	// LTEXT caption(KMaxCaption) = ""
       
  2018 	WriteTextL(aDataSink, *aCaptionAndIcon.iCaption);
       
  2019 
       
  2020 	// WORD number_of_icons = 0
       
  2021 	WriteLittleEndianUint16L(aDataSink, aCaptionAndIcon.iNumberOfIcons);
       
  2022 
       
  2023 	// LTEXT icon_file(KMaxFileNameLength) = ""
       
  2024 	TPtrC iconFile(KNullDesC);
       
  2025 	if (aCaptionAndIcon.iIconFile!=NULL)
       
  2026 		{
       
  2027 		iconFile.Set(*aCaptionAndIcon.iIconFile);
       
  2028 		}
       
  2029 	WriteTextL(aDataSink, iconFile);
       
  2030 	}
       
  2031 
       
  2032 void CApaLocalisableResourceFileWriter::MainResourceInCompiledFormatL(MDataSink& aDataSink) const
       
  2033 	{
       
  2034 	// LOCALISABLE_APP_INFO
       
  2035 
       
  2036 	// LONG reserved_long = 0
       
  2037 	WriteLittleEndianUint32L(aDataSink, 0);
       
  2038 
       
  2039 	// LLINK reserved_llink = 0
       
  2040 	WriteLittleEndianUint32L(aDataSink, 0);
       
  2041 	__ASSERT_DEBUG(iShortCaption, Panic(EPanicNullPointer));
       
  2042 	// LTEXT short_caption(KMaxCaption) = ""
       
  2043 	WriteTextL(aDataSink, *iShortCaption);
       
  2044 
       
  2045 	// STRUCT caption_and_icon
       
  2046 	WriteCaptionAndIconInfoL(aDataSink, iCaptionAndIcon);
       
  2047 
       
  2048 	// LEN WORD STRUCT view_list[]
       
  2049 	WriteLittleEndianUint16L(aDataSink, 0);
       
  2050 	__ASSERT_DEBUG(iGroupName, Panic(EPanicNullPointer));
       
  2051 	//	LTEXT group_name(KAppMaxGroupName) = ""
       
  2052 	WriteTextL(aDataSink, *iGroupName);
       
  2053 	}
       
  2054 
       
  2055 const TDesC8* CApaLocalisableResourceFileWriter::SecondResourceL(TBool& aSecondResourceInCompressedUnicodeFormat) const
       
  2056 	{
       
  2057 	aSecondResourceInCompressedUnicodeFormat=EFalse;
       
  2058 	return NULL;
       
  2059 	}
       
  2060 
       
  2061 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
  2062 
       
  2063 // ForJavaMIDletInstaller
       
  2064 
       
  2065 EXPORT_C void ForJavaMIDletInstaller::CheckInterimFormatFileNotCorruptL(RFile& aInterimFormatFile)
       
  2066 	{ // static
       
  2067 	RFile temporaryDuplicateOfFile; // this is needed as CFileStore::FromLC takes ownership of the file that it's passed, and closes the RFile object passed in - we still want to use it, so we'll create this temporary duplicate RFile object (it also handily means we don't have to rewind the RFile to the start when we copy it below)
       
  2068 	User::LeaveIfError(temporaryDuplicateOfFile.Duplicate(aInterimFormatFile));
       
  2069 	CFileStore* const fileStore=CFileStore::FromLC(temporaryDuplicateOfFile); // CFileStore::FromLC takes *immediate* ownership of the file it's passed (i.e. before doing anything that can leave)
       
  2070 	if (fileStore->Type()[1]!=KUidInterimFormatFileForJavaMIDletInstaller)
       
  2071 		{
       
  2072 		User::Leave(KErrCorrupt);
       
  2073 		}
       
  2074 	RStoreReadStream rootStream;
       
  2075 	rootStream.OpenLC(*fileStore,fileStore->Root());
       
  2076 	RFs unconnectedFs; // should not actually be used, so we don't need to use a real, connected RFs
       
  2077 	CApaAppInfoFileReader* const appInfoFileReader=new(ELeave) CApaAppInfoFileReader(unconnectedFs);
       
  2078 	CleanupStack::PushL(appInfoFileReader);
       
  2079 	appInfoFileReader->CApaAppInfoFile::ConstructL();
       
  2080 	appInfoFileReader->InternalizeL(rootStream); // will leave if the file is corrupt/badly formed
       
  2081 	CleanupStack::PopAndDestroy(3, fileStore);
       
  2082 	}
       
  2083 
       
  2084 EXPORT_C void ForJavaMIDletInstaller::GetJavaMIDletInfoL(RFs& aFs, const TDesC& aFileName,TUint32& aJavaMIDletInfo_AmsAuthId,TUint32& aJavaMIDletInfo_MIDlet)
       
  2085 	{ // static
       
  2086 	CApaAppInfoFileReader* const appInfoFileReader=CApaAppInfoFileReader::NewLC(aFs, aFileName);
       
  2087 	aJavaMIDletInfo_AmsAuthId=appInfoFileReader->iJavaMIDletInfo_AmsAuthId;
       
  2088 	aJavaMIDletInfo_MIDlet=appInfoFileReader->iJavaMIDletInfo_MIDlet;
       
  2089 	CleanupStack::PopAndDestroy(appInfoFileReader);
       
  2090 	}
       
  2091 
       
  2092 EXPORT_C CApaAppInfoFileWriter* ForJavaMIDletInstaller::NewInterimFormatFileWriterLC(RFs& aFs,const TDesC& aFileName,TUid aApplicationUid,TUint32 aJavaMIDletInfo_AmsAuthId,TInt aJavaMIDletInfo_MIDlet)
       
  2093 	{ // static
       
  2094 	CApaAppInfoFileWriter* self=new(ELeave) CApaAppInfoFileWriter(aFs);
       
  2095 	CleanupStack::PushL(self);
       
  2096 	self->ConstructL(aFileName,aApplicationUid,KUidInterimFormatFileForJavaMIDletInstaller,aJavaMIDletInfo_AmsAuthId,aJavaMIDletInfo_MIDlet);
       
  2097 	return self;
       
  2098 	}
       
  2099 
       
  2100 #endif // UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER
       
  2101 
       
  2102 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER CApaAppInfoFileWriter* CApaAppInfoFileWriter::NewLC(RFs& aFs, const TDesC& aFileName,TUid aUid)
       
  2103 /** Allocates and constructs an aif file writer. It leaves if the path of the 
       
  2104 specified aif file does not exist.
       
  2105 
       
  2106 @param aFs Connected session with the file server.
       
  2107 @param aFileName The full path and (language-neutral) filename of the aif file.
       
  2108 @param aUid The application's third (most derived) UID. 
       
  2109 @return Pointer to the newly constructed and initialised aif file writer. 
       
  2110 The object is left on the cleanup stack. */
       
  2111 	{
       
  2112 	CApaAppInfoFileWriter* self=new(ELeave) CApaAppInfoFileWriter(aFs);
       
  2113 	CleanupStack::PushL(self);
       
  2114 	self->ConstructL(aFileName,aUid);
       
  2115 	return self;
       
  2116 	}
       
  2117 
       
  2118 void CApaAppInfoFileWriter::ConstructL(const TDesC& aFileName,TUid aUid
       
  2119 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
  2120 									   ,TUid aMiddleUid/*=KUidAppInfoFile*/,TUint32 aJavaMIDletInfo_AmsAuthId/*=0*/,TInt aJavaMIDletInfo_MIDlet/*=0*/
       
  2121 #endif
       
  2122 									   )
       
  2123 	{
       
  2124 	__DECLARE_NAME(_S("CApaAppInfoFileWriter"));
       
  2125 	CApaAppInfoFile::ConstructL();
       
  2126 	TInt ret=iFs.MkDirAll(aFileName);
       
  2127     if (ret!=KErrAlreadyExists)
       
  2128         User::LeaveIfError(ret);
       
  2129 	CFileStore* store=CDirectFileStore::ReplaceL(iFs,aFileName,EFileRead|EFileWrite);
       
  2130 	iStore = store;
       
  2131 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
  2132 	iJavaMIDletInfo_AmsAuthId=aJavaMIDletInfo_AmsAuthId;
       
  2133 	iJavaMIDletInfo_MIDlet=aJavaMIDletInfo_MIDlet;
       
  2134 #else
       
  2135 	const TUid aMiddleUid=KUidAppInfoFile;
       
  2136 #endif
       
  2137 	store->SetTypeL(TUidType(KDirectFileStoreLayoutUid,aMiddleUid,aUid));
       
  2138 	iMap=CStoreMap::NewL(*store);	// Ready for Storing components
       
  2139 	}
       
  2140 
       
  2141 void CApaAppInfoFileWriter::ExternalizeL(RWriteStream& aStream) const
       
  2142 	{
       
  2143 	__ASSERT_DEBUG(iCaptionHeaderArray, Panic(EPanicNullPointer));
       
  2144 	aStream<< *iCaptionHeaderArray;
       
  2145 	aStream<< *iIconHeaderArray;
       
  2146 	aStream<< iCapability;
       
  2147 	aStream.WriteInt32L(
       
  2148 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
  2149 						EAifVersionAddsJavaMIDletInfo
       
  2150 #else
       
  2151 						EAifVersionAddsFileOwnershipInfo
       
  2152 #endif
       
  2153 						);
       
  2154 	aStream<< *iDataTypeHeaderArray;
       
  2155 	aStream<< *iViewDataHeaderArray;
       
  2156 	aStream << *iFileOwnershipInfoHeaderArray;
       
  2157 #if defined(UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER)
       
  2158 	aStream.WriteUint32L(iJavaMIDletInfo_AmsAuthId);
       
  2159 	aStream.WriteInt32L(iJavaMIDletInfo_MIDlet);
       
  2160 #endif
       
  2161 	}
       
  2162 
       
  2163 EXPORT_C void CApaAppInfoFileWriter::StoreL()
       
  2164 	{
       
  2165 	__ASSERT_DEBUG(iMap, Panic(EPanicNullPointer));
       
  2166 	__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2167 	RStoreWriteStream outStream(*iMap);
       
  2168 	TStreamId id=outStream.CreateLC(*iStore);
       
  2169 	ExternalizeL(outStream);
       
  2170 	outStream.CommitL();
       
  2171 	CleanupStack::PopAndDestroy(&outStream);
       
  2172 	iMap->Reset();
       
  2173 	iStore->SetRootL(id);
       
  2174 	iStore->CommitL();
       
  2175 	}
       
  2176 
       
  2177 EXPORT_C void CApaAppInfoFileWriter::AddCaptionL(TLanguage aLanguage,const TDesC& aCaption)
       
  2178 /** Appends a caption in the specified language to the aif file.
       
  2179 
       
  2180 @param aLanguage The language of the specified caption.
       
  2181 @param aCaption The new caption.
       
  2182 @leave KErrBadName The caption's name is longer than KApaMaxAppCaption characters. */
       
  2183 
       
  2184 // Write caption out to a new stream and add to iCaptionHeaderArray
       
  2185 	{
       
  2186 	if (aCaption.Length()>KApaMaxAppCaption)
       
  2187 		User::Leave(KErrBadName);
       
  2188 	TCaptionHeader captionHeader;
       
  2189 	captionHeader.iLanguage=aLanguage;
       
  2190 	captionHeader.iCaption=aCaption.AllocL();
       
  2191 	CleanupStack::PushL(captionHeader.iCaption.AsPtr());
       
  2192 	RStoreWriteStream outStream;
       
  2193 	__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2194 	TStreamId id=outStream.CreateLC(*iStore);
       
  2195 	outStream << *captionHeader.iCaption;
       
  2196 	outStream.CommitL();
       
  2197 	CleanupStack::PopAndDestroy(&outStream);
       
  2198 	iMap->BindL(captionHeader.iCaption,id);
       
  2199 	iCaptionHeaderArray->AppendL(captionHeader);
       
  2200 	CleanupStack::Pop(captionHeader.iCaption);
       
  2201 	}
       
  2202 
       
  2203 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddIconL(const TDesC& aIconFileName)
       
  2204 /** Loads the icon's bitmap and mask from the specified mbm file 
       
  2205 and writes the icon to the aif file. Takes ownership of the icon.
       
  2206 
       
  2207 @param aIconFileName Full path and filename of the icon file (with a .mbm 
       
  2208 extension) containing the icon bitmap at identifier 0 and its mask at 1. */
       
  2209 
       
  2210 // Icon file must contain 2 bitmaps: icon and mask, and they are assumed to be the same size.
       
  2211 	{
       
  2212 	CApaMaskedBitmap* icon=CApaMaskedBitmap::NewLC();
       
  2213 	User::LeaveIfError(icon->Load(aIconFileName,0));
       
  2214 	User::LeaveIfError((icon->Mask())->Load(aIconFileName,1));
       
  2215 	CleanupStack::Pop(icon);
       
  2216 	AddIconL(*icon);
       
  2217 	}
       
  2218 
       
  2219 EXPORT_C void CApaAppInfoFileWriter::AddIconL(CApaMaskedBitmap& aIcon)
       
  2220 /** Writes the specified pre-loaded icon to the aif file, and takes ownership of it.
       
  2221 
       
  2222 @param aIcon The new icon. */
       
  2223 
       
  2224 // Guaranteed to take ownership of the aIcon
       
  2225 // Will delete aIcon if it leaves
       
  2226 	{
       
  2227 	CleanupStack::PushL(&aIcon);
       
  2228 	TIconHeader iconHeader;
       
  2229 	iconHeader.iIcon = &aIcon;
       
  2230 	iconHeader.iIconSideInPixels = aIcon.SizeInPixels().iWidth;
       
  2231 	RStoreWriteStream outStream;
       
  2232 	__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2233 	TStreamId id=outStream.CreateLC(*iStore);
       
  2234 	outStream << *iconHeader.iIcon;
       
  2235 	outStream.CommitL();
       
  2236 	CleanupStack::PopAndDestroy(&outStream);
       
  2237 	iMap->BindL(iconHeader.iIcon,id);
       
  2238 	iIconHeaderArray->AppendL(iconHeader);
       
  2239 	CleanupStack::Pop(&aIcon);
       
  2240 	}
       
  2241 
       
  2242 EXPORT_C TInt CApaAppInfoFileWriter::SetCapability(const TDesC8& aInfo)
       
  2243 /** Sets the application's capability information. Note that the 
       
  2244 information is not written to the aif file until StoreL() is called.
       
  2245 @param aInfo A TApaAppCapabilityBuf object.
       
  2246 @return KErrNone always. */
       
  2247 	{
       
  2248 	// check that aInfo is of a permissable length
       
  2249 	TApaAppCapabilityBuf buf;
       
  2250 	TApaAppCapability::CopyCapability(buf,aInfo);
       
  2251 	iCapability = buf();
       
  2252 	return KErrNone;
       
  2253 	}
       
  2254 
       
  2255 EXPORT_C void CApaAppInfoFileWriter::AddDataTypeL(const TDataTypeWithPriority& aTypePriority)
       
  2256 	{
       
  2257 	__ASSERT_DEBUG(aTypePriority.iDataType.Des8().Length()>0,Panic(EDPanicBadDataType));
       
  2258 	__ASSERT_DEBUG(aTypePriority.iPriority<KDataTypePriorityUserSpecified,Panic(EDPanicBadDataType));
       
  2259 	TDataTypeHeader header;
       
  2260 	TDataType* dataType=new(ELeave) TDataType(aTypePriority.iDataType);
       
  2261 	CleanupStack::PushL(dataType);
       
  2262 	header.iDataType=dataType;
       
  2263 	RStoreWriteStream outStream;
       
  2264 	__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2265 	TStreamId id=outStream.CreateLC(*iStore);
       
  2266 	outStream << *header.iDataType;
       
  2267 	outStream.CommitL();
       
  2268 	CleanupStack::PopAndDestroy(&outStream);
       
  2269 	__ASSERT_DEBUG(iMap, Panic(EPanicNullPointer));
       
  2270 	iMap->BindL(header.iDataType,id);
       
  2271 	header.iPriority=aTypePriority.iPriority;
       
  2272 	iDataTypeHeaderArray->AppendL(header);
       
  2273 	CleanupStack::Pop(dataType);
       
  2274 	}
       
  2275 
       
  2276 //
       
  2277 // Adds a view with id aViewId to the data to be stored in the AIF. Icons and captions can be added to the
       
  2278 // view before it is stored - view data is written to an inline store so all the information for the view must
       
  2279 // be added and then the call to store the data made.
       
  2280 //
       
  2281 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddViewL(TUid aViewId)
       
  2282 // Write view data out to a new stream and add to iViewDataHeaderArray
       
  2283 	{
       
  2284 	AddViewL(aViewId,0);
       
  2285 	}
       
  2286 
       
  2287 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddViewL(TUid aViewId,TInt aScreenMode)
       
  2288 	{
       
  2289 	TViewDataHeader viewDataHeader;
       
  2290 	CApaAIFViewData* viewData=CApaAIFViewData::NewLC();
       
  2291 	viewData->SetViewUid(aViewId);
       
  2292 	viewData->SetScreenMode(aScreenMode);
       
  2293 	viewDataHeader.iViewData=viewData;
       
  2294 	__ASSERT_DEBUG(iViewDataHeaderArray, Panic(EPanicNullPointer));
       
  2295 	iViewDataHeaderArray->AppendL(viewDataHeader);
       
  2296 	CleanupStack::Pop(viewData);
       
  2297 	}
       
  2298 
       
  2299 //
       
  2300 // Stores the view data in the AIF, writing the store inline.
       
  2301 //
       
  2302 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::StoreViewL(TUid aViewId)
       
  2303 	{
       
  2304 	__ASSERT_DEBUG(iViewDataHeaderArray, Panic(EPanicNullPointer));
       
  2305 	const TInt count=iViewDataHeaderArray->Count();
       
  2306 	for (TInt ii=0;ii<count;ii++)
       
  2307 		{
       
  2308 		const TViewDataHeader& pData=(*iViewDataHeaderArray)[ii];
       
  2309 		if (pData.iViewData.AsPtr()->ViewUid() == aViewId)
       
  2310 			{
       
  2311 			RStoreWriteStream outStream;
       
  2312 			__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2313 			TStreamId id=outStream.CreateLC(*iStore);
       
  2314 			outStream << *pData.iViewData;
       
  2315 			outStream.CommitL();
       
  2316 			CleanupStack::PopAndDestroy(&outStream);
       
  2317 			iMap->BindL(pData.iViewData,id);
       
  2318 			return;
       
  2319 			}
       
  2320 		}
       
  2321 	}
       
  2322 
       
  2323 //
       
  2324 // Adds the icon aIcon to the view data with id aViewId which will later be stored in the AIF.
       
  2325 //
       
  2326 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddViewIconL(CApaMaskedBitmap& aIcon,TUid aViewId)
       
  2327 	{
       
  2328 	CApaAIFViewData* viewData=NULL;
       
  2329 	__ASSERT_DEBUG(iViewDataHeaderArray, Panic(EPanicNullPointer));
       
  2330 	const TInt count=iViewDataHeaderArray->Count();
       
  2331 	for (TInt ii=0;ii<count;ii++)
       
  2332 		{
       
  2333 		const TViewDataHeader& pData=(*iViewDataHeaderArray)[ii];
       
  2334 		if (pData.iViewData.AsPtr()->ViewUid() == aViewId)
       
  2335 			{
       
  2336 			viewData=pData.iViewData.AsPtr();
       
  2337 			}
       
  2338 		}
       
  2339 	if (viewData)
       
  2340 		viewData->AddIconL(aIcon);
       
  2341 	}
       
  2342 
       
  2343 //
       
  2344 // Adds the caption aCaption in langauge aLanguage to the view data with id aViewId which will later be stored in the AIF.
       
  2345 //
       
  2346 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddViewCaptionL(TLanguage aLanguage,const TDesC& aCaption,TUid aViewId)
       
  2347 	{
       
  2348 	CApaAIFViewData* viewData=NULL;
       
  2349 	const TInt count=iViewDataHeaderArray->Count();
       
  2350 	for (TInt ii=0;ii<count;ii++)
       
  2351 		{
       
  2352 		const TViewDataHeader& pData=(*iViewDataHeaderArray)[ii];
       
  2353 		if (pData.iViewData.AsPtr()->ViewUid() == aViewId)
       
  2354 			{
       
  2355 			viewData=pData.iViewData.AsPtr();
       
  2356 			}
       
  2357 		}
       
  2358 	if (viewData)
       
  2359 		viewData->AddCaptionL(aLanguage,aCaption);
       
  2360 	}
       
  2361 
       
  2362 //
       
  2363 // Adds the name aOwnedFileName to the list of files described as being owned by this application to later be stored in the AIF.
       
  2364 //
       
  2365 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void CApaAppInfoFileWriter::AddOwnedFileL(const TDesC& aOwnedFileName)
       
  2366 	{
       
  2367 	if (aOwnedFileName.Length()>KMaxFileName)
       
  2368 		User::Leave(KErrBadName);
       
  2369 	TFileOwnershipInfoHeader fileOwnershipInfoHeader;
       
  2370 	fileOwnershipInfoHeader.iOwnedFileName=aOwnedFileName.AllocL();
       
  2371 	CleanupStack::PushL(fileOwnershipInfoHeader.iOwnedFileName.AsPtr());
       
  2372 	RStoreWriteStream outStream;
       
  2373 	__ASSERT_DEBUG(iStore, Panic(EPanicNullPointer));
       
  2374 	TStreamId id=outStream.CreateLC(*iStore);
       
  2375 	outStream << *fileOwnershipInfoHeader.iOwnedFileName;
       
  2376 	outStream.CommitL();
       
  2377 	CleanupStack::PopAndDestroy(&outStream);
       
  2378 	__ASSERT_DEBUG(iMap, Panic(EPanicNullPointer));
       
  2379 	iMap->BindL(fileOwnershipInfoHeader.iOwnedFileName,id);
       
  2380 	__ASSERT_DEBUG(iFileOwnershipInfoHeaderArray, Panic(EPanicNullPointer));
       
  2381 	iFileOwnershipInfoHeaderArray->AppendL(fileOwnershipInfoHeader);
       
  2382 	CleanupStack::Pop(fileOwnershipInfoHeader.iOwnedFileName);
       
  2383 	}
       
  2384 
       
  2385 CApaAppCaptionFileReader::CApaAppCaptionFileReader(RFs& aFs,const TDesC& aAppFileName)
       
  2386 : iFs(aFs)
       
  2387 	{
       
  2388 	__ASSERT_DEBUG((aAppFileName.Length()+KApparcExtraLengthOfCaptionFileName<KMaxFileName),Panic(EFilenameTooLong));
       
  2389 	TParse appFileNameParse;
       
  2390 	appFileNameParse.Set(aAppFileName,NULL,NULL);
       
  2391 	iCaptionFileName=appFileNameParse.DriveAndPath(); //extract path name 
       
  2392 	iCaptionFileName.Append(appFileNameParse.Name()); //add app name without extension
       
  2393 	iCaptionFileName.Append(KApaCaptionFileSuffix); //add suffix
       
  2394 	iCaptionFileName.Append(KAppResourceFileExtension); //add extension
       
  2395 	BaflUtils::NearestLanguageFile(aFs,iCaptionFileName);
       
  2396 	}
       
  2397 
       
  2398 void CApaAppCaptionFileReader::GetCaptionsL(TApaAppCaption& aCaption,TApaAppCaption& aShortCaption)
       
  2399 //reads the caption and shortcaption of the current language from the appropriate caption file
       
  2400 	{	
       
  2401 	CResourceFile* file = CResourceFile::NewL(iFs, iCaptionFileName, 0, 0);
       
  2402 	CleanupStack::PushL(file);
       
  2403 	RResourceReader reader;
       
  2404 	reader.OpenL(file, 1);
       
  2405 	CleanupClosePushL(reader);
       
  2406 	aCaption = reader.ReadTPtrCL();
       
  2407 	aShortCaption = reader.ReadTPtrCL();
       
  2408 	CleanupStack::PopAndDestroy(&reader);
       
  2409 	CleanupStack::PopAndDestroy(file);
       
  2410 
       
  2411 	if ((!aShortCaption.Length())&&(aCaption.Length()))
       
  2412 		aShortCaption=aCaption;
       
  2413 	else if ((!aCaption.Length())&&(aShortCaption.Length()))
       
  2414 		aCaption=aShortCaption;	
       
  2415 	}
       
  2416 
       
  2417 //
       
  2418 // Sets the drive of aAifName to the current locale drive.
       
  2419 // Assumes that aAifName is already a valid full filename.
       
  2420 //
       
  2421 EXPORT_C_NOT_NEEDED_FOR_JAVA_MIDLET_INSTALLER void AppInfoFileUtils::GetAifFileName(const RFs& aFs,TDes& aAifName)
       
  2422 	{ // static
       
  2423 	TFileName aifName(aAifName);
       
  2424 	BaflUtils::NearestLanguageFile(aFs,aifName);
       
  2425 	aAifName=aifName;
       
  2426 	}
       
  2427 
       
  2428 //
       
  2429 // Sets aAifName to the full path of the relevant .AIF file.
       
  2430 // Note that this may be on a different drive to the .APP file if the system drive has been
       
  2431 // set to point to a new locale that has been downloaded.
       
  2432 //
       
  2433 void AppInfoFileUtils::GetAifFileNameL(const RFs& aFs,const TDesC& aFullName,TDes& aAifName)
       
  2434 	{ // static
       
  2435 	TParse parse;
       
  2436 	User::LeaveIfError(parse.Set(KAppInfoFileExtension,&aFullName,NULL));
       
  2437 	aAifName=parse.FullName();
       
  2438 	AppInfoFileUtils::GetAifFileName(aFs,aAifName);
       
  2439 	}
       
  2440 	
       
  2441 #endif // UI_FRAMEWORKS_V1_REMNANT_FOR_JAVA_MIDLET_INSTALLER