backupandrestore/backupengine/src/sbebufferhandler.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    19  @file
    19  @file
    20 */
    20 */
    21 
    21 
    22 
    22 
    23 #include "sbebufferhandler.h"
    23 #include "sbebufferhandler.h"
    24 #include "sblog.h"
       
    25 #include "sbepanic.h"
    24 #include "sbepanic.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #include "sbtrace.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "sbebufferhandlerTraces.h"
       
    29 #endif
    26 
    30 
    27 namespace conn
    31 namespace conn
    28 	{
    32 	{
    29 	template<class T>
    33 	template<class T>
    30 	TBool ReadFromBufferF(T& aT, TUint8*& appCurrent, const TUint8* apEnd)
    34 	TBool ReadFromBufferF(T& aT, TUint8*& appCurrent, const TUint8* apEnd)
    34 	@param appCurrent The current point into the buffer.
    38 	@param appCurrent The current point into the buffer.
    35 	@param apEnd The end of the buffer.
    39 	@param apEnd The end of the buffer.
    36 	@return ETrue if read succesfully. EFalse if a retry is needed.
    40 	@return ETrue if read succesfully. EFalse if a retry is needed.
    37 	*/
    41 	*/
    38 		{
    42 		{
       
    43 		OstTraceFunctionEntry0( _CONN_READFROMBUFFERF_ENTRY );
    39 		static TBuf8<sizeof(T)> SBuffer; // Static buffer used for buffering!
    44 		static TBuf8<sizeof(T)> SBuffer; // Static buffer used for buffering!
    40 		TBool ret = EFalse;
    45 		TBool ret = EFalse;
    41 		
    46 		
    42 		// Is there anything already in the buffer?
    47 		// Is there anything already in the buffer?
    43 		TUint8* ptr = NULL;
    48 		TUint8* ptr = NULL;
    77 				} // for
    82 				} // for
    78 			
    83 			
    79 			SBuffer.SetLength(0);
    84 			SBuffer.SetLength(0);
    80 			}
    85 			}
    81 			
    86 			
       
    87 		OstTraceFunctionExit0( _CONN_READFROMBUFFERF_EXIT );
    82 		return ret;
    88 		return ret;
    83 		}
    89 		}
    84 
    90 
    85 	template TBool ReadFromBufferF<TFileFixedHeader>(TFileFixedHeader&, TUint8*&, const TUint8*);
    91 	template TBool ReadFromBufferF<TFileFixedHeader>(TFileFixedHeader&, TUint8*&, const TUint8*);
    86 	template TBool ReadFromBufferF<TSnapshot>(TSnapshot&, TUint8*&, const TUint8*);
    92 	template TBool ReadFromBufferF<TSnapshot>(TSnapshot&, TUint8*&, const TUint8*);
    94 	@param aT The flat structure to write to the buffer.
   100 	@param aT The flat structure to write to the buffer.
    95 	@param ptr The buffer to write to.
   101 	@param ptr The buffer to write to.
    96 	@return ETrue on success. EFalse on failure.
   102 	@return ETrue on success. EFalse on failure.
    97 	*/
   103 	*/
    98 		{
   104 		{
       
   105 		OstTraceFunctionEntry0( _CONN_WRITETOBUFFERF_ENTRY );
    99 		TBool ret = EFalse;
   106 		TBool ret = EFalse;
   100 		
   107 		
   101 		if ((aPtr.MaxSize() - aPtr.Size()) >= static_cast<TInt>(sizeof(T)))
   108 		if ((aPtr.MaxSize() - aPtr.Size()) >= static_cast<TInt>(sizeof(T)))
   102 			{
   109 			{
   103 			aPtr.Append(reinterpret_cast<TUint8*>(&aT), sizeof(T));
   110 			aPtr.Append(reinterpret_cast<TUint8*>(&aT), sizeof(T));
   104 			ret = ETrue;
   111 			ret = ETrue;
   105 			} // if
   112 			} // if
   106 		
   113 		
       
   114 		OstTraceFunctionExit0( _CONN_WRITETOBUFFERF_EXIT );
   107 		return ret;
   115 		return ret;
   108 		}
   116 		}
   109 		
   117 		
   110 	TBool ReadFromBufferV(TPtr8& aT, TInt aSize, TUint8*& appCurrent, const TUint8* apEnd)
   118 	TBool ReadFromBufferV(TPtr8& aT, TInt aSize, TUint8*& appCurrent, const TUint8* apEnd)
   111 	/** Reads from the buffer.
   119 	/** Reads from the buffer.
   115 	@param appCurrent Pointer to read from.
   123 	@param appCurrent Pointer to read from.
   116 	@param apEnd the end of the data.
   124 	@param apEnd the end of the data.
   117 	@return ETrue on success. EFalse on failure.
   125 	@return ETrue on success. EFalse on failure.
   118 	*/
   126 	*/
   119 		{
   127 		{
       
   128 		OstTraceFunctionEntry0( _CONN_READFROMBUFFERV_ENTRY );
   120 		TBool ret = EFalse;
   129 		TBool ret = EFalse;
   121 		
   130 		
   122 		// Does into already contain data?
   131 		// Does into already contain data?
   123 		if (aT.Size() > 0)
   132 		if (aT.Size() > 0)
   124 			{
   133 			{
   141 				appCurrent += aSize;
   150 				appCurrent += aSize;
   142 				ret = ETrue;
   151 				ret = ETrue;
   143 				} // else
   152 				} // else
   144 			} // else
   153 			} // else
   145 		
   154 		
       
   155 		OstTraceFunctionExit0( _CONN_READFROMBUFFERV_EXIT );
   146 		return ret;
   156 		return ret;
   147 		}
   157 		}
   148 		
   158 		
   149 	TBool WriteToBufferV(const TPtr8& aPtr, TInt aSize, TPtr8& aBuffer)
   159 	TBool WriteToBufferV(const TPtr8& aPtr, TInt aSize, TPtr8& aBuffer)
   150 	/** Writes some vairable data to the buffer.
   160 	/** Writes some vairable data to the buffer.
   155 	@param aSize size of the data to write.
   165 	@param aSize size of the data to write.
   156 	@param aBuffer the buffer to write to.
   166 	@param aBuffer the buffer to write to.
   157 	@return ETrue on success. EFalse on failure.
   167 	@return ETrue on success. EFalse on failure.
   158 	*/
   168 	*/
   159 		{
   169 		{
       
   170 		OstTraceFunctionEntry0( _CONN_WRITETOBUFFERV_ENTRY );
   160 		TBool ret = EFalse;
   171 		TBool ret = EFalse;
   161 		
   172 		
   162 		if ((aBuffer.MaxSize() - aBuffer.Size()) >= aSize)
   173 		if ((aBuffer.MaxSize() - aBuffer.Size()) >= aSize)
   163 			{
   174 			{
   164 			aBuffer.Append(aPtr.Ptr(), aSize);
   175 			aBuffer.Append(aPtr.Ptr(), aSize);
   165 			ret = ETrue;
   176 			ret = ETrue;
   166 			} // if
   177 			} // if
   167 		
   178 		
   168 		
   179 		
       
   180 		OstTraceFunctionExit0( _CONN_WRITETOBUFFERV_EXIT );
   169 		return ret;
   181 		return ret;
   170 		}
   182 		}
   171 		
   183 		
   172 	CBufferFileWriter* CBufferFileWriter::NewL(RFs& aFs, CDesCArray* aFileNames)
   184 	CBufferFileWriter* CBufferFileWriter::NewL(RFs& aFs, CDesCArray* aFileNames)
   173 	/** Symbain constructor
   185 	/** Symbain constructor
   175 	@param aFs Handle to the Symbian Fs file server
   187 	@param aFs Handle to the Symbian Fs file server
   176 	@param aFileNames list of files to write ownership transfer
   188 	@param aFileNames list of files to write ownership transfer
   177 	@return a CBufferFileWriter.
   189 	@return a CBufferFileWriter.
   178 	*/
   190 	*/
   179 		{
   191 		{
       
   192 		OstTraceFunctionEntry0( CBUFFERFILEWRITER_NEWL_ENTRY );
   180 		CBufferFileWriter* self = new(ELeave) CBufferFileWriter(aFs, aFileNames);
   193 		CBufferFileWriter* self = new(ELeave) CBufferFileWriter(aFs, aFileNames);
   181 		CleanupStack::PushL(self);
   194 		CleanupStack::PushL(self);
   182 		self->ConstructL();
   195 		self->ConstructL();
   183 		CleanupStack::Pop(self);
   196 		CleanupStack::Pop(self);
   184 		
   197 		
       
   198 		OstTraceFunctionExit0( CBUFFERFILEWRITER_NEWL_EXIT );
   185 		return self;
   199 		return self;
   186 		} // NewL
   200 		} // NewL
   187 		
   201 		
   188 	CBufferFileWriter::CBufferFileWriter(RFs& aFs, CDesCArray* aFileNames) :
   202 	CBufferFileWriter::CBufferFileWriter(RFs& aFs, CDesCArray* aFileNames) :
   189 		iFs(aFs), iFileNames(aFileNames)
   203 		iFs(aFs), iFileNames(aFileNames)
   190 	/** Standard C++ constructor
   204 	/** Standard C++ constructor
   191 	
   205 	
   192 	@param aFs an RFS to use in this class.
   206 	@param aFs an RFS to use in this class.
   193 	*/
   207 	*/
   194 		{
   208 		{
       
   209 		OstTraceFunctionEntry0( CBUFFERFILEWRITER_CBUFFERFILEWRITER_CONS_ENTRY );
       
   210 		OstTraceFunctionExit0( CBUFFERFILEWRITER_CBUFFERFILEWRITER_CONS_EXIT );
   195 		} // CBufferFileWriter
   211 		} // CBufferFileWriter
   196 		
   212 		
   197 	CBufferFileWriter::~CBufferFileWriter()
   213 	CBufferFileWriter::~CBufferFileWriter()
   198 	/** Standard C++ destructor
   214 	/** Standard C++ destructor
   199 	*/
   215 	*/
   200 		{
   216 		{
       
   217 		OstTraceFunctionEntry0( CBUFFERFILEWRITER_CBUFFERFILEWRITER_DES_ENTRY );
   201 		delete iFileNames;
   218 		delete iFileNames;
   202 		iFileHandle.Close();
   219 		iFileHandle.Close();
       
   220 		OstTraceFunctionExit0( CBUFFERFILEWRITER_CBUFFERFILEWRITER_DES_EXIT );
   203 		}
   221 		}
   204 		
   222 		
   205 	void CBufferFileWriter::ConstructL()
   223 	void CBufferFileWriter::ConstructL()
   206 	/** Symbain second phase constructor
   224 	/** Symbain second phase constructor
   207 	
   225 	
   208 	@param aFileNames list of files to write
   226 	@param aFileNames list of files to write
   209 	*/
   227 	*/
   210 		{
   228 		{
   211 		#if defined(SBE_LOGGING_ENABLED)
   229 		OstTraceFunctionEntry0( CBUFFERFILEWRITER_CONSTRUCTL_ENTRY );
   212 		if (iFileNames)
   230 		if (iFileNames)
   213 			{
   231 			{
   214 			TUint count = iFileNames->Count();
   232 			TUint count = iFileNames->Count();
   215 			while(count--)
   233 			while(count--)
   216 				{
   234 				{
   217 				const TDesC& fileName = (*iFileNames)[count];
   235 				const TDesC& fileName = (*iFileNames)[count];
   218             	__LOG2("CBufferFileWriter::ConstructL() - file[%04d] is: %S", count, &fileName);
   236 				OstTraceExt2(TRACE_NORMAL, CBUFFERFILEWRITER_CONSTRUCTL, "file[%04d] is: %S", static_cast<TInt32>(count), fileName);
   219 				}
   237 				}
   220 			}
   238 			}
   221 		
   239 		
   222 		#endif
   240 		OstTraceFunctionExit0( CBUFFERFILEWRITER_CONSTRUCTL_EXIT );
   223 		}
   241 		}
   224 		
   242 		
   225 	void CBufferFileWriter::StartL(TPtr8& aBuffer, TBool& aCompleted)
   243 	void CBufferFileWriter::StartL(TPtr8& aBuffer, TBool& aCompleted)
   226 	/** Start writing the files to the buffer
   244 	/** Start writing the files to the buffer
   227 	
   245 	
   228 	@param aBuffer The buffer to write to.
   246 	@param aBuffer The buffer to write to.
   229 	@param aCompleted on return if we have finished.
   247 	@param aCompleted on return if we have finished.
   230 	*/
   248 	*/
   231 		{
   249 		{
   232         __LOG("CBufferFileWriter::StartL() - START");
   250         OstTraceFunctionEntry0( CBUFFERFILEWRITER_STARTL_ENTRY );        
   233 		WriteToBufferL(aBuffer, aCompleted);
   251 		WriteToBufferL(aBuffer, aCompleted);        
   234         __LOG("CBufferFileWriter::StartL() - END");
   252 		OstTraceFunctionExit0( CBUFFERFILEWRITER_STARTL_EXIT );
   235 		} // StartL
   253 		} // StartL
   236 		
   254 		
   237 	void CBufferFileWriter::ContinueL(TPtr8& aBuffer, TBool& aCompleted)
   255 	void CBufferFileWriter::ContinueL(TPtr8& aBuffer, TBool& aCompleted)
   238 	/** Continue writing the files to the buffer
   256 	/** Continue writing the files to the buffer
   239 	
   257 	
   240 	@param aBuffer The buffer to write to.
   258 	@param aBuffer The buffer to write to.
   241 	@param aCompleted on return if we have finished.
   259 	@param aCompleted on return if we have finished.
   242 	*/
   260 	*/
   243 		{
   261 		{
   244         __LOG("CBufferFileWriter::ContinueL() - START");
   262         OstTraceFunctionEntry0( CBUFFERFILEWRITER_CONTINUEL_ENTRY );        
   245 		WriteToBufferL(aBuffer, aCompleted);
   263 		WriteToBufferL(aBuffer, aCompleted);        
   246         __LOG("CBufferFileWriter::ContinueL() - END");
   264 		OstTraceFunctionExit0( CBUFFERFILEWRITER_CONTINUEL_EXIT );
   247 		}
   265 		}
   248 
   266 
   249 	void CBufferFileWriter::WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted)
   267 	void CBufferFileWriter::WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted)
   250 	/** Writes files to the buffer
   268 	/** Writes files to the buffer
   251 	
   269 	
   252 	@param aBuffer The buffer to write to.
   270 	@param aBuffer The buffer to write to.
   253 	@param aCompleted on return if we have finished.
   271 	@param aCompleted on return if we have finished.
   254 	*/
   272 	*/
   255 		{
   273 		{
       
   274 		OstTraceFunctionEntry0( CBUFFERFILEWRITER_WRITETOBUFFERL_ENTRY );
   256 		aCompleted = EFalse;
   275 		aCompleted = EFalse;
   257 		
   276 		
   258 		const TUint count = iFileNames->Count();
   277 		const TUint count = iFileNames->Count();
   259 		while (iCurrentFile < count)
   278 		while (iCurrentFile < count)
   260 			{
   279 			{
   262 			
   281 			
   263 			_LIT( KTrailingBackSlash, "\\" );
   282 			_LIT( KTrailingBackSlash, "\\" );
   264             if (name.Right(1) == KTrailingBackSlash() )
   283             if (name.Right(1) == KTrailingBackSlash() )
   265             	{
   284             	{
   266              	// Directory entry
   285              	// Directory entry
   267  	           	__LOG1("CBufferFileWriter::WriteToBufferL() - empty directory: %S ", &name);
   286                 OstTraceExt1(TRACE_NORMAL, CBUFFERFILEWRITER_WRITETOBUFFERL, "empty directory: %S ", name);
   268  	           	if(!iHeaderWritten)
   287  	           	if(!iHeaderWritten)
   269  	        	   {
   288  	        	   {
   270  	        	   TFileFixedHeader header(name.Length(), 0, 0, 0);
   289  	        	   TFileFixedHeader header(name.Length(), 0, 0, 0);
   271  	        	   if (WriteToBufferF(header, aBuffer) == EFalse)
   290  	        	   if (WriteToBufferF(header, aBuffer) == EFalse)
   272  	        		   {
   291  	        		   {
   273  	        		   __LOG("CBufferFileReader::WriteToBufferL() - WriteToBufferF() returned False so breaking!");
   292  	        	       OstTrace0(TRACE_NORMAL, DUP1_CBUFFERFILEWRITER_WRITETOBUFFERL, "WriteToBufferF() returned False so breaking!");
   274  	        		   break;
   293  	        		   break;
   275  	        		   }
   294  	        		   }
   276  	        	   iHeaderWritten = ETrue;
   295  	        	   iHeaderWritten = ETrue;
   277  	        	   } // if
   296  	        	   } // if
   278  	           	
   297  	           	
   279 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(name.Ptr())), name.Size(), name.Size());
   298 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(name.Ptr())), name.Size(), name.Size());
   280 				
   299 				
   281 				if (WriteToBufferV(ptr, ptr.Size(), aBuffer) == EFalse)
   300 				if (WriteToBufferV(ptr, ptr.Size(), aBuffer) == EFalse)
   282 					{
   301 					{
   283 					__LOG("CBufferFileReader::WriteToBufferL() - WriteToBufferV() returned False so breaking!");
   302 				    OstTrace0(TRACE_NORMAL, DUP2_CBUFFERFILEWRITER_WRITETOBUFFERL, "WriteToBufferV() returned False so breaking!");
   284 					break;
   303 					break;
   285 					}
   304 					}
   286 
   305 
   287  	           	iHeaderWritten = EFalse;
   306  	           	iHeaderWritten = EFalse;
   288  	           	iFileNameWritten = EFalse;
   307  	           	iFileNameWritten = EFalse;
   289             	}
   308             	}
   290             else
   309             else
   291             	{
   310             	{
   292 				if (!iFileOpen) // File needs to be opened
   311 				if (!iFileOpen) // File needs to be opened
   293 					{
   312 					{
   294 	                __LOG1("CBufferFileWriter::WriteToBufferL() - trying to open: %S for reading", &name);
   313 				    OstTraceExt1(TRACE_NORMAL, DUP3_CBUFFERFILEWRITER_WRITETOBUFFERL, "trying to open: %S for reading", name);
   295 					const TInt error = iFileHandle.Open(iFs, name, EFileRead | EFileShareReadersOnly);
   314 					const TInt error = iFileHandle.Open(iFs, name, EFileRead | EFileShareReadersOnly);
   296 	                if  (error != KErrNone)
   315 	                if  (error != KErrNone)
   297 	                    {
   316 	                    {
   298 	                    __LOG2("CBufferFileWriter::WriteToBufferL() - opening: %S for reading failed with error: %d", &name, error);
   317 	                    OstTraceExt2(TRACE_ERROR, DUP4_CBUFFERFILEWRITER_WRITETOBUFFERL, "opening: %S for reading failed with error: %d", name, error);
   299 	                    User::Leave(error);
   318 	                    User::Leave(error);
   300 	                    }
   319 	                    }
   301 
   320 
   302 					iFileOpen = ETrue;
   321 					iFileOpen = ETrue;
   303 					} // if
   322 					} // if
   305 				if (iFileOpen && !iHeaderWritten)
   324 				if (iFileOpen && !iHeaderWritten)
   306 					{
   325 					{
   307 					// File size
   326 					// File size
   308 					TInt size;
   327 					TInt size;
   309 					TInt err = iFileHandle.Size(size);
   328 					TInt err = iFileHandle.Size(size);
   310 	                __LOG2("CBufferFileWriter::WriteToBufferL() - size of file is: %d (err: %d)", size, err);
   329 					OstTraceExt2(TRACE_NORMAL, DUP5_CBUFFERFILEWRITER_WRITETOBUFFERL, "size of file is: %d (err: %d)", size, err);
   311 					TUint att;
   330 					TUint att;
   312 					err = iFileHandle.Att(att);
   331 					err = iFileHandle.Att(att);
   313 					__LOG2("CBufferFileWriter::WriteToBufferL() - attributes: %d (err: %d)", size, err);
   332 					OstTraceExt2(TRACE_NORMAL, DUP6_CBUFFERFILEWRITER_WRITETOBUFFERL, "attributes: %d (err: %d)", att, err);
   314 					TTime modified;
   333 					TTime modified;
   315 					err = iFileHandle.Modified(modified);
   334 					err = iFileHandle.Modified(modified);					
   316 					__LOG2("CBufferFileWriter::WriteToBufferL() - modified: %d (err: %d)", size, err);
   335 					OstTraceExt4(TRACE_NORMAL, DUP7_CBUFFERFILEWRITER_WRITETOBUFFERL, "modified: %d-%d-%d (err: %d)", static_cast<TInt>(modified.DateTime().Year()), static_cast<TInt>(modified.DateTime().Month() + 1), static_cast<TInt>(modified.DateTime().Day()), err);
   317 					TFileFixedHeader header((*iFileNames)[iCurrentFile].Length(), size, att, modified.Int64());
   336 					TFileFixedHeader header((*iFileNames)[iCurrentFile].Length(), size, att, modified.Int64());
   318 					if (WriteToBufferF(header, aBuffer) == EFalse)
   337 					if (WriteToBufferF(header, aBuffer) == EFalse)
   319 						{
   338 						{
   320 						__LOG("CBufferFileReader::WriteToBufferL() - WriteToBufferF() returned False so breaking!");
   339 					    OstTrace0(TRACE_NORMAL, DUP8_CBUFFERFILEWRITER_WRITETOBUFFERL, "WriteToBufferF() returned False so breaking!");
   321 						break;
   340 						break;
   322 						}
   341 						}
   323 						
   342 						
   324 					iHeaderWritten = ETrue;
   343 					iHeaderWritten = ETrue;
   325 					} // if
   344 					} // if
   330 					
   349 					
   331 					TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(name.Ptr())), name.Size(), name.Size());
   350 					TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(name.Ptr())), name.Size(), name.Size());
   332 					
   351 					
   333 					if (WriteToBufferV(ptr, ptr.Size(), aBuffer) == EFalse)
   352 					if (WriteToBufferV(ptr, ptr.Size(), aBuffer) == EFalse)
   334 						{
   353 						{
   335 						__LOG("CBufferFileReader::WriteToBufferV() - WriteToBufferF() returned False so breaking!");
   354 					    OstTrace0(TRACE_NORMAL, DUP9_CBUFFERFILEWRITER_WRITETOBUFFERL, "WriteToBufferF() returned False so breaking!");
   336 						break;
   355 						break;
   337 						}
   356 						}
   338 					iFileNameWritten = ETrue;
   357 					iFileNameWritten = ETrue;
   339 					}
   358 					}
   340 
   359 
   341 	            __LOG1("CBufferFileWriter::WriteToBufferL() - buffer is of length: %d", aBuffer.Length());
   360 				OstTrace1(TRACE_NORMAL, DUP10_CBUFFERFILEWRITER_WRITETOBUFFERL, "buffer is of length: %d", aBuffer.Length());
   342 					
   361 					
   343 				TInt bufferLeft = aBuffer.MaxSize() - aBuffer.Size();
   362 				TInt bufferLeft = aBuffer.MaxSize() - aBuffer.Size();
   344 				TPtr8 ptr(const_cast<TUint8*>(aBuffer.Ptr()) + aBuffer.Size(), bufferLeft);
   363 				TPtr8 ptr(const_cast<TUint8*>(aBuffer.Ptr()) + aBuffer.Size(), bufferLeft);
   345 				TInt fileSize = 0;
   364 				TInt fileSize = 0;
   346 				iFileHandle.Size(fileSize);
   365 				iFileHandle.Size(fileSize);
   347 				TInt fileLeft = fileSize - iOffset;
   366 				TInt fileLeft = fileSize - iOffset;
   348 				if (bufferLeft < fileLeft)
   367 				if (bufferLeft < fileLeft)
   349 					{
   368 					{
   350 	                __LOG("CBufferFileWriter::WriteToBufferL() - buffer space available is less than file size!");
   369 				    OstTrace0(TRACE_NORMAL, DUP11_CBUFFERFILEWRITER_WRITETOBUFFERL, "buffer space available is less than file size!");
   351 
   370 
   352 	                // Write buffer size
   371 	                // Write buffer size
   353 					User::LeaveIfError(iFileHandle.Read(iOffset, ptr, bufferLeft)); // TODO: Is this correct?
   372 				    TInt err = iFileHandle.Read(iOffset, ptr, bufferLeft); // TODO: Is this correct?
       
   373 					LEAVEIFERROR(err, OstTrace1(TRACE_ERROR, DUP14_CBUFFERFILEWRITER_WRITETOBUFFERL, "Leave: %d", err));
   354 					aBuffer.SetLength(aBuffer.Length() + bufferLeft);
   374 					aBuffer.SetLength(aBuffer.Length() + bufferLeft);
   355 					iOffset += bufferLeft;
   375 					iOffset += bufferLeft;
   356 					break;
   376 					break;
   357 					} // if
   377 					} // if
   358 				else
   378 				else
   359 					{
   379 					{
   360 	                __LOG("CBufferFileWriter::WriteToBufferL() - enough space in buffer for whole file...");
   380 				    OstTrace0(TRACE_NORMAL, DUP12_CBUFFERFILEWRITER_WRITETOBUFFERL, "enough space in buffer for whole file...");
   361 
   381 
   362 	                // Write file size
   382 	                // Write file size
   363 					User::LeaveIfError(iFileHandle.Read(ptr, fileLeft)); // TODO: Is this correct?
   383 				    TInt err = iFileHandle.Read(ptr, fileLeft); // TODO: Is this correct?
       
   384 					LEAVEIFERROR(err, OstTrace1(TRACE_ERROR, DUP15_CBUFFERFILEWRITER_WRITETOBUFFERL, "Leave: %d", err));
   364 					aBuffer.SetLength(aBuffer.Length() + fileLeft);
   385 					aBuffer.SetLength(aBuffer.Length() + fileLeft);
   365 					} // else
   386 					} // else
   366 
   387 
   367 	            __LOG1("CBufferFileWriter::WriteToBufferL() - After read from file, buffer is now of length: %d", aBuffer.Length());
   388 				OstTrace1(TRACE_NORMAL, DUP13_CBUFFERFILEWRITER_WRITETOBUFFERL, "After read from file, buffer is now of length: %d", aBuffer.Length());
   368 	            
   389 	            
   369 				iFileHandle.Close();
   390 				iFileHandle.Close();
   370 				iFileOpen = EFalse;
   391 				iFileOpen = EFalse;
   371 				iHeaderWritten = EFalse;
   392 				iHeaderWritten = EFalse;
   372 				iFileNameWritten = EFalse;
   393 				iFileNameWritten = EFalse;
   377 			
   398 			
   378 		if (iCurrentFile >= count)
   399 		if (iCurrentFile >= count)
   379 			{
   400 			{
   380 			aCompleted = ETrue;
   401 			aCompleted = ETrue;
   381 			} // if
   402 			} // if
       
   403 		OstTraceFunctionExit0( CBUFFERFILEWRITER_WRITETOBUFFERL_EXIT );
   382 		} // WriteToBufferL
   404 		} // WriteToBufferL
   383 		
   405 		
   384 	CBufferFileReader* CBufferFileReader::NewL(RFs& aFs, RSnapshots* apSnapshots, MValidationHandler* aValidationHandler)
   406 	CBufferFileReader* CBufferFileReader::NewL(RFs& aFs, RSnapshots* apSnapshots, MValidationHandler* aValidationHandler)
   385 	/** Symbian OS constructor
   407 	/** Symbian OS constructor
   386 	
   408 	
   387 	@param aFs File server to use.
   409 	@param aFs File server to use.
   388 	@param apSnapshots list of snapshots.
   410 	@param apSnapshots list of snapshots.
   389 	*/
   411 	*/
   390 		{
   412 		{
   391         __LOG("CBufferFileReader::NewL() - START");
   413         OstTraceFunctionEntry0( CBUFFERFILEREADER_NEWL_ENTRY );        
   392 		CBufferFileReader* self = new(ELeave) CBufferFileReader(aFs, apSnapshots, aValidationHandler);
   414 		CBufferFileReader* self = new(ELeave) CBufferFileReader(aFs, apSnapshots, aValidationHandler);
   393 		
   415 		
   394 		CleanupStack::PushL( self );
   416 		CleanupStack::PushL( self );
   395 		
   417 		
   396 	#ifdef SBE_LOGGING_ENABLED
       
   397         if  (apSnapshots)
   418         if  (apSnapshots)
   398             {
   419             {
   399 		    const TInt count = apSnapshots->Count();
   420 		    const TInt count = apSnapshots->Count();
   400             __LOG1("CBufferFileReader::NewL() - Got %d snapshots to compare against during restore...", count);
   421 		    OstTrace1(TRACE_NORMAL, CBUFFERFILEREADER_NEWL, "Got %d snapshots to compare against during restore...", count);
   401 
   422 
   402 		    for(TInt x = 0; x < count; ++x)
   423 		    for(TInt x = 0; x < count; ++x)
   403 			    {
   424 			    {
   404                 const TDesC& snapshot = (*apSnapshots)[x]->FileName();
   425                 const TDesC& snapshot = (*apSnapshots)[x]->FileName();
   405                 __LOG3("CBufferFileReader::NewL() -    snapshot[%4d/%4d] is: %S", x+1, count, &snapshot);
   426                 OstTraceExt3(TRACE_NORMAL, DUP1_CBUFFERFILEREADER_NEWL, "snapshot[%4d/%4d] is: %S", x+1, count, snapshot);
   406 			    } // for x
   427 			    } // for x
   407 
   428 
   408 		    }
   429 		    }
   409 	#endif
       
   410         
       
   411         __LOG("CBufferFileReader::NewL() - END");
       
   412         
   430         
   413         CleanupStack::Pop( self );
   431         CleanupStack::Pop( self );
       
   432 		OstTraceFunctionExit0( CBUFFERFILEREADER_NEWL_EXIT );
   414 		return self;
   433 		return self;
   415 		} // NewL
   434 		} // NewL
   416 		
   435 		
   417 	CBufferFileReader::CBufferFileReader(RFs& aFs, RSnapshots* apSnapshots, MValidationHandler* aValidationHandler) :
   436 	CBufferFileReader::CBufferFileReader(RFs& aFs, RSnapshots* apSnapshots, MValidationHandler* aValidationHandler) :
   418 		iFs(aFs), iSnapshots(apSnapshots), iValidationHandler(aValidationHandler)
   437 		iFs(aFs), iSnapshots(apSnapshots), iValidationHandler(aValidationHandler)
   420 	
   439 	
   421 	@param aFs File server to use.
   440 	@param aFs File server to use.
   422 	@param apSnapshots list of snapshots.
   441 	@param apSnapshots list of snapshots.
   423 	*/
   442 	*/
   424 		{
   443 		{
       
   444 		OstTraceFunctionEntry0( CBUFFERFILEREADER_CBUFFERFILEREADER_CONS_ENTRY );
       
   445 		OstTraceFunctionExit0( CBUFFERFILEREADER_CBUFFERFILEREADER_CONS_EXIT );
   425 		} // CBufferFileReader
   446 		} // CBufferFileReader
   426 		
   447 		
   427 	void CBufferFileReader::StartL(const TDesC8& aBuffer, TBool aLastSection)
   448 	void CBufferFileReader::StartL(const TDesC8& aBuffer, TBool aLastSection)
   428 	/** Start reading from the buffer.
   449 	/** Start reading from the buffer.
   429 	
   450 	
   430 	@param aBuffer The buffer to read from.
   451 	@param aBuffer The buffer to read from.
   431 	@param aLastSection Is this the last section?
   452 	@param aLastSection Is this the last section?
   432 	*/
   453 	*/
   433 		{
   454 		{
   434         __LOG("CBufferFileReader::StartL() - START");
   455         OstTraceFunctionEntry0( CBUFFERFILEREADER_STARTL_ENTRY );        
   435         if (iSnapshots)
   456         if (iSnapshots)
   436         	{
   457         	{
   437         	iSnapshots->Sort(CSnapshot::Compare);
   458         	iSnapshots->Sort(CSnapshot::Compare);
   438         	}
   459         	}
   439 		ReadFromBufferL(aBuffer, aLastSection);
   460 		ReadFromBufferL(aBuffer, aLastSection);        
   440         __LOG("CBufferFileReader::StartL() - END");
   461 		OstTraceFunctionExit0( CBUFFERFILEREADER_STARTL_EXIT );
   441 		} // StartL
   462 		} // StartL
   442 	
   463 	
   443 	void CBufferFileReader::ContinueL(const TDesC8& aBuffer, TBool aLastSection)
   464 	void CBufferFileReader::ContinueL(const TDesC8& aBuffer, TBool aLastSection)
   444 	/** Continue reading from the buffer.
   465 	/** Continue reading from the buffer.
   445 	
   466 	
   446 	@param aBuffer The buffer to read from.
   467 	@param aBuffer The buffer to read from.
   447 	@param aLastSection Is this the last section?
   468 	@param aLastSection Is this the last section?
   448 	*/
   469 	*/
   449 		{
   470 		{
   450         __LOG("CBufferFileReader::ContinueL() - START");
   471         OstTraceFunctionEntry0( CBUFFERFILEREADER_CONTINUEL_ENTRY );        
   451 		ReadFromBufferL(aBuffer, aLastSection);
   472 		ReadFromBufferL(aBuffer, aLastSection);        
   452         __LOG("CBufferFileReader::ContinueL() - END");
   473 		OstTraceFunctionExit0( CBUFFERFILEREADER_CONTINUEL_EXIT );
   453 		} // ContinueL
   474 		} // ContinueL
   454 	
   475 	
   455 	void CBufferFileReader::CheckFileInSnapshotL()
   476 	void CBufferFileReader::CheckFileInSnapshotL()
   456 	/**
   477 	/**
   457 	Checks to see if a given file is in a snapshot.
   478 	Checks to see if a given file is in a snapshot.
   458 	*/
   479 	*/
   459 		{
   480 		{
   460         __LOG2("CBufferFileReader::CheckFileInSnapshot() - START - ipSnapshots: 0x%08x, iSnapshotChecked: %d", iSnapshots, iSnapshotChecked);
   481         OstTraceFunctionEntry0( CBUFFERFILEREADER_CHECKFILEINSNAPSHOTL_ENTRY );
       
   482         OstTraceExt2(TRACE_NORMAL, CBUFFERFILEREADER_CHECKFILEINSNAPSHOTL, "ipSnapshots: 0x%08x, iSnapshotChecked: %d", reinterpret_cast<TInt32>(iSnapshots), static_cast<TInt32>(iSnapshotChecked));
   461 
   483 
   462 		iRestore = ETrue;
   484 		iRestore = ETrue;
   463 		
   485 		
   464 		if (iSnapshots)
   486 		if (iSnapshots)
   465 			{
   487 			{
   472 			CleanupStack::PopAndDestroy(snapshot);		
   494 			CleanupStack::PopAndDestroy(snapshot);		
   473 			} // if
   495 			} // if
   474 		
   496 		
   475 		iSnapshotChecked = ETrue;
   497 		iSnapshotChecked = ETrue;
   476 
   498 
   477         __LOG2("CBufferFileReader::CheckFileInSnapshot() - END - iSnapshotChecked: %d, iRestore: %d", iSnapshotChecked, iRestore);
   499 		OstTraceExt2(TRACE_NORMAL, DUP1_CBUFFERFILEREADER_CHECKFILEINSNAPSHOTL, "iSnapshotChecked: %d, iRestore: %d", iSnapshotChecked, iRestore);
       
   500 		OstTraceFunctionExit0( CBUFFERFILEREADER_CHECKFILEINSNAPSHOTL_EXIT );
   478 		}
   501 		}
   479 		
   502 		
   480 	void CBufferFileReader::RecreateDirL()
   503 	void CBufferFileReader::RecreateDirL()
   481 	/**
   504 	/**
   482 	Recreates a directory path on disk.
   505 	Recreates a directory path on disk.
   483 	*/
   506 	*/
   484 		{
   507 		{
   485         __LOG1("CBufferFileReader::RecreateDirL() - START - iFileName: %S", &iFileName);
   508         OstTraceFunctionEntry0( CBUFFERFILEREADER_RECREATEDIRL_ENTRY );
       
   509         OstTraceExt1(TRACE_NORMAL, CBUFFERFILEREADER_RECREATEDIRL, "iFileName: %S", iFileName);
   486 		// Create the path
   510 		// Create the path
   487 		TInt err = iFs.MkDirAll(iFileName);
   511 		TInt err = iFs.MkDirAll(iFileName);
   488 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   512 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   489 			{
   513 			{
   490             __LOG1("CBufferFileReader::WriteToFile() - making directory resulted in fatal error: %d", err);
   514 		    OstTrace1(TRACE_ERROR, DUP1_CBUFFERFILEREADER_RECREATEDIRL, "making directory resulted in fatal error: %d", err);
   491 			User::Leave(err);
   515 			User::Leave(err);
   492 			} // if
   516 			} // if
   493         
   517         
   494         __LOG("CBufferFileReader::RecreateDirL() - END");
   518 		OstTraceFunctionExit0( CBUFFERFILEREADER_RECREATEDIRL_EXIT );
   495 		}
   519 		}
   496 		
   520 		
   497 	
   521 	
   498 	void CBufferFileReader::RecreateFileL()
   522 	void CBufferFileReader::RecreateFileL()
   499 	/**
   523 	/**
   500 	Recreates a file on disk. Deletes the original if it still exists.
   524 	Recreates a file on disk. Deletes the original if it still exists.
   501 	*/
   525 	*/
   502 		{
   526 		{
   503         __LOG1("CBufferFileReader::RecreateFileL() - START - iFileName: %S", &iFileName);
   527         OstTraceFunctionEntry0( CBUFFERFILEREADER_RECREATEFILEL_ENTRY );
       
   528         OstTraceExt1(TRACE_NORMAL, CBUFFERFILEREADER_RECREATEFILEL, "iFileName: %S", iFileName);
   504 		// Create the path
   529 		// Create the path
   505 		TInt err = iFs.MkDirAll(iFileName);
   530 		TInt err = iFs.MkDirAll(iFileName);
   506 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   531 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   507 			{
   532 			{
   508             __LOG1("CBufferFileReader::WriteToFile() - making directory resulted in fatal error: %d", err);
   533 		    OstTrace1(TRACE_ERROR, DUP1_CBUFFERFILEREADER_RECREATEFILEL, "making directory resulted in fatal error: %d", err);
   509 			User::Leave(err);
   534 			User::Leave(err);
   510 			} // if
   535 			} // if
   511 		
   536 		
   512 		TEntry entry;
   537 		TEntry entry;
   513 		TBool isReadOnly = EFalse;
   538 		TBool isReadOnly = EFalse;
   521 				iFs.SetAtt(iFileName, entry.iAtt, ~entry.iAtt);
   546 				iFs.SetAtt(iFileName, entry.iAtt, ~entry.iAtt);
   522 				}
   547 				}
   523 			}				
   548 			}				
   524 				
   549 				
   525         err = iFileHandle.Replace(iFs, iFileName, EFileWrite);
   550         err = iFileHandle.Replace(iFs, iFileName, EFileWrite);
   526         __LOG1("CBufferFileReader::WriteToFile() - replacing file returned err: %d", err);
   551         OstTrace1(TRACE_NORMAL, DUP2_CBUFFERFILEREADER_RECREATEFILEL, "CBufferFileReader::WriteToFile() - replacing file returned err: %d", err);
   527         User::LeaveIfError( err );
   552         LEAVEIFERROR( err, OstTrace1(TRACE_ERROR, DUP3_CBUFFERFILEREADER_RECREATEFILEL, "Leave: %d", err) );
   528         
   553         
   529         if(isReadOnly)
   554         if(isReadOnly)
   530         	{
   555         	{
   531 			entry.iAtt |= KEntryAttReadOnly;
   556 			entry.iAtt |= KEntryAttReadOnly;
   532         	iFs.SetAtt(iFileName, entry.iAtt, ~entry.iAtt);
   557         	iFs.SetAtt(iFileName, entry.iAtt, ~entry.iAtt);
   533         	}
   558         	}
   534 			
   559 			
   535 		iFileOpen = ETrue;
   560 		iFileOpen = ETrue;        
   536         __LOG("CBufferFileReader::RecreateFileL() - END");
   561 		OstTraceFunctionExit0( CBUFFERFILEREADER_RECREATEFILEL_EXIT );
   537 		}
   562 		}
   538 	
   563 	
   539 		
   564 		
   540 	TBool CBufferFileReader::WriteToFileL(TUint8*& aCurrent, const TUint8* aEnd)
   565 	TBool CBufferFileReader::WriteToFileL(TUint8*& aCurrent, const TUint8* aEnd)
   541 	/**
   566 	/**
   544 	@param aCurrent start point of data to write.
   569 	@param aCurrent start point of data to write.
   545 	@param aEnd end point of data to write.
   570 	@param aEnd end point of data to write.
   546 	@return ETrue if write finished. EFalse if there is more data to write.
   571 	@return ETrue if write finished. EFalse if there is more data to write.
   547 	*/
   572 	*/
   548 		{
   573 		{
   549         __LOG2("CBufferFileReader::WriteToFile() - START - iFileHandle: 0x%08x, iFixedHeader.iFileSize: %d", iFileHandle.SubSessionHandle(), iFixedHeader.iFileSize);
   574         OstTraceFunctionEntry0( CBUFFERFILEREADER_WRITETOFILEL_ENTRY );
       
   575         OstTraceExt2(TRACE_NORMAL, CBUFFERFILEREADER_WRITETOFILEL, "iFileHandle: 0x%08x, iFixedHeader.iFileSize: %d", iFileHandle.SubSessionHandle(), iFixedHeader.iFileSize);
   550 		TBool retVal = ETrue;
   576 		TBool retVal = ETrue;
   551 		TInt filesize;
   577 		TInt filesize;
   552 		const TInt err1 = iFileHandle.Size(filesize);
   578 		const TInt err1 = iFileHandle.Size(filesize);
   553         __LOG2("CBufferFileReader::WriteToFile() - fileSize: %d (err: %d)", filesize, err1);
   579 		OstTraceExt2(TRACE_NORMAL, DUP1_CBUFFERFILEREADER_WRITETOFILEL, "fileSize: %d (err: %d)", filesize, err1);
   554 		User::LeaveIfError(err1);
   580 		LEAVEIFERROR(err1, OstTrace1(TRACE_ERROR, DUP6_CBUFFERFILEREADER_WRITETOFILEL, "Leave: %d", err1));
   555 		if ((aEnd - aCurrent) >= (iFixedHeader.iFileSize - filesize))
   581 		if ((aEnd - aCurrent) >= (iFixedHeader.iFileSize - filesize))
   556 			{
   582 			{
   557 			TPtr8 ptr(aCurrent, iFixedHeader.iFileSize -filesize, iFixedHeader.iFileSize - filesize);
   583 			TPtr8 ptr(aCurrent, iFixedHeader.iFileSize -filesize, iFixedHeader.iFileSize - filesize);
   558 			const TInt err2 = iFileHandle.Write(ptr);
   584 			const TInt err2 = iFileHandle.Write(ptr);
   559             __LOG2("CBufferFileReader::WriteToFile() - writing %d bytes returned error: %d", ptr.Length(), err2);
   585 			OstTraceExt2(TRACE_NORMAL, DUP2_CBUFFERFILEREADER_WRITETOFILEL, "writing %d bytes returned error: %d", ptr.Length(), err2);
   560 			User::LeaveIfError(err2);
   586 			LEAVEIFERROR(err2, OstTrace1(TRACE_ERROR, DUP7_CBUFFERFILEREADER_WRITETOFILEL, "Leave: %d", err2));
   561 
   587 
   562 			// Write the attributes & modified time
   588 			// Write the attributes & modified time
   563 			const TInt err3 = iFileHandle.Set(iFixedHeader.iModified, 
   589 			const TInt err3 = iFileHandle.Set(iFixedHeader.iModified, 
   564 					iFixedHeader.iAttributes, KEntryAttNormal);
   590 					iFixedHeader.iAttributes, KEntryAttNormal);
   565 
   591 
   566             __LOG1("CBufferFileReader::WriteToFile() - setting attribs returned error: %d", err3);
   592 			OstTrace1(TRACE_NORMAL, DUP3_CBUFFERFILEREADER_WRITETOFILEL, "setting attribs returned error: %d", err3);
   567 			User::LeaveIfError(err3);
   593 			LEAVEIFERROR(err3, OstTrace1(TRACE_ERROR, DUP8_CBUFFERFILEREADER_WRITETOFILEL, "Leave: %d", err3));
   568 			
   594 			
   569 			// Move current along
   595 			// Move current along
   570 			aCurrent += iFixedHeader.iFileSize - filesize;
   596 			aCurrent += iFixedHeader.iFileSize - filesize;
   571 
   597 
   572 			// Finished reset state
   598 			// Finished reset state
   575 		else
   601 		else
   576 			{
   602 			{
   577 			TInt size = aEnd - aCurrent;
   603 			TInt size = aEnd - aCurrent;
   578 			TPtr8 ptr(aCurrent, size, size);
   604 			TPtr8 ptr(aCurrent, size, size);
   579 			const TInt err2 = iFileHandle.Write(ptr);
   605 			const TInt err2 = iFileHandle.Write(ptr);
   580             __LOG2("CBufferFileReader::WriteToFile() - writing %d bytes returned error: %d", ptr.Length(), err2);
   606 			OstTraceExt2(TRACE_NORMAL, DUP4_CBUFFERFILEREADER_WRITETOFILEL, "writing %d bytes returned error: %d", ptr.Length(), err2);
   581 
   607 
   582 			retVal = EFalse;
   608 			retVal = EFalse;
   583 			} // else
   609 			} // else
   584 			
   610 			
   585         __LOG1("CBufferFileReader::WriteToFile() - END - finished: %d", retVal);
   611 		OstTrace1(TRACE_NORMAL, DUP5_CBUFFERFILEREADER_WRITETOFILEL, "finished: %d", retVal);
       
   612 		OstTraceFunctionExit0( CBUFFERFILEREADER_WRITETOFILEL_EXIT );
   586 		return retVal;
   613 		return retVal;
   587 		}
   614 		}
   588 
   615 
   589 	void CBufferFileReader::ReadFromBufferL(const TDesC8& aBuffer, TBool aLastSection)
   616 	void CBufferFileReader::ReadFromBufferL(const TDesC8& aBuffer, TBool aLastSection)
   590 	/** Reads from the buffer and writes files to disk.
   617 	/** Reads from the buffer and writes files to disk.
   592 	@param aBuffer The buffer to read from.
   619 	@param aBuffer The buffer to read from.
   593 	@param aLastSection Is this the last section?
   620 	@param aLastSection Is this the last section?
   594 	@leave KErrUnderflow More data is needed.
   621 	@leave KErrUnderflow More data is needed.
   595 	*/	
   622 	*/	
   596         {
   623         {
   597         __LOG5("CBufferFileReader::ReadFromBufferL() - START - iFileNameRead: %d, iSnapshotChecked: %d, iRestore: %d, iFileOpen: %d, iFileName: %S", iFileNameRead, iSnapshotChecked, iRestore, iFileOpen, &iFileName);
   624         OstTraceFunctionEntry0( CBUFFERFILEREADER_READFROMBUFFERL_ENTRY );
       
   625         OstTraceExt5(TRACE_NORMAL, CBUFFERFILEREADER_READFROMBUFFERL, "iFileNameRead: %d, iSnapshotChecked: %d, iRestore: %d, iFileOpen: %d, iFileName: %S", iFileNameRead, iSnapshotChecked, iRestore, iFileOpen, iFileName);
   598 
   626 
   599         TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
   627         TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
   600 		const TUint8* end = current + aBuffer.Size();
   628 		const TUint8* end = current + aBuffer.Size();
   601 		
   629 		
   602 		// Workaround for "dual fixed header in backup" error. Tries to detect the special error case where iFixedHeaderRead=true but filename wasn't read
   630 		// Workaround for "dual fixed header in backup" error. Tries to detect the special error case where iFixedHeaderRead=true but filename wasn't read
   614 					}
   642 					}
   615 				}
   643 				}
   616 
   644 
   617 			if(workAroundNeeded)
   645 			if(workAroundNeeded)
   618 				{
   646 				{
   619 				__LOG("CBufferFileReader::ReadFromBufferL() - Dual header was detected, workaround!!!");
   647 			    OstTrace0(TRACE_NORMAL, DUP1_CBUFFERFILEREADER_READFROMBUFFERL, "Dual header was detected, workaround!!!");
   620 				iFixedHeaderRead = EFalse; // Mark that the processing loop reads the fixed header again
   648 				iFixedHeaderRead = EFalse; // Mark that the processing loop reads the fixed header again
   621 				}
   649 				}
   622 			}
   650 			}
   623 		
   651 		
   624 		while (current < end)
   652 		while (current < end)
   625 			{
   653 			{
   626             __LOG2("CBufferFileReader::ReadFromBufferL() - iFixedHeaderRead: %d, iLeftToSkip: %d", iFixedHeaderRead, iLeftToSkip);
   654 		    OstTraceExt2(TRACE_NORMAL, DUP2_CBUFFERFILEREADER_READFROMBUFFERL, "iFixedHeaderRead: %d, iLeftToSkip: %d", iFixedHeaderRead, iLeftToSkip);
   627 
   655 
   628 			// Do we have the fixed header?
   656 			// Do we have the fixed header?
   629 			if (!iFixedHeaderRead)
   657 			if (!iFixedHeaderRead)
   630 				{
   658 				{
   631 				if (ReadFromBufferF(iFixedHeader, current, end) == EFalse)
   659 				if (ReadFromBufferF(iFixedHeader, current, end) == EFalse)
   632 					{
   660 					{
   633 					__LOG("CBufferFileReader::ReadFromBufferL() - ReadFromBufferF() returned False so breaking!");
   661 				    OstTrace0(TRACE_NORMAL, DUP3_CBUFFERFILEREADER_READFROMBUFFERL, "ReadFromBufferF() returned False so breaking!");
   634 					break;
   662 					break;
   635 					} // if
   663 					} // if
   636 				
   664 				
   637                 __LOG1("CBufferFileReader::ReadFromBufferL() - fixed header - iFileNameLength:  %d", iFixedHeader.iFileNameLength);
   665 				OstTrace1(TRACE_NORMAL, DUP4_CBUFFERFILEREADER_READFROMBUFFERL, "fixed header - iFileNameLength:  %d", iFixedHeader.iFileNameLength);
   638                 __LOG1("CBufferFileReader::ReadFromBufferL() - fixed header - iFileSize:        %d", iFixedHeader.iFileSize);
   666 				OstTrace1(TRACE_NORMAL, DUP5_CBUFFERFILEREADER_READFROMBUFFERL, "fixed header - iFileSize:        %d", iFixedHeader.iFileSize);
   639                 __LOG1("CBufferFileReader::ReadFromBufferL() - fixed header - iAttributes:      %d", iFixedHeader.iAttributes);
   667 				OstTrace1(TRACE_NORMAL, DUP6_CBUFFERFILEREADER_READFROMBUFFERL, "fixed header - iAttributes:      %d", iFixedHeader.iAttributes);
   640                 
   668                 
   641                 if ((iFixedHeader.iFileNameLength > KMaxFileName) || (!iFixedHeader.iFileNameLength))
   669                 if ((iFixedHeader.iFileNameLength > KMaxFileName) || (!iFixedHeader.iFileNameLength))
   642 					{
   670 					{
   643 					__LOG1("CBufferFileReader::ReadFromBufferL() - Leaving - iFileNameLength: %d more then MaxLength", iFixedHeader.iFileNameLength);
   671                     OstTrace1(TRACE_ERROR, DUP7_CBUFFERFILEREADER_READFROMBUFFERL, "Leaving - iFileNameLength: %d more then MaxLength", iFixedHeader.iFileNameLength);
   644 					User::Leave(KErrOverflow);
   672 					User::Leave(KErrOverflow);
   645 					}
   673 					}
   646                 
   674                 
   647 				iFixedHeaderRead = ETrue;
   675 				iFixedHeaderRead = ETrue;
   648 				} // if
   676 				} // if
   649 
   677 
   650 				
   678 				
   651             __LOG1("CBufferFileReader::ReadFromBufferL() - iFileNameRead: %d", iFileNameRead);
   679 			OstTrace1(TRACE_NORMAL, DUP8_CBUFFERFILEREADER_READFROMBUFFERL, "iFileNameRead: %d", iFileNameRead);
   652 			if (!iFileNameRead)
   680 			if (!iFileNameRead)
   653 				{
   681 				{
   654 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(iFileName.Ptr())), iBytesRead, iFixedHeader.iFileNameLength * KCharWidthInBytes);
   682 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(iFileName.Ptr())), iBytesRead, iFixedHeader.iFileNameLength * KCharWidthInBytes);
   655 				
   683 				
   656 				if (ReadFromBufferV(ptr, iFixedHeader.iFileNameLength * KCharWidthInBytes, current, end) == EFalse)
   684 				if (ReadFromBufferV(ptr, iFixedHeader.iFileNameLength * KCharWidthInBytes, current, end) == EFalse)
   657 					{
   685 					{
   658 					iBytesRead = ptr.Size();
   686 					iBytesRead = ptr.Size();
   659 					__LOG1("CBufferFileReader::ReadFromBufferL() - ReadFromBufferV() returned False - Filename bytes read: %d", iBytesRead);
   687 					OstTrace1(TRACE_NORMAL, DUP9_CBUFFERFILEREADER_READFROMBUFFERL, "ReadFromBufferV() returned False - Filename bytes read: %d", iBytesRead);
   660 					break;
   688 					break;
   661 					} // if
   689 					} // if
   662 				
   690 				
   663 				iFileName.SetLength(iFixedHeader.iFileNameLength);
   691 				iFileName.SetLength(iFixedHeader.iFileNameLength);
   664 				iFileNameRead = ETrue;
   692 				iFileNameRead = ETrue;
   665                 __LOG1("CBufferFileReader::ReadFromBufferL() - Got filename: %S", &iFileName);
   693 				OstTraceExt1(TRACE_NORMAL, DUP10_CBUFFERFILEREADER_READFROMBUFFERL, "Got filename: %S", iFileName);
   666 				}
   694 				}
   667 			
   695 			
   668 			// Is the file in the snapshot, if not it was deleted in an increment and does not need restoring
   696 			// Is the file in the snapshot, if not it was deleted in an increment and does not need restoring
   669             __LOG1("CBufferFileReader::ReadFromBufferL() - iSnapshotChecked: %d", iSnapshotChecked);
   697 			OstTrace1(TRACE_NORMAL, DUP11_CBUFFERFILEREADER_READFROMBUFFERL, "iSnapshotChecked: %d", iSnapshotChecked);
   670 			if (!iSnapshotChecked)
   698 			if (!iSnapshotChecked)
   671 				{
   699 				{
   672 				CheckFileInSnapshotL();
   700 				CheckFileInSnapshotL();
   673 				} // if
   701 				} // if
   674 			
   702 			
   675             __LOG2("CBufferFileReader::ReadFromBufferL() - iValidationHandler: 0x%08x, iRestore: %d", iValidationHandler, iRestore);
   703 			OstTraceExt2(TRACE_NORMAL, DUP12_CBUFFERFILEREADER_READFROMBUFFERL, "iValidationHandler: 0x%08x, iRestore: %d", reinterpret_cast<TInt32>(iValidationHandler), static_cast<TInt32>(iRestore));
   676 			if (iValidationHandler != NULL)
   704 			if (iValidationHandler != NULL)
   677 				{
   705 				{
   678 				if (iRestore)
   706 				if (iRestore)
   679 					{
   707 					{
   680 					iRestore = iValidationHandler->ValidFileL(iFileName);
   708 					iRestore = iValidationHandler->ValidFileL(iFileName);
   681                     __LOG1("CBufferFileReader::ReadFromBufferL() - validation handler result: %d", iRestore);
   709 					OstTrace1(TRACE_NORMAL, DUP13_CBUFFERFILEREADER_READFROMBUFFERL, "validation handler result: %d", iRestore);
   682 					}
   710 					}
   683 				}
   711 				}
   684 			
   712 			
   685 			if (!iRestore && !iLeftToSkip)
   713 			if (!iRestore && !iLeftToSkip)
   686 				{
   714 				{
   687                 __LOG1("CBufferFileReader::ReadFromBufferL() - restore not permitted, skipping file data (%d bytes)", iFixedHeader.iFileSize);
   715 			    OstTrace1(TRACE_NORMAL, DUP14_CBUFFERFILEREADER_READFROMBUFFERL, "restore not permitted, skipping file data (%d bytes)", iFixedHeader.iFileSize);
   688 				iLeftToSkip = iFixedHeader.iFileSize; // So we can skip the bytes
   716 				iLeftToSkip = iFixedHeader.iFileSize; // So we can skip the bytes
   689 				}
   717 				}
   690 			
   718 			
   691             __LOG1("CBufferFileReader::ReadFromBufferL() - iFileOpen: %d", iFileOpen);
   719 			OstTrace1(TRACE_NORMAL, DUP15_CBUFFERFILEREADER_READFROMBUFFERL, "iFileOpen: %d", iFileOpen);
   692 			if (iRestore)
   720 			if (iRestore)
   693 				{
   721 				{
   694 				// Check if it is a directory or file
   722 				// Check if it is a directory or file
   695 				_LIT( KTrailingBackSlash, "\\" );
   723 				_LIT( KTrailingBackSlash, "\\" );
   696 				if (iFileName.Right(1) == KTrailingBackSlash())
   724 				if (iFileName.Right(1) == KTrailingBackSlash())
   697 					{
   725 					{
   698 					__LOG("CBufferFileReader::ReadFromBufferL() - Attempting to recreate directory path...");
   726 				    OstTrace0(TRACE_NORMAL, DUP16_CBUFFERFILEREADER_READFROMBUFFERL, "Attempting to recreate directory path...");
   699 					RecreateDirL();
   727 					RecreateDirL();
   700 					Reset();
   728 					Reset();
   701 					}
   729 					}
   702 				else 
   730 				else 
   703 					{
   731 					{
   704 					// Have we opened the file?
   732 					// Have we opened the file?
   705 					if (!iFileOpen)
   733 					if (!iFileOpen)
   706 						{
   734 						{
   707 						__LOG("CBufferFileReader::ReadFromBufferL() - Attempting to recreate file...");
   735 					    OstTrace0(TRACE_NORMAL, DUP17_CBUFFERFILEREADER_READFROMBUFFERL, "Attempting to recreate file...");
   708 						RecreateFileL();		
   736 						RecreateFileL();		
   709 						}
   737 						}
   710 					
   738 					
   711 					// Write to the file
   739 					// Write to the file
   712 	                __LOG("CBufferFileReader::ReadFromBufferL() - Attempting to write to file...");
   740 					OstTrace0(TRACE_NORMAL, DUP18_CBUFFERFILEREADER_READFROMBUFFERL, "Attempting to write to file...");
   713 					if (!WriteToFileL(current, end))
   741 					if (!WriteToFileL(current, end))
   714 						{
   742 						{
   715 						__LOG("CBufferFileReader::ReadFromBufferL() - WriteToFileL() returned False so breaking!");
   743 					    OstTrace0(TRACE_NORMAL, DUP19_CBUFFERFILEREADER_READFROMBUFFERL, "WriteToFileL() returned False so breaking!");
   716 						break;
   744 						break;
   717 						}	
   745 						}	
   718 					}//if
   746 					}//if
   719 				} // if
   747 				} // if
   720 			else
   748 			else
   721 				{
   749 				{
   722 				// We need to skip the bytes in the data
   750 				// We need to skip the bytes in the data
   723                 __LOG2("CBufferFileReader::ReadFromBufferL() - We\'re in skip mode. EndPos: %8d, CurrentPos: %8d", end, current);
   751 			    OstTraceExt2(TRACE_NORMAL, DUP20_CBUFFERFILEREADER_READFROMBUFFERL, "We\'re in skip mode. EndPos: %8d, CurrentPos: %8d", reinterpret_cast<TInt32>(end), reinterpret_cast<TInt32>(current));
   724 				if ((end - current) >= iLeftToSkip)
   752 				if ((end - current) >= iLeftToSkip)
   725 					{
   753 					{
   726 					current += iLeftToSkip;
   754 					current += iLeftToSkip;
   727 
   755 
   728 					// Finished reset state
   756 					// Finished reset state
   729                     __LOG("CBufferFileReader::ReadFromBufferL() - Finished skipping");
   757 					OstTrace0(TRACE_NORMAL, DUP21_CBUFFERFILEREADER_READFROMBUFFERL, "Finished skipping");
   730 					Reset();
   758 					Reset();
   731 					} // if
   759 					} // if
   732 				else
   760 				else
   733 					{
   761 					{
   734                     __LOG1("CBufferFileReader::ReadFromBufferL() - Still more data to skip...: %d bytes", iLeftToSkip);
   762 				    OstTrace1(TRACE_NORMAL, DUP22_CBUFFERFILEREADER_READFROMBUFFERL, "Still more data to skip...: %d bytes", iLeftToSkip);
   735 					iLeftToSkip = iLeftToSkip - (end - current);
   763 					iLeftToSkip = iLeftToSkip - (end - current);
   736 					break;
   764 					break;
   737 					} // else
   765 					} // else
   738 				} // else
   766 				} // else
   739 			} // while
   767 			} // while
   740 			
   768 			
   741             __LOG3("CBufferFileReader::ReadFromBufferL() - aLastSection: %d, iFileOpen: %d, iLeftToSkip: %d", aLastSection, iFileOpen, iLeftToSkip);
   769             OstTraceExt3(TRACE_NORMAL, DUP23_CBUFFERFILEREADER_READFROMBUFFERL, "aLastSection: %d, iFileOpen: %d, iLeftToSkip: %d", aLastSection, iFileOpen, iLeftToSkip);
   742 
   770 
   743 			if ((aLastSection && iFileOpen) ||
   771 			if ((aLastSection && iFileOpen) ||
   744 			    (aLastSection && (iLeftToSkip > 0)))
   772 			    (aLastSection && (iLeftToSkip > 0)))
   745 				{
   773 				{
   746                 __LOG("CBufferFileReader::ReadFromBufferL() - Leaving with KErrUnderflow because not all skipped data was consumed!");
   774 			    OstTrace0(TRACE_ERROR, DUP24_CBUFFERFILEREADER_READFROMBUFFERL, "Leaving with KErrUnderflow because not all skipped data was consumed!");
   747 				User::Leave(KErrUnderflow);
   775 				User::Leave(KErrUnderflow);
   748 			} // if
   776 			} // if
   749 
   777         
   750         __LOG("CBufferFileReader::ReadFromBufferL() - END");
   778 		OstTraceFunctionExit0( CBUFFERFILEREADER_READFROMBUFFERL_EXIT );
   751 		} // ReadFromBufferL
   779 		} // ReadFromBufferL
   752 		
   780 		
   753 	void CBufferFileReader::RedirectMIDletRestorePathL(const TDesC& aOriginal, CDesCArray& aRedirected)
   781 	void CBufferFileReader::RedirectMIDletRestorePathL(const TDesC& aOriginal, CDesCArray& aRedirected)
   754 	/** Redirects the midlet restore path
   782 	/** Redirects the midlet restore path
   755 	
   783 	
   756 	@param aOriginal the original path
   784 	@param aOriginal the original path
   757 	@param aRedirected the redirected path
   785 	@param aRedirected the redirected path
   758 	*/
   786 	*/
   759 		{
   787 		{
       
   788 		OstTraceFunctionEntry0( CBUFFERFILEREADER_REDIRECTMIDLETRESTOREPATHL_ENTRY );
   760 		TFileName redirectedFilename(KMIDletTempRestorePath);
   789 		TFileName redirectedFilename(KMIDletTempRestorePath);
   761 		// Backslash used to isolate the filename from aOriginal's absolute path
   790 		// Backslash used to isolate the filename from aOriginal's absolute path
   762 		const TChar KTCharBackslash('\\');
   791 		const TChar KTCharBackslash('\\');
   763 		
   792 		
   764 		// Isolate the filename from aOriginal and Append it to our temp path
   793 		// Isolate the filename from aOriginal and Append it to our temp path
   765 		redirectedFilename.Append(aOriginal.Mid(aOriginal.LocateReverseF(KTCharBackslash) + 1));
   794 		redirectedFilename.Append(aOriginal.Mid(aOriginal.LocateReverseF(KTCharBackslash) + 1));
   766 		aRedirected.AppendL(redirectedFilename);
   795 		aRedirected.AppendL(redirectedFilename);
       
   796 		OstTraceFunctionExit0( CBUFFERFILEREADER_REDIRECTMIDLETRESTOREPATHL_EXIT );
   767 		}
   797 		}
   768 
   798 
   769 	void CBufferFileReader::ReadMIDletsFromBufferL(const TDesC8& aBuffer, TBool aLastSection, 
   799 	void CBufferFileReader::ReadMIDletsFromBufferL(const TDesC8& aBuffer, TBool aLastSection, 
   770 		CDesCArray& aUnpackedFileNames)
   800 		CDesCArray& aUnpackedFileNames)
   771 	/** Reads from the buffer and writes files to disk.
   801 	/** Reads from the buffer and writes files to disk.
   773 	@param aBuffer The buffer to read from.
   803 	@param aBuffer The buffer to read from.
   774 	@param aLastSection Is this the last section?
   804 	@param aLastSection Is this the last section?
   775 	@leave KErrUnderflow More data is needed.
   805 	@leave KErrUnderflow More data is needed.
   776 	*/	
   806 	*/	
   777 		{
   807 		{
       
   808 		OstTraceFunctionEntry0( CBUFFERFILEREADER_READMIDLETSFROMBUFFERL_ENTRY );
   778 		TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
   809 		TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
   779 		const TUint8* end = current + aBuffer.Size();
   810 		const TUint8* end = current + aBuffer.Size();
   780 		TInt fileIndex = 0;
   811 		TInt fileIndex = 0;
   781 		while (current < end)
   812 		while (current < end)
   782 			{
   813 			{
   783 			// Do we have the fixed header?
   814 			// Do we have the fixed header?
   784 			if (!iFixedHeaderRead)
   815 			if (!iFixedHeaderRead)
   785 				{
   816 				{
   786 				if (ReadFromBufferF(iFixedHeader, current, end) == EFalse)
   817 				if (ReadFromBufferF(iFixedHeader, current, end) == EFalse)
   787 					{
   818 					{
   788 					__LOG("CBufferFileReader::ReadMIDletsFromBufferL() - ReadFromBufferF() returned False so breaking!");
   819 				    OstTrace0(TRACE_NORMAL, CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "ReadFromBufferF() returned False so breaking!");
   789 					break;
   820 					break;
   790 					} // if
   821 					} // if
   791 				__LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - fixed header - iFileNameLength:  %d", iFixedHeader.iFileNameLength);
   822 				OstTrace1(TRACE_NORMAL, DUP1_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "fixed header - iFileNameLength:  %d", iFixedHeader.iFileNameLength);
   792                 __LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - fixed header - iFileSize:        %d", iFixedHeader.iFileSize);
   823 				OstTrace1(TRACE_NORMAL, DUP2_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "fixed header - iFileSize:        %d", iFixedHeader.iFileSize);
   793                 __LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - fixed header - iAttributes:      %d", iFixedHeader.iAttributes);	
   824 				OstTrace1(TRACE_NORMAL, DUP3_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "fixed header - iAttributes:      %d", iFixedHeader.iAttributes);	
   794 					
   825 					
   795 				if ((iFixedHeader.iFileNameLength > KMaxFileName) || (!iFixedHeader.iAttributes) || (!iFixedHeader.iFileNameLength))
   826 				if ((iFixedHeader.iFileNameLength > KMaxFileName) || (!iFixedHeader.iAttributes) || (!iFixedHeader.iFileNameLength))
   796 					{
   827 					{
   797 					__LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - Leaving - iFileNameLength: %d more then MaxLength", iFixedHeader.iFileNameLength);
   828 				    OstTrace1(TRACE_ERROR, DUP4_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "Leaving - iFileNameLength: %d more then MaxLength", iFixedHeader.iFileNameLength);
   798 					User::Leave(KErrOverflow);
   829 					User::Leave(KErrOverflow);
   799 					}
   830 					}
   800 				
   831 				
   801 				iFixedHeaderRead = ETrue;
   832 				iFixedHeaderRead = ETrue;
   802 				} // if
   833 				} // if
   806 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(iFileName.Ptr())), iBytesRead, iFixedHeader.iFileNameLength * KCharWidthInBytes);
   837 				TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(iFileName.Ptr())), iBytesRead, iFixedHeader.iFileNameLength * KCharWidthInBytes);
   807 				
   838 				
   808 				if (ReadFromBufferV(ptr, iFixedHeader.iFileNameLength * KCharWidthInBytes, current, end) == EFalse)
   839 				if (ReadFromBufferV(ptr, iFixedHeader.iFileNameLength * KCharWidthInBytes, current, end) == EFalse)
   809 					{
   840 					{
   810 					iBytesRead = ptr.Size();
   841 					iBytesRead = ptr.Size();
   811 					__LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - ReadFromBufferV() returned False - Filename bytes read: %d", iBytesRead);
   842 					OstTrace1(TRACE_NORMAL, DUP5_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "ReadFromBufferV() returned False - Filename bytes read: %d", iBytesRead);
   812 					break;
   843 					break;
   813 					} // if
   844 					} // if
   814 				
   845 				
   815 					
   846 					
   816 				iFileName.SetLength(iFixedHeader.iFileNameLength);
   847 				iFileName.SetLength(iFixedHeader.iFileNameLength);
   833 				CheckFileInSnapshotL();
   864 				CheckFileInSnapshotL();
   834 				} // if
   865 				} // if
   835 			
   866 			
   836 			if (!iRestore && !iLeftToSkip)
   867 			if (!iRestore && !iLeftToSkip)
   837 				{
   868 				{
   838                 __LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - restore not permitted, skipping file data (%d bytes)", iFixedHeader.iFileSize);
   869 			    OstTrace1(TRACE_NORMAL, DUP6_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "restore not permitted, skipping file data (%d bytes)", iFixedHeader.iFileSize);
   839 				iLeftToSkip = iFixedHeader.iFileSize; // So we can skip the bytes
   870 				iLeftToSkip = iFixedHeader.iFileSize; // So we can skip the bytes
   840 				}
   871 				}
   841 
   872 
   842 			if (iRestore)
   873 			if (iRestore)
   843 				{
   874 				{
   848 					}
   879 					}
   849 					
   880 					
   850 				// Write to the file
   881 				// Write to the file
   851 				if (!WriteToFileL(current, end))
   882 				if (!WriteToFileL(current, end))
   852 					{
   883 					{
   853 					__LOG("CBufferFileReader::ReadMIDletsFromBufferL() - WriteToFileL() returned False so breaking!");
   884 				    OstTrace0(TRACE_NORMAL, DUP7_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "WriteToFileL() returned False so breaking!");
   854 					break;
   885 					break;
   855 					}
   886 					}
   856 				} // if
   887 				} // if
   857 			else
   888 			else
   858 				{
   889 				{
   864 					// Finished reset state
   895 					// Finished reset state
   865 					Reset();
   896 					Reset();
   866 					} // if
   897 					} // if
   867 				else
   898 				else
   868 					{
   899 					{
   869 					__LOG1("CBufferFileReader::ReadMIDletsFromBufferL() - Still more data to skip...: %d bytes", iLeftToSkip);
   900 				    OstTrace1(TRACE_NORMAL, DUP8_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "Still more data to skip...: %d bytes", iLeftToSkip);
   870 					iLeftToSkip = iLeftToSkip - (end - current);
   901 					iLeftToSkip = iLeftToSkip - (end - current);
   871 					break;
   902 					break;
   872 					} // else
   903 					} // else
   873 				} // else
   904 				} // else
   874 			} // while
   905 			} // while
   875 			
   906 			
   876 			if ((aLastSection && iFileOpen) ||
   907 			if ((aLastSection && iFileOpen) ||
   877 			    (aLastSection && (iLeftToSkip > 0)))
   908 			    (aLastSection && (iLeftToSkip > 0)))
   878 				{
   909 				{
       
   910 			    OstTrace0(TRACE_ERROR, DUP9_CBUFFERFILEREADER_READMIDLETSFROMBUFFERL, "Leave: KErrUnderflow");
   879 				User::Leave(KErrUnderflow);
   911 				User::Leave(KErrUnderflow);
   880 				} // if
   912 				} // if
       
   913 		OstTraceFunctionExit0( CBUFFERFILEREADER_READMIDLETSFROMBUFFERL_EXIT );
   881 		} // ReadMIDletsFromBufferL
   914 		} // ReadMIDletsFromBufferL
   882 		
   915 		
   883 	void CBufferFileReader::Reset()
   916 	void CBufferFileReader::Reset()
   884 	/** Resets the state of the object.
   917 	/** Resets the state of the object.
   885 	*/
   918 	*/
   886 		{
   919 		{
       
   920 		OstTraceFunctionEntry0( CBUFFERFILEREADER_RESET_ENTRY );
   887 		iFileHandle.Close();
   921 		iFileHandle.Close();
   888 		iFileOpen = EFalse;
   922 		iFileOpen = EFalse;
   889 		iFileNameRead = EFalse;
   923 		iFileNameRead = EFalse;
   890 		iLeftToSkip = 0;
   924 		iLeftToSkip = 0;
   891 		iSnapshotChecked = EFalse;
   925 		iSnapshotChecked = EFalse;
   892 		iFileName.SetLength(0);
   926 		iFileName.SetLength(0);
   893 		iFixedHeaderRead = EFalse;
   927 		iFixedHeaderRead = EFalse;
   894 		iBytesRead = 0;
   928 		iBytesRead = 0;
       
   929 		OstTraceFunctionExit0( CBUFFERFILEREADER_RESET_EXIT );
   895 		}
   930 		}
   896 		
   931 		
   897 	CBufferFileReader::~CBufferFileReader()
   932 	CBufferFileReader::~CBufferFileReader()
   898 	/** destructor
   933 	/** destructor
   899 	*/
   934 	*/
   900 		{
   935 		{
       
   936 		OstTraceFunctionEntry0( CBUFFERFILEREADER_CBUFFERFILEREADER_DES_ENTRY );
   901 		iFileHandle.Close();
   937 		iFileHandle.Close();
       
   938 		OstTraceFunctionExit0( CBUFFERFILEREADER_CBUFFERFILEREADER_DES_EXIT );
   902 		}
   939 		}
   903 		
   940 		
   904 	
   941 	
   905 	
   942 	
   906 	CBufferSnapshotWriter* CBufferSnapshotWriter::NewL(RSnapshots* aSnapshots)
   943 	CBufferSnapshotWriter* CBufferSnapshotWriter::NewL(RSnapshots* aSnapshots)
   907 	/** Symbian OS constructor
   944 	/** Symbian OS constructor
   908 	
   945 	
   909 	@param aFiles File information to write to the buffer.ownernship transfer
   946 	@param aFiles File information to write to the buffer.ownernship transfer
   910 	*/
   947 	*/
   911 		{
   948 		{
       
   949 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_NEWL_ENTRY );
   912 		CBufferSnapshotWriter* self = new(ELeave) CBufferSnapshotWriter(aSnapshots);
   950 		CBufferSnapshotWriter* self = new(ELeave) CBufferSnapshotWriter(aSnapshots);
   913 		CleanupStack::PushL(self);
   951 		CleanupStack::PushL(self);
   914 		self->ConstructL();
   952 		self->ConstructL();
   915 		CleanupStack::Pop(self);
   953 		CleanupStack::Pop(self);
   916 		
   954 		
       
   955 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_NEWL_EXIT );
   917 		return self;
   956 		return self;
   918 		} // NewL
   957 		} // NewL
   919 		
   958 		
   920 	CBufferSnapshotWriter::CBufferSnapshotWriter(RSnapshots* aSnapshots) : iSnapshots(aSnapshots)
   959 	CBufferSnapshotWriter::CBufferSnapshotWriter(RSnapshots* aSnapshots) : iSnapshots(aSnapshots)
   921 	/** Standard C++ constructor
   960 	/** Standard C++ constructor
   922 	*/
   961 	*/
   923 		{
   962 		{
       
   963 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_CBUFFERSNAPSHOTWRITER_CONS_ENTRY );
       
   964 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_CBUFFERSNAPSHOTWRITER_CONS_EXIT );
   924 		}
   965 		}
   925 		
   966 		
   926 	void CBufferSnapshotWriter::ConstructL()
   967 	void CBufferSnapshotWriter::ConstructL()
   927 	/** Symbian second phase constructor
   968 	/** Symbian second phase constructor
   928 
   969 
   929 	@param aFiles File information to write to the buffer.
   970 	@param aFiles File information to write to the buffer.
   930 	*/
   971 	*/
   931 		{
   972 		{
       
   973 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_CONSTRUCTL_ENTRY );
   932 		__ASSERT_DEBUG(iSnapshots, Panic(KErrArgument));
   974 		__ASSERT_DEBUG(iSnapshots, Panic(KErrArgument));
   933 		#ifdef SBE_LOGGING_ENABLED
   975 
   934         const TInt count = iSnapshots->Count();
   976         const TInt count = iSnapshots->Count();
   935         __LOG1("CBufferFileReader::NewL() - Got %d snapshots to compare against during restore...", count);
   977         OstTrace1(TRACE_NORMAL, CBUFFERSNAPSHOTWRITER_CONSTRUCTL, "Got %d snapshots to compare against during restore...", count);
   936 
   978 
   937 	    for(TInt x = 0; x < count; ++x)
   979 	    for(TInt x = 0; x < count; ++x)
   938 		    {
   980 		    {
   939             const TDesC& snapshot = (*iSnapshots)[x]->FileName();
   981             const TDesC& snapshot = (*iSnapshots)[x]->FileName();
   940             __LOG3("CBufferFileReader::NewL() -    snapshot[%4d/%4d] is: %S", x+1, count, &snapshot);
   982             OstTraceExt3(TRACE_NORMAL, DUP1_CBUFFERSNAPSHOTWRITER_CONSTRUCTL, "snapshot[%4d/%4d] is: %S", x+1, count, snapshot);
   941 		    } // for x
   983 		    } // for x
   942 
   984 
   943 		#endif
   985 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_CONSTRUCTL_EXIT );
   944 		} // ConstructL
   986 		} // ConstructL
   945 		
   987 		
   946 	CBufferSnapshotWriter::~CBufferSnapshotWriter()
   988 	CBufferSnapshotWriter::~CBufferSnapshotWriter()
   947 	/** Standard C++ destructor
   989 	/** Standard C++ destructor
   948 	*/
   990 	*/
   949 		{
   991 		{
       
   992 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_CBUFFERSNAPSHOTWRITER_DES_ENTRY );
   950 		if(iSnapshots)
   993 		if(iSnapshots)
   951 			{
   994 			{
   952 			iSnapshots->ResetAndDestroy();
   995 			iSnapshots->ResetAndDestroy();
   953 			delete iSnapshots;
   996 			delete iSnapshots;
   954 			}
   997 			}
       
   998 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_CBUFFERSNAPSHOTWRITER_DES_EXIT );
   955 		} // ~CBufferSnapshotWriter
   999 		} // ~CBufferSnapshotWriter
   956 		
  1000 		
   957 	void CBufferSnapshotWriter::StartL(TPtr8& aBuffer, TBool& aCompleted)
  1001 	void CBufferSnapshotWriter::StartL(TPtr8& aBuffer, TBool& aCompleted)
   958 	/** Starts writing to the buffer 
  1002 	/** Starts writing to the buffer 
   959 	
  1003 	
   960 	@param aBuffer The buffer.
  1004 	@param aBuffer The buffer.
   961 	@param aCompleted On return if we have finished writing data.
  1005 	@param aCompleted On return if we have finished writing data.
   962 	*/
  1006 	*/
   963 		{
  1007 		{
   964         __LOG("CBufferSnapshotWriter::StartL() - START");
  1008         OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_STARTL_ENTRY );        
   965 		WriteToBufferL(aBuffer, aCompleted);
  1009 		WriteToBufferL(aBuffer, aCompleted);        
   966         __LOG("CBufferSnapshotWriter::StartL() - END");
  1010 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_STARTL_EXIT );
   967 		} // WriteToBufferL
  1011 		} // WriteToBufferL
   968 
  1012 
   969 	void CBufferSnapshotWriter::ContinueL(TPtr8& aBuffer, TBool& aCompleted)
  1013 	void CBufferSnapshotWriter::ContinueL(TPtr8& aBuffer, TBool& aCompleted)
   970 	/** Continues writing to the buffer 
  1014 	/** Continues writing to the buffer 
   971 	
  1015 	
   972 	@param aBuffer The buffer.
  1016 	@param aBuffer The buffer.
   973 	@param aCompleted On return if we have finished writing data.
  1017 	@param aCompleted On return if we have finished writing data.
   974 	*/
  1018 	*/
   975 		{
  1019 		{
   976         __LOG("CBufferSnapshotWriter::ContinueL() - START");
  1020         OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_CONTINUEL_ENTRY );        
   977 		WriteToBufferL(aBuffer, aCompleted);
  1021 		WriteToBufferL(aBuffer, aCompleted);        
   978         __LOG("CBufferSnapshotWriter::ContinueL() - END");
  1022 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_CONTINUEL_EXIT );
   979 		} // WriteToBufferL
  1023 		} // WriteToBufferL
   980 		
  1024 		
   981 	void CBufferSnapshotWriter::WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted)
  1025 	void CBufferSnapshotWriter::WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted)
   982 	/** Writes to the buffer 
  1026 	/** Writes to the buffer 
   983 
  1027 
   984 	@param aBuffer The buffer.
  1028 	@param aBuffer The buffer.
   985 	@param aCompleted On return if we have finished writing data.
  1029 	@param aCompleted On return if we have finished writing data.
   986 	*/
  1030 	*/
   987 		{
  1031 		{
   988         __LOG1("CBufferSnapshotWriter::WriteToBufferL() - START - aBuffer length: %d", aBuffer.Length());
  1032         OstTraceFunctionEntry0( CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL_ENTRY );
       
  1033         OstTrace1(TRACE_NORMAL, CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL, "aBuffer length: %d", aBuffer.Length());
   989 		aCompleted = EFalse;
  1034 		aCompleted = EFalse;
   990 		
  1035 		
   991 		const TUint count = iSnapshots->Count();
  1036 		const TUint count = iSnapshots->Count();
   992 		while (iCurrentSnapshot < count)
  1037 		while (iCurrentSnapshot < count)
   993 			{
  1038 			{
   994             __LOG1("CBufferSnapshotWriter::WriteToBufferL() - iCurrentSnapshot: %d", iCurrentSnapshot);
  1039 		    OstTrace1(TRACE_NORMAL, DUP1_CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL, "iCurrentSnapshot: %d", iCurrentSnapshot);
   995 
  1040 
   996 			// Check there is enough room
  1041 			// Check there is enough room
   997 			if (sizeof(TSnapshot) > static_cast<TUint>(aBuffer.MaxSize() - aBuffer.Size()))
  1042 			if (sizeof(TSnapshot) > static_cast<TUint>(aBuffer.MaxSize() - aBuffer.Size()))
   998 				{
  1043 				{
   999 				__LOG("CBufferSnapshotWriter::WriteToBufferL() - Snapshot size is more than buffer available - break");
  1044 			    OstTrace0(TRACE_NORMAL, DUP2_CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL, "Snapshot size is more than buffer available - break");
  1000 				break;
  1045 				break;
  1001 				} // if
  1046 				} // if
  1002 				
  1047 				
  1003 			// Write modified
  1048 			// Write modified
  1004 			TSnapshot snapshot;
  1049 			TSnapshot snapshot;
  1005 			(*iSnapshots)[iCurrentSnapshot]->Snapshot(snapshot);
  1050 			(*iSnapshots)[iCurrentSnapshot]->Snapshot(snapshot);
  1006             __LOG1("CBufferSnapshotWriter::WriteToBufferL() - writing snapshot for file: %S", &snapshot.iFileName);
  1051 			OstTraceExt1(TRACE_NORMAL, DUP3_CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL, "writing snapshot for file: %S", snapshot.iFileName);
  1007 
  1052 
  1008 			WriteToBufferF(snapshot, aBuffer);
  1053 			WriteToBufferF(snapshot, aBuffer);
  1009 			
  1054 			
  1010 			++iCurrentSnapshot;			
  1055 			++iCurrentSnapshot;			
  1011 			} // while
  1056 			} // while
  1013 		if (iCurrentSnapshot >= count)
  1058 		if (iCurrentSnapshot >= count)
  1014 			{
  1059 			{
  1015 			aCompleted = ETrue;
  1060 			aCompleted = ETrue;
  1016 			} // if
  1061 			} // if
  1017 
  1062 
  1018         __LOG1("CBufferSnapshotWriter::WriteToBufferL() - END - aCompleted: %d", aCompleted);
  1063 		OstTrace1(TRACE_NORMAL, DUP4_CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL, "aCompleted: %d", aCompleted);
       
  1064 		OstTraceFunctionExit0( CBUFFERSNAPSHOTWRITER_WRITETOBUFFERL_EXIT );
  1019 		} // WriteToBufferL
  1065 		} // WriteToBufferL
  1020 	
  1066 	
  1021 	CBufferSnapshotReader* CBufferSnapshotReader::NewL(RSnapshots& aSnapshots)
  1067 	CBufferSnapshotReader* CBufferSnapshotReader::NewL(RSnapshots& aSnapshots)
  1022 	/** Symbian constructor
  1068 	/** Symbian constructor
  1023 	
  1069 	
  1024 	@param aFiles Locaton to store files read from buffer.
  1070 	@param aFiles Locaton to store files read from buffer.
  1025 	*/
  1071 	*/
  1026 		{
  1072 		{
  1027 		return new (ELeave) CBufferSnapshotReader(aSnapshots);
  1073 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_NEWL_ENTRY );
       
  1074 		CBufferSnapshotReader* reader = new (ELeave) CBufferSnapshotReader(aSnapshots); 
       
  1075 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_NEWL_EXIT );
       
  1076 		return reader;
  1028 		}
  1077 		}
  1029 		
  1078 		
  1030 	CBufferSnapshotReader::CBufferSnapshotReader(RSnapshots& aSnapshots) :
  1079 	CBufferSnapshotReader::CBufferSnapshotReader(RSnapshots& aSnapshots) :
  1031 		iSnapshots(aSnapshots)
  1080 		iSnapshots(aSnapshots)
  1032 	/** C++ constructor
  1081 	/** C++ constructor
  1033 	
  1082 	
  1034 	@param aSnapshots snapshots of files.
  1083 	@param aSnapshots snapshots of files.
  1035 	*/
  1084 	*/
  1036 		{
  1085 		{
       
  1086 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_CBUFFERSNAPSHOTREADER_CONS_ENTRY );
       
  1087 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_CBUFFERSNAPSHOTREADER_CONS_EXIT );
  1037 		}
  1088 		}
  1038 		
  1089 		
  1039 	CBufferSnapshotReader::~CBufferSnapshotReader()
  1090 	CBufferSnapshotReader::~CBufferSnapshotReader()
  1040 	/**
  1091 	/**
  1041 	C++ destructor
  1092 	C++ destructor
  1042 	*/
  1093 	*/
  1043 		{
  1094 		{
       
  1095 		OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_CBUFFERSNAPSHOTREADER_DES_ENTRY );
       
  1096 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_CBUFFERSNAPSHOTREADER_DES_EXIT );
  1044 		}
  1097 		}
  1045 		
  1098 		
  1046 	void CBufferSnapshotReader::StartL(const TDesC8& aBuffer, TBool aLastSection)
  1099 	void CBufferSnapshotReader::StartL(const TDesC8& aBuffer, TBool aLastSection)
  1047 	/** Starts reading data from the buffer
  1100 	/** Starts reading data from the buffer
  1048 	
  1101 	
  1049 	@param aBuffer buffer to read from.
  1102 	@param aBuffer buffer to read from.
  1050 	@param aLastSection is this the last section.
  1103 	@param aLastSection is this the last section.
  1051 	*/
  1104 	*/
  1052 		{
  1105 		{
  1053         __LOG2("CBufferSnapshotReader::StartL() - START - buffer len: %d, aLastSection: %d", aBuffer.Length(), aLastSection);
  1106         OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_STARTL_ENTRY );
       
  1107         OstTraceExt2(TRACE_NORMAL, CBUFFERSNAPSHOTREADER_STARTL, "buffer len: %d, aLastSection: %d", aBuffer.Length(), aLastSection);
  1054 
  1108 
  1055 		ReadFromBufferL(aBuffer, aLastSection);
  1109 		ReadFromBufferL(aBuffer, aLastSection);
  1056 
  1110         
  1057         __LOG("CBufferSnapshotReader::StartL() - END");
  1111 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_STARTL_EXIT );
  1058 		}
  1112 		}
  1059 		
  1113 		
  1060 	void CBufferSnapshotReader::ContinueL(const TDesC8& aBuffer, TBool aLastSection)
  1114 	void CBufferSnapshotReader::ContinueL(const TDesC8& aBuffer, TBool aLastSection)
  1061 	/** Continues reading data from the buffer
  1115 	/** Continues reading data from the buffer
  1062 	
  1116 	
  1063 	@param aBuffer buffer to read from.
  1117 	@param aBuffer buffer to read from.
  1064 	@param aLastSection is this the last section.
  1118 	@param aLastSection is this the last section.
  1065 	*/
  1119 	*/
  1066 		{
  1120 		{
  1067         __LOG2("CBufferSnapshotReader::ContinueL() - START - buffer len: %d, aLastSection: %d", aBuffer.Length(), aLastSection);
  1121         OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_CONTINUEL_ENTRY );
       
  1122         OstTraceExt2(TRACE_NORMAL, CBUFFERSNAPSHOTREADER_CONTINUEL, "buffer len: %d, aLastSection: %d", aBuffer.Length(), aLastSection);
  1068 
  1123 
  1069 		ReadFromBufferL(aBuffer, aLastSection);
  1124 		ReadFromBufferL(aBuffer, aLastSection);
  1070 
  1125 
  1071         __LOG("CBufferSnapshotReader::ContinueL() - END");
  1126 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_CONTINUEL_EXIT );
  1072 		}
  1127 		}
  1073 		
  1128 		
  1074 	void CBufferSnapshotReader::ReadFromBufferL(const TDesC8& aBuffer, TBool /*aLastSection*/)
  1129 	void CBufferSnapshotReader::ReadFromBufferL(const TDesC8& aBuffer, TBool /*aLastSection*/)
  1075 	/** Reads data from the buffer
  1130 	/** Reads data from the buffer
  1076 	
  1131 	
  1077 	@param aBuffer buffer to read from.
  1132 	@param aBuffer buffer to read from.
  1078 	@param aLastSection is this the last section.
  1133 	@param aLastSection is this the last section.
  1079 	*/
  1134 	*/
  1080 		{
  1135 		{
  1081         __LOG("CBufferSnapshotReader::ReadFromBufferL() - START");
  1136         OstTraceFunctionEntry0( CBUFFERSNAPSHOTREADER_READFROMBUFFERL_ENTRY );        
  1082 
  1137 
  1083 		TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
  1138 		TUint8* current = const_cast<TUint8*>(aBuffer.Ptr());
  1084 		const TUint8* end = current + aBuffer.Size();
  1139 		const TUint8* end = current + aBuffer.Size();
  1085 		while (current < end)
  1140 		while (current < end)
  1086 			{
  1141 			{
  1087 			if (ReadFromBufferF(iSnapshot, current, end) == EFalse)
  1142 			if (ReadFromBufferF(iSnapshot, current, end) == EFalse)
  1088 				{
  1143 				{
  1089 				__LOG("CBufferSnapshotReader::ReadFromBufferL() - returned EFalse breaking!");
  1144 			    OstTrace0(TRACE_NORMAL, CBUFFERSNAPSHOTREADER_READFROMBUFFERL, "returned EFalse breaking!");
  1090 				break;
  1145 				break;
  1091 				}
  1146 				}
  1092 			
  1147 			
  1093             __LOG1("CBufferSnapshotReader::ReadFromBufferL() - read snapshot info for file: %S", &iSnapshot.iFileName);
  1148 			OstTraceExt1(TRACE_NORMAL, DUP1_CBUFFERSNAPSHOTREADER_READFROMBUFFERL, "read snapshot info for file: %S", iSnapshot.iFileName);
  1094             CSnapshot* snapshot = CSnapshot::NewLC(iSnapshot);
  1149             CSnapshot* snapshot = CSnapshot::NewLC(iSnapshot);
  1095 			iSnapshots.AppendL(snapshot);
  1150 			iSnapshots.AppendL(snapshot);
  1096 			CleanupStack::Pop(snapshot);
  1151 			CleanupStack::Pop(snapshot);
  1097 			} // while
  1152 			} // while
  1098 
  1153         
  1099         __LOG("CBufferSnapshotReader::ReadFromBufferL() - END");
  1154 		OstTraceFunctionExit0( CBUFFERSNAPSHOTREADER_READFROMBUFFERL_EXIT );
  1100 		} // ReadFromBufferL
  1155 		} // ReadFromBufferL
  1101 		
  1156 		
  1102 	
  1157 	
  1103 	// CSnapshot //
  1158 	// CSnapshot //
  1104 	
  1159 	
  1110 	@param aSelection - Selection Nmae
  1165 	@param aSelection - Selection Nmae
  1111 	@return CSelection a pointer to a new object 
  1166 	@return CSelection a pointer to a new object 
  1112 	*/
  1167 	*/
  1113 	CSnapshot* CSnapshot::NewLC(const TInt64& aModified, const TDesC& aFileName)
  1168 	CSnapshot* CSnapshot::NewLC(const TInt64& aModified, const TDesC& aFileName)
  1114 		{
  1169 		{
       
  1170 		OstTraceFunctionEntry0( CSNAPSHOT_NEWLC_ENTRY );
  1115 		CSnapshot* self = new (ELeave) CSnapshot(aModified);
  1171 		CSnapshot* self = new (ELeave) CSnapshot(aModified);
  1116 		CleanupStack::PushL(self);
  1172 		CleanupStack::PushL(self);
  1117 		self->ConstructL(aFileName);
  1173 		self->ConstructL(aFileName);
       
  1174 		OstTraceFunctionExit0( CSNAPSHOT_NEWLC_EXIT );
  1118 		return self;
  1175 		return self;
  1119 		}
  1176 		}
  1120 	
  1177 	
  1121 	/**
  1178 	/**
  1122 	
  1179 	
  1125 	@param aSnapshot - TSnapshot snapshot
  1182 	@param aSnapshot - TSnapshot snapshot
  1126 	@return CSelection a pointer to a new object 
  1183 	@return CSelection a pointer to a new object 
  1127 	*/
  1184 	*/
  1128 	CSnapshot* CSnapshot::NewLC(const TSnapshot& aSnapshot)
  1185 	CSnapshot* CSnapshot::NewLC(const TSnapshot& aSnapshot)
  1129 		{
  1186 		{
       
  1187 		OstTraceFunctionEntry0( DUP1_CSNAPSHOT_NEWLC_ENTRY );
  1130 		return CSnapshot::NewLC(aSnapshot.iModified, aSnapshot.iFileName);
  1188 		return CSnapshot::NewLC(aSnapshot.iModified, aSnapshot.iFileName);
  1131 		}
  1189 		}
  1132 	
  1190 	
  1133 	/**
  1191 	/**
  1134 	Standard C++ destructor
  1192 	Standard C++ destructor
  1135 	*/
  1193 	*/
  1136 	CSnapshot::~CSnapshot()
  1194 	CSnapshot::~CSnapshot()
  1137 		{
  1195 		{
       
  1196 		OstTraceFunctionEntry0( CSNAPSHOT_CSNAPSHOT_DES_ENTRY );
  1138 		delete iFileName;
  1197 		delete iFileName;
       
  1198 		OstTraceFunctionExit0( CSNAPSHOT_CSNAPSHOT_DES_EXIT );
  1139 		}
  1199 		}
  1140 	
  1200 	
  1141 	/**
  1201 	/**
  1142 	Standard C++ constructor
  1202 	Standard C++ constructor
  1143 	*/
  1203 	*/
  1144 	CSnapshot::CSnapshot(const TInt64& aModified) : iModified(aModified)
  1204 	CSnapshot::CSnapshot(const TInt64& aModified) : iModified(aModified)
  1145 		{
  1205 		{
       
  1206 		OstTraceFunctionEntry0( CSNAPSHOT_CSNAPSHOT_CONS_ENTRY );
       
  1207 		OstTraceFunctionExit0( CSNAPSHOT_CSNAPSHOT_CONS_EXIT );
  1146 		}
  1208 		}
  1147 		
  1209 		
  1148 	/**
  1210 	/**
  1149 	Symbian 2nd phase constructor
  1211 	Symbian 2nd phase constructor
  1150 	*/
  1212 	*/
  1151 	void CSnapshot::ConstructL(const TDesC& aFileName)
  1213 	void CSnapshot::ConstructL(const TDesC& aFileName)
  1152 		{
  1214 		{
       
  1215 		OstTraceFunctionEntry0( CSNAPSHOT_CONSTRUCTL_ENTRY );
  1153 		iFileName = aFileName.AllocL();
  1216 		iFileName = aFileName.AllocL();
       
  1217 		OstTraceFunctionExit0( CSNAPSHOT_CONSTRUCTL_EXIT );
  1154 		}
  1218 		}
  1155 	
  1219 	
  1156 	/**
  1220 	/**
  1157 	Selection Type
  1221 	Selection Type
  1158 	
  1222 	
  1179 	@return TSnapshot snapshot
  1243 	@return TSnapshot snapshot
  1180 	
  1244 	
  1181 	*/
  1245 	*/
  1182 	void CSnapshot::Snapshot(TSnapshot& aSnapshot)
  1246 	void CSnapshot::Snapshot(TSnapshot& aSnapshot)
  1183 		{
  1247 		{
       
  1248 		OstTraceFunctionEntry0( CSNAPSHOT_SNAPSHOT_ENTRY );
  1184 		aSnapshot.iFileName = *iFileName;
  1249 		aSnapshot.iFileName = *iFileName;
  1185 		aSnapshot.iModified = iModified;
  1250 		aSnapshot.iModified = iModified;
       
  1251 		OstTraceFunctionExit0( CSNAPSHOT_SNAPSHOT_EXIT );
  1186 		}
  1252 		}
  1187 		
  1253 		
  1188 	/**
  1254 	/**
  1189 	Method will be used for Sort on RPointerArray
  1255 	Method will be used for Sort on RPointerArray
  1190 	
  1256