coreapplicationuis/rfsplugins/FormatterRFSPlugin/src/formatterrfsplugin.cpp
branchRCL_3
changeset 10 469fa8a78de7
parent 7 fc3225a0ab43
equal deleted inserted replaced
9:332e7bf3b42f 10:469fa8a78de7
    17 
    17 
    18 
    18 
    19 // SYSTEM INCLUDE
    19 // SYSTEM INCLUDE
    20 #include <centralrepository.h>
    20 #include <centralrepository.h>
    21 #include <driveinfo.h>
    21 #include <driveinfo.h>
    22 #include <swi/sisregistrysession.h>
    22 
    23 #include <swi/sisregistryentry.h>
       
    24 #include <swi/sisregistrypackage.h>
       
    25 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    26 #include <starterdomaincrkeys.h>
    23 #include <starterdomaincrkeys.h>
       
    24 
    27 // USER INCLUDE
    25 // USER INCLUDE
    28 #include "formatterrfsplugin.h"
    26 #include "formatterrfsplugin.h"
    29 #include "formatterrfspluginprivatecrkeys.h"
    27 #include "formatterrfspluginprivatecrkeys.h"
    30 #include "formatterrfsplugincommon.h"
    28 #include "formatterrfsplugincommon.h"
    31 #include "trace.h"
    29 #include "trace.h"
    37 _LIT(KPathDelimeter, "\\");
    35 _LIT(KPathDelimeter, "\\");
    38 
    36 
    39 
    37 
    40 // ================= LOCAL FUNCTIONS =======================
    38 // ================= LOCAL FUNCTIONS =======================
    41 
    39 
    42 // ---------------------------------------------------------------------------
       
    43 // ExcludeListNameL
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 static void FileWriteL(RPointerArray<HBufC> &files)
       
    47     {
       
    48     RFs fileSession;
       
    49     RFile file;
       
    50     User::LeaveIfError(fileSession.Connect());
       
    51     TInt err = file.Open(fileSession,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite|EFileStreamText);
       
    52         
       
    53     if ( err != KErrNone )
       
    54         {
       
    55         RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL , FileWrite : Failed to open the file"));
       
    56         return;
       
    57         }
       
    58 
       
    59     TInt pos = 0;
       
    60     file.Seek(ESeekEnd,pos);
       
    61     TInt size = files.Count();
       
    62     RBuf filenameBuf;
       
    63 
       
    64     for ( TInt i=0; i < size; i++)
       
    65         {
       
    66         HBufC8* fileName = HBufC8::NewLC(files[i]->Size());
       
    67         TPtr8 fileNamePtr(fileName->Des());
       
    68         fileNamePtr.Copy(*files[i]);
       
    69 
       
    70         filenameBuf.Create(fileNamePtr.Length());
       
    71         filenameBuf.Copy(fileNamePtr);
       
    72         TFileText fileText ;
       
    73         fileText.Set(file) ;
       
    74         fileText.Seek(ESeekStart);
       
    75         fileText.Write(filenameBuf);
       
    76         CleanupStack::PopAndDestroy();//Filename
       
    77         file.Flush();
       
    78         }
       
    79 
       
    80     file.Close();
       
    81     fileSession.Close();    
       
    82     }
       
    83 
       
    84 static void MergeFilesL()
       
    85     {
       
    86     
       
    87     RFs fileSession;
       
    88     RFile excludeFileName;
       
    89     
       
    90     User::LeaveIfError(fileSession.Connect());
       
    91     TInt ret = excludeFileName.Open(fileSession,_L("c:\\private\\100059C9\\excludelist.txt"),EFileRead);
       
    92 
       
    93 		if(ret != KErrNone)
       
    94 			{
       
    95 			RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL , MergeFiles : Failed to open the file"));
       
    96 			return;
       
    97 			}
       
    98     excludeFileName.Close();
       
    99 
       
   100     CFileMan* fileMan=CFileMan::NewL(fileSession);
       
   101     CleanupStack::PushL(fileMan);
       
   102  
       
   103     TInt result=fileMan->Copy(_L("c:\\private\\100059C9\\excludelist.txt"),_L("c:\\private\\100059C9\\excludelistcache.txt"),CFileMan::EOverWrite);
       
   104 		RDebug::Print(_L("CFormatterRFSPlugin::MergeFilesL copying the excludelist.txt to excludelistcache.txt , CFileMan::Copy returned = %d"), result);   
       
   105     CleanupStack::PopAndDestroy(fileMan);
       
   106 
       
   107     fileSession.Close();
       
   108     }
       
   109 
    40 
   110 static HBufC* ExcludeListNameL( TChar aSystemDrive )
    41 static HBufC* ExcludeListNameL( TChar aSystemDrive )
   111     {
    42     {
   112     FUNC_LOG;
    43     FUNC_LOG;
   113 		
    44 		
   114     RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL"));
    45     HBufC* buf = HBufC::NewLC( KExcludeList().Length() + KExcludeListPathNameLenExt );
   115     
    46     TPtr bufPtr = buf->Des();
   116     RFs fileSession;
    47     bufPtr.Append( aSystemDrive );
   117     RFile file;
    48     bufPtr.Append( KDriveDelimiter );
   118     
    49     bufPtr.Append( KExcludeList );
   119     _LIT8(KFileName, "c:\\private\\100059C9\\excludelistcache.txt\n");
    50     CleanupStack::Pop( buf );
   120     TBuf8 <50> fileName;
       
   121     fileName.Copy(KFileName);
       
   122 
       
   123     User::LeaveIfError(fileSession.Connect());
       
   124     
       
   125     RDir dir;
       
   126     if(dir.Open(fileSession,_L("c:\\private\\100059C9\\"),KEntryAttNormal) != KErrNone)
       
   127         {
       
   128         User::LeaveIfError(fileSession.MkDir(_L("c:\\private\\100059C9\\")));
       
   129         }
       
   130     
       
   131     TInt rev = file.Replace(fileSession,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite|EFileStreamText);
       
   132     
       
   133     RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL, Replace returned %d"),rev);
       
   134     
       
   135     file.Flush();
       
   136     file.Close();
       
   137     dir.Close();
       
   138     fileSession.Close();
       
   139 
       
   140     Swi::RSisRegistrySession session;
       
   141     CleanupClosePushL(session);
       
   142     User::LeaveIfError(session.Connect());
       
   143     
       
   144     // Get the installed application UIDs
       
   145     RArray<TUid> uids;
       
   146     CleanupClosePushL(uids);
       
   147     session.InstalledUidsL(uids);
       
   148     TInt uidcount = uids.Count(); 
       
   149     
       
   150     Swi::RSisRegistryEntry entry;
       
   151     Swi::RSisRegistryEntry entry2;
       
   152     CleanupClosePushL(entry);
       
   153     CleanupClosePushL(entry2);
       
   154     
       
   155     RPointerArray<HBufC> registryFiles;
       
   156     RPointerArray<HBufC> augmentedRegistryFiles;
       
   157     RPointerArray<HBufC> nonRemovableFiles;
       
   158     RPointerArray<HBufC> nonRemovableAugmentedFiles;
       
   159     CleanupResetAndDestroyPushL(registryFiles);
       
   160     CleanupResetAndDestroyPushL(augmentedRegistryFiles);
       
   161     CleanupResetAndDestroyPushL(nonRemovableFiles);
       
   162     CleanupResetAndDestroyPushL(nonRemovableAugmentedFiles);
       
   163     
       
   164      TInt count;
       
   165      RPointerArray<Swi::CSisRegistryPackage> augmentationPackages;
       
   166      CleanupResetAndDestroyPushL(augmentationPackages);
       
   167      for ( TInt iter=0; iter<uidcount; iter++)
       
   168          {
       
   169          User::LeaveIfError(entry.Open(session,uids[iter]));
       
   170          if(EFalse == entry.RemovableL())
       
   171              {
       
   172              entry.FilesL(nonRemovableFiles);
       
   173              entry.RegistryFilesL(registryFiles);
       
   174              TInt fileCount = nonRemovableFiles.Count(); 
       
   175              for (TInt z=fileCount-1; z>=0;z--)
       
   176                  {
       
   177                  TPtr firstChar(nonRemovableFiles[z]->Des());
       
   178                  if(firstChar.Mid(0,1) == _L("z"))
       
   179                      {
       
   180                      delete nonRemovableFiles[z];
       
   181                      nonRemovableFiles.Remove(z);
       
   182                      }
       
   183                  }
       
   184              // Look for augmentations.
       
   185              if(entry.IsAugmentationL())
       
   186                  {
       
   187                  entry.AugmentationsL(augmentationPackages);
       
   188                  count = entry.AugmentationsNumberL();
       
   189                  for (TInt i=0; i < count; ++i)
       
   190                      {
       
   191                      User::LeaveIfError(entry2.OpenL(session,*augmentationPackages[i]));
       
   192                      if(EFalse == entry2.RemovableL())
       
   193                          {
       
   194                          entry2.FilesL(nonRemovableAugmentedFiles);
       
   195                          entry2.RegistryFilesL(augmentedRegistryFiles);
       
   196                          for (TInt c=0; c<nonRemovableAugmentedFiles.Count();c++)
       
   197                                {
       
   198                                TPtr firstChar(nonRemovableAugmentedFiles[c]->Des());
       
   199                                if(firstChar.Mid(0,1) == _L("z"))
       
   200                                    {
       
   201                                    delete nonRemovableAugmentedFiles[c];
       
   202                                    nonRemovableAugmentedFiles.Remove(c);
       
   203                                    }
       
   204                                }
       
   205 											}
       
   206                      	entry2.Close();
       
   207                      	}
       
   208                  }
       
   209              }
       
   210          entry.Close();
       
   211          }
       
   212      RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL Writing the file names to the excludelist.txt"));
       
   213  
       
   214      MergeFilesL();
       
   215 		 FileWriteL(nonRemovableAugmentedFiles);
       
   216 		 FileWriteL(augmentedRegistryFiles);
       
   217 		 FileWriteL(nonRemovableFiles);
       
   218  		 FileWriteL(registryFiles);
       
   219 
       
   220      TInt pos = 0;
       
   221      User::LeaveIfError(fileSession.Connect());
       
   222      User::LeaveIfError(file.Open(fileSession,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite|EFileStreamText));
       
   223           
       
   224      file.Seek(ESeekEnd,pos);
       
   225 
       
   226      TBuf<KMaxFileName> configurationLine ;
       
   227      TFileText fileText ;
       
   228      fileText.Set(file) ;
       
   229      fileText.Seek(ESeekStart);
       
   230      configurationLine.Format(_L("c:\\private\\100059C9\\excludelistcache.txt")) ;
       
   231      fileText.Write(configurationLine);
       
   232      
       
   233      file.Flush();
       
   234      file.Close();
       
   235      fileSession.Close();
       
   236     
       
   237      
       
   238      CleanupStack::PopAndDestroy(9,&session);
       
   239 
       
   240      HBufC* buf = HBufC::NewLC( KExcludeListcache().Length() + KExcludeListPathNameLenExt );
       
   241      TPtr bufPtr = buf->Des();
       
   242      bufPtr.Append( aSystemDrive );
       
   243      bufPtr.Append( KDriveDelimiter );
       
   244      bufPtr.Append( KExcludeListcache );
       
   245      CleanupStack::Pop( buf );
       
   246     return buf;
    51     return buf;
   247     }
    52     }
   248 
    53 
   249 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
   250 // CheckFileExist
    55 // CheckFileExist