javamanager/javabackup/midp2backup_usif/src.s60/midp2backupplugin.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 77 7cee158cb8cd
child 84 0553e2305d00
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of Midp2BackupPlugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "midp2backupplugin.h"
       
    20 #include "midp2backupdataids.h"
       
    21 #include "apparcbackuputil.h"
       
    22 #include "javastoragebackuputil.h"
       
    23 #include "javaversionbackuputil.h"
       
    24 
       
    25 #include "javastoragenames.h"
       
    26 #include "javastorageentry.h"
       
    27 #include "javastorage.h"
       
    28 
       
    29 #include "javacommonutils.h"
       
    30 #include "logger.h"
       
    31 
       
    32 #include <connect/sbdefs.h>
       
    33 #include <s32mem.h>
       
    34 #include <s32file.h>
       
    35 #include <f32file.h>
       
    36 #include <apgcli.h>
       
    37 
       
    38 
       
    39 using namespace std;
       
    40 using namespace java::storage;
       
    41 using namespace java::backup;
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 CMidp2BackupPlugin::CMidp2BackupPlugin()
       
    46 {
       
    47     LOG(EBackup, EInfo, "CMidp2BackupPlugin constructor");
       
    48 }
       
    49 
       
    50 void CMidp2BackupPlugin::ConstructL()
       
    51 {
       
    52     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ConstructL");
       
    53 
       
    54     iIconDescIndex = 0;
       
    55     iBufferSpaceLeft = 0;
       
    56     iFirstCallToGetBackupDataSection = ETrue;
       
    57     iStorageDataBackup = ETrue;
       
    58     iStorageDataRestore = ETrue;
       
    59     iJavaVersionInfoWritten = EFalse;
       
    60     iRestoreState = EVersion;
       
    61 
       
    62     User::LeaveIfError(iFs.Connect());
       
    63     // to share file handles with AppArc
       
    64     User::LeaveIfError(iFs.ShareProtected());
       
    65 
       
    66     iStorageBackupUtil = CStorageBackupUtil::NewL();
       
    67     iAppArcUtil = CAppArcBackupUtil::NewL(iFs);
       
    68 }
       
    69 
       
    70 CMidp2BackupPlugin* CMidp2BackupPlugin::NewL()
       
    71 {
       
    72     LOG(EBackup, EInfo, "CMidp2BackupPlugin::NewL");
       
    73 
       
    74     CMidp2BackupPlugin* self = new(ELeave) CMidp2BackupPlugin();
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop();
       
    78 
       
    79     return self;
       
    80 }
       
    81 
       
    82 CMidp2BackupPlugin::~CMidp2BackupPlugin()
       
    83 {
       
    84     LOG(EBackup, EInfo, "CMidp2BackupPlugin destructor");
       
    85 
       
    86     iFs.Close();
       
    87     iIconUidArray.Close();
       
    88     delete iAppArcUtil;
       
    89     delete iIconDesc;
       
    90     delete iRestoreIconDesc;
       
    91     delete iStorageBackupUtil;
       
    92 }
       
    93 
       
    94 // from base class CBackupPlugin
       
    95 
       
    96 void CMidp2BackupPlugin::PrepareForBURL(TInt aBackupStateValue)
       
    97 {
       
    98     (void)aBackupStateValue;  // Just to suppress a warning in release builds
       
    99     LOG1(EBackup, EInfo, "CMidp2BackupPlugin::PrepareForBURL, BUR state: %d", aBackupStateValue);
       
   100 }
       
   101 
       
   102 void CMidp2BackupPlugin::ReceiveSnapshotDataL(TDriveNumber /* aDrive */, TDesC8& /* aBuffer */, TBool /* aLastSection */)
       
   103 {
       
   104     JELOG2(EBackup);
       
   105     User::Leave(KErrNotSupported);
       
   106 }
       
   107 
       
   108 TUint CMidp2BackupPlugin::GetExpectedDataSize(TDriveNumber /* aDrive */)
       
   109 {
       
   110     JELOG2(EBackup);
       
   111     return 0;
       
   112 }
       
   113 
       
   114 void CMidp2BackupPlugin::GetSnapshotDataL(TDriveNumber /* aDrive */, TPtr8& /* aBuffer */, TBool& /* aFinished */)
       
   115 {
       
   116     JELOG2(EBackup);
       
   117     User::Leave(KErrNotSupported);
       
   118 }
       
   119 
       
   120 void CMidp2BackupPlugin::InitialiseGetBackupDataL(TDriveNumber aDrive)
       
   121 {
       
   122     LOG(EBackup, EInfo, "CMidp2BackupPlugin::InitialiseGetBackupDataL");
       
   123     iDrive = aDrive;
       
   124 }
       
   125 
       
   126 void CMidp2BackupPlugin::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished)
       
   127 {
       
   128     LOG(EBackup, EInfo, "CMidp2BackupPlugin::GetBackupDataSectionL");
       
   129 
       
   130     iBufferSpaceLeft = aBuffer.MaxLength();
       
   131     RDesWriteStream stream(aBuffer);
       
   132     CleanupClosePushL(stream);
       
   133 
       
   134     if (!iJavaVersionInfoWritten)
       
   135     {
       
   136         JavaVersionBackupUtil::WriteJavaVersionL(stream);
       
   137         iJavaVersionInfoWritten = ETrue;
       
   138         iBufferSpaceLeft -= 8;
       
   139     }
       
   140 
       
   141     if (iStorageDataBackup)
       
   142     {
       
   143         iStorageBackupUtil->BackupStorageDataL(stream, iStorageDataBackup, iBufferSpaceLeft);
       
   144         aFinished = EFalse;
       
   145     }
       
   146 
       
   147     else
       
   148     {
       
   149         if (iFirstCallToGetBackupDataSection)
       
   150         {
       
   151             LOG(EBackup, EInfo, "First Call To GetBackupDataSection");
       
   152             // Get the uids of midlets whose icons are to be backed up
       
   153             iIconFilePointer = 0;
       
   154             ResetIconArray();
       
   155             iAppArcUtil->GetMidletsFromAppArcL(iIconUidArray, iDrive);
       
   156 
       
   157             /* Streaming MMC's unique Id, if current drive is MMC
       
   158                and there's at least one midlet on the drive*/
       
   159             if (iIconUidArray.Count() > 0 && iDrive >= EDriveE && iDrive <= EDriveZ)
       
   160             {
       
   161                 TUint32 mmcId = MmcIdL();
       
   162 
       
   163                 if (mmcId != 0)
       
   164                 {
       
   165                     LOG1(EBackup,EInfo, "Write MMC id: %u", mmcId);
       
   166                     stream.WriteUint32L(mmcId);
       
   167                     iBufferSpaceLeft -= sizeof(mmcId);
       
   168                 }
       
   169             }
       
   170             // Setting flag to EFalse
       
   171             iFirstCallToGetBackupDataSection = EFalse;
       
   172         }
       
   173 
       
   174         // Next icon uid and filename
       
   175         TUid currentUid;
       
   176         HBufC* fullFileName = NULL;
       
   177 
       
   178         // Streaming leftover part of icon file
       
   179         if (iIconDescIndex)
       
   180         {
       
   181             LOG(EBackup, EInfo, "Streaming leftover part of icon file");
       
   182 
       
   183             /* if the icon file is bigger than the space in the buffer, write only
       
   184              part of it and fill iLeftover with remaining part. */
       
   185             if (iIconDesc->Size() - iIconDescIndex > iBufferSpaceLeft)
       
   186             {
       
   187                 stream.WriteL(iIconDesc->Mid(iIconDescIndex), iBufferSpaceLeft);
       
   188                 iIconDescIndex += iBufferSpaceLeft;
       
   189             }
       
   190             else
       
   191             {
       
   192                 stream.WriteL(iIconDesc->Mid(iIconDescIndex));
       
   193                 iIconDescIndex = 0;
       
   194             }
       
   195 
       
   196             aFinished = EFalse;
       
   197         }
       
   198 
       
   199         // Get new icon file
       
   200         else if (NextIcon(currentUid, fullFileName))
       
   201         {
       
   202             LOG1(EBackup, EInfo, "New icon file, id: %d", currentUid.iUid);
       
   203 
       
   204             // Readstream for icon file
       
   205             RFileReadStream fileStream;
       
   206 
       
   207             User::LeaveIfError(fileStream.Open(iFs, *fullFileName, EFileRead));
       
   208             CleanupClosePushL(fileStream);
       
   209 
       
   210             TEntry* entry = new(ELeave) TEntry();
       
   211             CleanupStack::PushL(entry);
       
   212 
       
   213             iFs.Entry(*fullFileName, *entry);
       
   214             TInt32 size = entry->iSize;
       
   215 
       
   216             // Write icon file content into iIconDesc
       
   217             LOG(EBackup, EInfo, "Write icon file content into iIconDesc");
       
   218             delete iIconDesc;
       
   219             iIconDesc = NULL;
       
   220             iIconDesc = HBufC8::NewL(size);
       
   221 
       
   222             TPtr8 buf = iIconDesc->Des();
       
   223             fileStream.ReadL(buf, size);
       
   224 
       
   225             // get the group name of the midlet from AppArc
       
   226             TBuf< KApaMaxAppGroupName >groupName(iAppArcUtil->GetMidletGroupName(currentUid));
       
   227             TInt groupNameSize = groupName.Size();
       
   228 
       
   229             // Write the size of the data
       
   230             LOG(EBackup,EInfo, "Write the size of the data");
       
   231 
       
   232             TParsePtrC parse(*fullFileName);
       
   233             TPtrC fileName = parse.NameAndExt();
       
   234             TInt32 fileNameSize = fileName.Size();
       
   235 
       
   236             stream.WriteInt32L(sizeof(TUid)    // Uid
       
   237                                + sizeof(TInt32)   // fileNameSize
       
   238                                + fileNameSize // filename
       
   239                                + sizeof(TInt32)   // number of icons
       
   240                                + sizeof(TInt32)   // groupnamesize
       
   241                                + groupNameSize
       
   242                                + size // icon file
       
   243                               );
       
   244             iBufferSpaceLeft -= sizeof(TInt32);
       
   245 
       
   246             // Write the Uid of the midlet
       
   247             LOG(EBackup, EInfo, "Write the Uid of the midlet");
       
   248             stream.WriteInt32L(currentUid.iUid);
       
   249             iBufferSpaceLeft -= sizeof(TUid);
       
   250 
       
   251             // Write the size of the icon filename
       
   252             LOG(EBackup, EInfo, "Write the size of the icon filename");
       
   253             stream.WriteInt32L(fileNameSize);
       
   254             iBufferSpaceLeft -= sizeof(TInt32);
       
   255 
       
   256             // Write icon filename
       
   257             LOG(EBackup, EInfo, "Write icon filename");
       
   258             stream.WriteL(fileName);
       
   259             iBufferSpaceLeft -= fileNameSize;
       
   260 
       
   261             // Write number of icons in midlet
       
   262             LOG(EBackup, EInfo, "Write number of icons in midlet");
       
   263             TInt iconCount;
       
   264             iAppArcUtil->NumberOfOwnDefinedIcons(TUid::Uid(currentUid.iUid), iconCount);
       
   265             stream.WriteInt32L(iconCount);
       
   266             iBufferSpaceLeft -= sizeof(TInt32);
       
   267 
       
   268             // TPtr8 groupName(iAppArcUtil->GetMidletGroupName(currentUid));
       
   269             LOG(EBackup, EInfo, "Write the size of the Group name of the midlet");
       
   270             stream.WriteInt32L(groupNameSize);
       
   271             iBufferSpaceLeft -= sizeof(TInt32);
       
   272 
       
   273             if (groupNameSize != 0)
       
   274             {
       
   275                 LOG(EBackup, EInfo, "Write the Group name of the midlet");
       
   276                 stream.WriteL(groupName);
       
   277                 iBufferSpaceLeft -= groupNameSize;
       
   278             }
       
   279 
       
   280             /* if the icon file is bigger than the space in the buffer,
       
   281                write only part of it and fill iLeftover with remaining part */
       
   282             LOG(EBackup, EInfo, "Write icon");
       
   283             if (size > iBufferSpaceLeft)
       
   284             {
       
   285                 stream.WriteL(buf, iBufferSpaceLeft);
       
   286                 iIconDescIndex = iBufferSpaceLeft;
       
   287             }
       
   288             else
       
   289             {
       
   290                 stream.WriteL(buf, size);
       
   291                 iIconDescIndex = 0;
       
   292             }
       
   293 
       
   294             aFinished = EFalse;
       
   295 
       
   296             CleanupStack::PopAndDestroy(&fileStream);
       
   297             CleanupStack::PopAndDestroy(entry);
       
   298         }
       
   299 
       
   300         else
       
   301         {
       
   302             aFinished = ETrue;
       
   303             iFirstCallToGetBackupDataSection = ETrue;
       
   304             iStorageDataBackup = ETrue;
       
   305         }
       
   306 
       
   307         delete fullFileName;
       
   308     }
       
   309     CleanupStack::PopAndDestroy(&stream);
       
   310 }
       
   311 
       
   312 
       
   313 void CMidp2BackupPlugin::InitialiseRestoreBaseDataL(TDriveNumber aDrive)
       
   314 {
       
   315     LOG(EBackup, EInfo, "CMidp2BackupPlugin::InitialiseRestoreBaseDataL");
       
   316     iDrive = aDrive;
       
   317 }
       
   318 
       
   319 void CMidp2BackupPlugin::RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished)
       
   320 {
       
   321     LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreBaseDataSectionL");
       
   322 
       
   323     iBufferSpaceLeft = aBuffer.Size();
       
   324     RDesReadStream stream(aBuffer);
       
   325     CleanupClosePushL(stream);
       
   326     TBool versionCheck = ETrue;
       
   327 
       
   328     if (((iRestoreState == EVersion) || (iRestoreState == EInstall)) && iBufferSpaceLeft >= 8)
       
   329     {
       
   330         if (iRestoreState == EInstall)
       
   331         {
       
   332             versionCheck = EFalse;
       
   333         }
       
   334         TUint ret = JavaVersionBackupUtil::CheckJavaVersionL(stream,iDrive,versionCheck);
       
   335         if (1==ret)
       
   336         {
       
   337             // Here set the satus to restore finished, so that control goes back to SBE & SBE calls B&R for another drive
       
   338             iRestoreState = EInstall;
       
   339         }
       
   340         else
       
   341         {
       
   342             /* version information has been written to stream.
       
   343              So change restore state to restore storage data  */
       
   344             iRestoreState = EStorage;
       
   345         }
       
   346         // version information is of length 8 bytes.
       
   347         iBufferSpaceLeft -= 8;
       
   348     }
       
   349 
       
   350     if (iRestoreState == EStorage)
       
   351     {
       
   352         iStorageBackupUtil -> RestoreStorageDataL(stream, iRestoreState, iBufferSpaceLeft);
       
   353     }
       
   354 
       
   355     // Only at first call
       
   356     if ((iRestoreState != EStorage && iRestoreState != EVersion) && (iRestoreState != EInstall))
       
   357     {
       
   358         if (iRestoreState == EAppArc)
       
   359         {
       
   360             // Making AppArc deregistrations
       
   361             TRAPD(err, iAppArcUtil->DeregisterAppsL(iDrive));
       
   362 
       
   363             if (err)
       
   364             {
       
   365                 ELOG(EBackup, "Leave in deregistering apps");
       
   366             }
       
   367         }
       
   368 
       
   369         // Process the data buffer for restore
       
   370         ProcessBufferL(stream);
       
   371 
       
   372         if (aFinished)
       
   373         {
       
   374             // Set state to EStorage
       
   375             iRestoreState = EStorage;
       
   376         }
       
   377     }
       
   378 
       
   379     aFinished = ETrue;
       
   380     CleanupStack::PopAndDestroy(&stream);
       
   381 }
       
   382 
       
   383 void CMidp2BackupPlugin::InitialiseRestoreIncrementDataL(TDriveNumber /* aDrive */)
       
   384 {
       
   385     JELOG2(EBackup);
       
   386     User::Leave(KErrNotSupported);
       
   387 }
       
   388 
       
   389 void CMidp2BackupPlugin::RestoreIncrementDataSectionL(TDesC8& /* aBuffer */, TBool /* aFinished */)
       
   390 {
       
   391     JELOG2(EBackup);
       
   392     User::Leave(KErrNotSupported);
       
   393 }
       
   394 
       
   395 void CMidp2BackupPlugin::RestoreComplete(TDriveNumber /* aDrive */)
       
   396 {
       
   397     LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreComplete");
       
   398 }
       
   399 
       
   400 TUint CMidp2BackupPlugin::MmcIdL()
       
   401 {
       
   402     LOG(EBackup, EInfo, "CMidp2BackupPlugin::MmcIdL()");
       
   403 
       
   404     TVolumeInfo* volumeInfo = new(ELeave) TVolumeInfo();
       
   405 
       
   406     TInt err = iFs.Volume(*volumeInfo, iDrive);
       
   407 
       
   408     if (!err)
       
   409     {
       
   410         TUint mmcId = volumeInfo->iUniqueID;
       
   411         return mmcId;
       
   412     }
       
   413     else
       
   414     {
       
   415         return 0;
       
   416     }
       
   417 
       
   418 
       
   419 }
       
   420 
       
   421 void CMidp2BackupPlugin::ProcessBufferL(RDesReadStream& stream)
       
   422 {
       
   423     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessBuffer()");
       
   424 
       
   425     // Cycle until there's data in the buffer
       
   426     while (iBufferSpaceLeft > 0)
       
   427     {
       
   428         switch (iRestoreState)
       
   429         {
       
   430         case EAppArc:
       
   431             ProcessFirstBufferL(stream, iBufferSpaceLeft);
       
   432             break;
       
   433 
       
   434         case EInIcon:
       
   435             ProcessInIconL(stream, iBufferSpaceLeft);
       
   436             break;
       
   437 
       
   438         case EInSize:
       
   439             ProcessInSizeL(stream, iBufferSpaceLeft);
       
   440             break;
       
   441 
       
   442         default:
       
   443             CleanupStack::PopAndDestroy(&stream);
       
   444             User::Leave(KErrNotSupported);
       
   445         }
       
   446     }
       
   447 }
       
   448 
       
   449 
       
   450 _LIT(KStarWildCard, "*.*");
       
   451 
       
   452 void CMidp2BackupPlugin::RestoreMmcRegistryL()
       
   453 {
       
   454     LOG(EBackup, EInfo, "CMidp2BackupPlugin::RestoreMmcRegistry()");
       
   455 
       
   456     /* If backed up MMC is not the same as the current MMC, copy the entries
       
   457        from the directory of the backed up MMC to the directory
       
   458        of the current MMC */
       
   459     TUint32 mmc = MmcIdL();
       
   460 
       
   461     if (iBackupMmc != mmc)
       
   462     {
       
   463         // Create path to old place
       
   464         TPath path_old;
       
   465         CreateMmcPath(path_old, iDrive, iBackupMmc);
       
   466 
       
   467         // Create path to new place
       
   468         TPath path_new;
       
   469         CreateMmcPath(path_new, iDrive, mmc);
       
   470 
       
   471         // Get old files list
       
   472         CFileMan* fileMan = CFileMan::NewL(iFs);
       
   473 
       
   474         CleanupStack::PushL(fileMan);
       
   475 
       
   476         // Copy to new place
       
   477         iFs.MkDir(path_new);
       
   478         path_old.Append(KStarWildCard);
       
   479         TInt  err = fileMan->Copy(path_old, path_new);
       
   480 
       
   481         ILOG1(EBackup, "File copy, status: %d", err);
       
   482 
       
   483         User::LeaveIfError(err);
       
   484 
       
   485         CleanupStack::PopAndDestroy();
       
   486     }
       
   487 }
       
   488 
       
   489 _LIT(KPrivatePath, "C:\\private\\");
       
   490 
       
   491 void CMidp2BackupPlugin::CreateMmcPath(TDes& aPathName, TInt aDrive, TUint aUniqueId)
       
   492 {
       
   493     LOG(EBackup, EInfo, "CMidp2BackupPlugin::CreateMmcPath()");
       
   494 
       
   495     aPathName.Zero();
       
   496     aPathName.Append(KPrivatePath);
       
   497     aPathName.AppendNum(KRegistryServerUid, EHex);
       
   498     aPathName.Append(KPathDelimiter);
       
   499 
       
   500     // append drive name
       
   501     TDriveUnit driveUnit(aDrive);
       
   502     aPathName.Append(driveUnit.Name().Left(1));
       
   503     aPathName.Append(KPathDelimiter);
       
   504 
       
   505     TUint64 id = aUniqueId;
       
   506     aPathName.AppendNum(id, EHex);
       
   507     aPathName.Append(KPathDelimiter);
       
   508 }
       
   509 
       
   510 TBool CMidp2BackupPlugin::NextIcon(TUid& aCurrentUid, HBufC*& aFullFileName)
       
   511 {
       
   512     LOG(EBackup, EInfo, "CMidp2BackupPlugin::NextIcon()");
       
   513 
       
   514     if (iIconUidArray.Count() > iIconFilePointer)
       
   515     {
       
   516         aCurrentUid = iIconUidArray[iIconFilePointer];
       
   517         iAppArcUtil->GetIconFilename(iIconUidArray[iIconFilePointer], aFullFileName);
       
   518         iIconFilePointer++;
       
   519         return ETrue;
       
   520     }
       
   521     else
       
   522     {
       
   523         // There are no more icon files
       
   524         return EFalse;
       
   525     }
       
   526 }
       
   527 
       
   528 void CMidp2BackupPlugin::ProcessFirstBufferL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   529 {
       
   530     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessFirstBuffer()");
       
   531 
       
   532     if (iDrive >= EDriveE && iDrive <= EDriveZ)
       
   533     {
       
   534         // Read MMC id and restore MMC entries if needed
       
   535         iBackupMmc = aStream.ReadUint32L();
       
   536         aBufferSpaceLeft -= sizeof(iBackupMmc);
       
   537         LOG1(EBackup, EInfo, "Read MMC Id: %u", iBackupMmc);
       
   538         RestoreMmcRegistryL();
       
   539     }
       
   540     if (aBufferSpaceLeft >= sizeof(TInt32))
       
   541     {
       
   542         iIconFileSizeLeft = aStream.ReadInt32L();
       
   543         aBufferSpaceLeft -= sizeof(iIconFileSizeLeft);
       
   544         iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   545         iRestoreState = EInIcon;
       
   546     }
       
   547     else
       
   548     {
       
   549         // No more data to read
       
   550         aBufferSpaceLeft = 0;
       
   551     }
       
   552 }
       
   553 
       
   554 void CMidp2BackupPlugin::ProcessInIconL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   555 {
       
   556     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInIcon()");
       
   557 
       
   558     TPtr8 restoreIconPtr = iRestoreIconDesc->Des();
       
   559     HBufC8* tempDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   560     CleanupStack::PushL(tempDesc);
       
   561     TPtr8 tempPtr = tempDesc->Des();
       
   562 
       
   563     // Icon cannot be read fully
       
   564     if (iIconFileSizeLeft > aBufferSpaceLeft)
       
   565     {
       
   566         aStream.ReadL(tempPtr, aBufferSpaceLeft);
       
   567         restoreIconPtr.Append(tempPtr);
       
   568         iIconFileSizeLeft -= aBufferSpaceLeft;
       
   569         aBufferSpaceLeft = 0;
       
   570         iRestoreState = EInIcon;
       
   571     }
       
   572     // Icon can be read fully
       
   573     else
       
   574     {
       
   575         aStream.ReadL(tempPtr, iIconFileSizeLeft);
       
   576         restoreIconPtr.Append(tempPtr);
       
   577         aBufferSpaceLeft -= iIconFileSizeLeft;
       
   578         iRestoreState = EInSize;
       
   579 
       
   580         TRAPD(err, iAppArcUtil->RegisterAppL(restoreIconPtr, iDrive));
       
   581 
       
   582         if (err)
       
   583         {
       
   584             ELOG(EBackup, "Registerin application to AppArc failed.");
       
   585         }
       
   586     }
       
   587 
       
   588     CleanupStack::PopAndDestroy(tempDesc);
       
   589 }
       
   590 
       
   591 void CMidp2BackupPlugin::ProcessInSizeL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   592 {
       
   593     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInSize()");
       
   594 
       
   595     if (aBufferSpaceLeft >= sizeof(TInt32))
       
   596     {
       
   597         if (iSizeBuffer.Size() != 0)
       
   598         {
       
   599             // Read leftover part of size
       
   600             TInt readData = sizeof(TInt32) - iSizeBuffer.Size();
       
   601             aStream.ReadL(iSizeBuffer, readData);
       
   602             RMemReadStream sizeStream(iSizeBuffer.Ptr(), 4);
       
   603             CleanupClosePushL(sizeStream);
       
   604             iIconFileSizeLeft = sizeStream.ReadInt32L();
       
   605             CleanupStack::PopAndDestroy(&sizeStream);
       
   606             aBufferSpaceLeft -= sizeof(readData);
       
   607         }
       
   608         else
       
   609         {
       
   610             // Read size in full
       
   611             iIconFileSizeLeft = aStream.ReadInt32L();
       
   612             aBufferSpaceLeft -= sizeof(iIconFileSizeLeft);
       
   613         }
       
   614 
       
   615         delete iRestoreIconDesc;
       
   616         iRestoreIconDesc = NULL;
       
   617         iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   618         iRestoreState = EInIcon;
       
   619     }
       
   620     else
       
   621     {
       
   622         // Read first byte(s) of size
       
   623         aStream.ReadL(iSizeBuffer, aBufferSpaceLeft);
       
   624         aBufferSpaceLeft = 0;
       
   625     }
       
   626 }
       
   627 
       
   628 void CMidp2BackupPlugin::ResetIconArray()
       
   629 {
       
   630     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ResetIconArray()");
       
   631 
       
   632     // Remove all entries
       
   633     while (iIconUidArray.Count())
       
   634     {
       
   635         iIconUidArray.Remove(0);
       
   636     }
       
   637 }