javamanager/javabackup/midp2backup/src.s60/midp2backupplugin.cpp
branchRCL_3
changeset 14 04becd199f91
child 18 9ac0a0a7da70
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 <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         TDesC path_old_Des(path_old);
       
   484         TDesC path_new_Des(path_new);
       
   485 
       
   486         /*LOG1WSTR( EBackup, EInfo, "path_old: %S", &path_old );
       
   487         LOG1WSTR( EBackup, EInfo, "path_new: %S", &path_new );
       
   488         */
       
   489         User::LeaveIfError(err);
       
   490 
       
   491         CleanupStack::PopAndDestroy();
       
   492     }
       
   493 }
       
   494 
       
   495 _LIT(KPrivatePath, "C:\\private\\");
       
   496 
       
   497 void CMidp2BackupPlugin::CreateMmcPath(TDes& aPathName, TInt aDrive, TUint aUniqueId)
       
   498 {
       
   499     LOG(EBackup, EInfo, "CMidp2BackupPlugin::CreateMmcPath()");
       
   500 
       
   501     aPathName.Zero();
       
   502     aPathName.Append(KPrivatePath);
       
   503     aPathName.AppendNum(KRegistryServerUid, EHex);
       
   504     aPathName.Append(KPathDelimiter);
       
   505 
       
   506     // append drive name
       
   507     TDriveUnit driveUnit(aDrive);
       
   508     aPathName.Append(driveUnit.Name().Left(1));
       
   509     aPathName.Append(KPathDelimiter);
       
   510 
       
   511     TUint64 id = aUniqueId;
       
   512     aPathName.AppendNum(id, EHex);
       
   513     aPathName.Append(KPathDelimiter);
       
   514 }
       
   515 
       
   516 TBool CMidp2BackupPlugin::NextIcon(TUid& aCurrentUid, HBufC*& aFullFileName)
       
   517 {
       
   518     LOG(EBackup, EInfo, "CMidp2BackupPlugin::NextIcon()");
       
   519 
       
   520     if (iIconUidArray.Count() > iIconFilePointer)
       
   521     {
       
   522         aCurrentUid = iIconUidArray[iIconFilePointer];
       
   523         iAppArcUtil->GetIconFilename(iIconUidArray[iIconFilePointer], aFullFileName);
       
   524         iIconFilePointer++;
       
   525         return ETrue;
       
   526     }
       
   527     else
       
   528     {
       
   529         // There are no more icon files
       
   530         return EFalse;
       
   531     }
       
   532 }
       
   533 
       
   534 void CMidp2BackupPlugin::ProcessFirstBufferL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   535 {
       
   536     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessFirstBuffer()");
       
   537 
       
   538     if (iDrive >= EDriveE && iDrive <= EDriveZ)
       
   539     {
       
   540         // Read MMC id and restore MMC entries if needed
       
   541         iBackupMmc = aStream.ReadUint32L();
       
   542         aBufferSpaceLeft -= sizeof(iBackupMmc);
       
   543         LOG1(EBackup, EInfo, "Read MMC Id: %u", iBackupMmc);
       
   544         RestoreMmcRegistryL();
       
   545     }
       
   546     if (aBufferSpaceLeft >= sizeof(TInt32))
       
   547     {
       
   548         iIconFileSizeLeft = aStream.ReadInt32L();
       
   549         aBufferSpaceLeft -= sizeof(iIconFileSizeLeft);
       
   550         iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   551         iRestoreState = EInIcon;
       
   552     }
       
   553     else
       
   554     {
       
   555         // No more data to read
       
   556         aBufferSpaceLeft = 0;
       
   557     }
       
   558 }
       
   559 
       
   560 void CMidp2BackupPlugin::ProcessInIconL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   561 {
       
   562     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInIcon()");
       
   563 
       
   564     TPtr8 restoreIconPtr = iRestoreIconDesc->Des();
       
   565     HBufC8* tempDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   566     CleanupStack::PushL(tempDesc);
       
   567     TPtr8 tempPtr = tempDesc->Des();
       
   568 
       
   569     // Icon cannot be read fully
       
   570     if (iIconFileSizeLeft > aBufferSpaceLeft)
       
   571     {
       
   572         aStream.ReadL(tempPtr, aBufferSpaceLeft);
       
   573         restoreIconPtr.Append(tempPtr);
       
   574         iIconFileSizeLeft -= aBufferSpaceLeft;
       
   575         aBufferSpaceLeft = 0;
       
   576         iRestoreState = EInIcon;
       
   577     }
       
   578     // Icon can be read fully
       
   579     else
       
   580     {
       
   581         aStream.ReadL(tempPtr, iIconFileSizeLeft);
       
   582         restoreIconPtr.Append(tempPtr);
       
   583         aBufferSpaceLeft -= iIconFileSizeLeft;
       
   584         iRestoreState = EInSize;
       
   585 
       
   586         TRAPD(err, iAppArcUtil->RegisterAppL(restoreIconPtr, iDrive));
       
   587 
       
   588         if (err)
       
   589         {
       
   590             ELOG(EBackup, "Registerin application to AppArc failed.");
       
   591         }
       
   592     }
       
   593 
       
   594     CleanupStack::PopAndDestroy(tempDesc);
       
   595 }
       
   596 
       
   597 void CMidp2BackupPlugin::ProcessInSizeL(RDesReadStream& aStream, TInt& aBufferSpaceLeft)
       
   598 {
       
   599     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ProcessInSize()");
       
   600 
       
   601     if (aBufferSpaceLeft >= sizeof(TInt32))
       
   602     {
       
   603         if (iSizeBuffer.Size() != 0)
       
   604         {
       
   605             // Read leftover part of size
       
   606             TInt readData = sizeof(TInt32) - iSizeBuffer.Size();
       
   607             aStream.ReadL(iSizeBuffer, readData);
       
   608             RMemReadStream sizeStream(iSizeBuffer.Ptr(), 4);
       
   609             CleanupClosePushL(sizeStream);
       
   610             iIconFileSizeLeft = sizeStream.ReadInt32L();
       
   611             CleanupStack::PopAndDestroy(&sizeStream);
       
   612             aBufferSpaceLeft -= sizeof(readData);
       
   613         }
       
   614         else
       
   615         {
       
   616             // Read size in full
       
   617             iIconFileSizeLeft = aStream.ReadInt32L();
       
   618             aBufferSpaceLeft -= sizeof(iIconFileSizeLeft);
       
   619         }
       
   620 
       
   621         delete iRestoreIconDesc;
       
   622         iRestoreIconDesc = NULL;
       
   623         iRestoreIconDesc = HBufC8::NewL(iIconFileSizeLeft);
       
   624         iRestoreState = EInIcon;
       
   625     }
       
   626     else
       
   627     {
       
   628         // Read first byte(s) of size
       
   629         aStream.ReadL(iSizeBuffer, aBufferSpaceLeft);
       
   630         aBufferSpaceLeft = 0;
       
   631     }
       
   632 }
       
   633 
       
   634 void CMidp2BackupPlugin::ResetIconArray()
       
   635 {
       
   636     LOG(EBackup, EInfo, "CMidp2BackupPlugin::ResetIconArray()");
       
   637 
       
   638     // Remove all entries
       
   639     while (iIconUidArray.Count())
       
   640     {
       
   641         iIconUidArray.Remove(0);
       
   642     }
       
   643 }