/**
@internalComponent
*/
void CPreModifierPlugin::FsFileLockL(TFsPluginRequest& aRequest)
	{
	TInt length = 0;
	TInt64 pos = 0;
	TFileName filename;
	TParse parse;
	
	TInt err = aRequest.FileName(filename);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

	err = aRequest.Read(TFsPluginRequest::ELength, length);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

    parse.Set(filename, NULL, NULL);
	TPtrC extension(parse.Ext());

	_LOG4(_L("CPreModifierPlugin::FsFileLockL, file: %S, pos: %d, length: %d"), &filename, pos, length);
	
	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsFileLockL, post intercept"));

		// Request read from post interception
		if (extension.CompareF(_L(".lockread")) == 0)
			{
			length = 10;
			HBufC8* tempBuf = HBufC8::NewMaxLC(length);
			TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);		
			_LOG(_L("CPreModifierPlugin::FsFileLockL , calling AdoptFromClient in post intercept"));
			RFilePlugin fileplugin(aRequest);
			TInt err = fileplugin.AdoptFromClient();
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL
			
			_LOG2(_L("CPreModifierPlugin::FsFileLockL, Adopt returned %d"), err);
			
			err = fileplugin.Read(pos, tempBufPtr, length); 
			_LOG2(_L("CPreModifierPlugin::FsFileLockL, FileRead returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL
			fileplugin.Close();
			CleanupStack::PopAndDestroy();						          
			}

		// Request close from post interception
		if(extension.CompareF(_L(".lockclose")) == 0)
			{		
			_LOG(_L("CPreModifierPlugin::FsFileLockL, file = *.lockclose post intercept "));
			RFilePlugin fileplugin(aRequest);
		    TInt err = fileplugin.AdoptFromClient();
			_LOG2(_L("CPreModifierPlugin::FsFileLockL ,Open %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL		
			fileplugin.Close();			
			_LOG(_L("CPreModifierPlugin::FsFileLockL, Close"));
			}

		}
	else
		{
			User::Invariant();
		}
	}
void CPreModifierPlugin::FsFileReplaceL(TFsPluginRequest& aRequest)
	{
	TFileName filename;
	TParse parse;
	
	filename = aRequest.Src().FullName();

	TUint mode;
	TInt err = aRequest.Read(TFsPluginRequest::EMode, mode);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

	parse.Set(filename, NULL, NULL);
	TPtrC extension(parse.Ext());

	_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, file: %S"), &filename);
	
	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsFileReplaceL, post intercept"));
		if ((extension.CompareF(_L(".tst")) == 0) && (aRequest.Message().Int1() != 0))
			{
			//write to the newly replaced file
			TBuf8<64> wbuffer;
			wbuffer.Copy(_L8("TestTestTest"));

			RFilePlugin fileplugin(aRequest);
			TInt err = fileplugin.AdoptFromClient();
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL

    		err = fileplugin.Write(0, wbuffer);
			_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Write to the newly created file returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL

			TInt length = wbuffer.Length();
			HBufC8* tempBuf = HBufC8::NewMaxLC(length);
			TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
			err = fileplugin.Read(0, tempBufPtr);
			_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Read returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRe

			//testing the correct thing has been written to the drive
			err = wbuffer.Compare(tempBufPtr);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL
			
			fileplugin.Close();
			CleanupStack::PopAndDestroy();
			}
		}
	else
		{
		User::Invariant();
		}
	}
예제 #3
0
/**
@internalComponent
 */
void CStacked3Plugin::FsFileWriteL(TFsPluginRequest& aRequest)
	{
	TInt length = 0;
	TInt64 pos = 0;
	TFileName filename;
	TParse parse;

	TInt err = aRequest.FileName(filename);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

	err = aRequest.Read(TFsPluginRequest::ELength, length);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL
	
	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL
	
	parse.Set(filename, NULL, NULL);

	_LOG4(_L("CStacked3Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename,  pos, length);

	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CStacked3Plugin::FsFileWriteL, post intercept"));
		}
	else
		{
		_LOG(_L("CStacked3Plugin::FsFileWriteL, pre intercept"));	

		//set up test data for plugin
		TBuf8<20> wbuffer;			
		wbuffer.Copy(_L8("HELLO WORLD  SYMBIAN"));
		TInt length = wbuffer.Length();

		HBufC8* tempBuf = HBufC8::NewMaxLC(length);
		TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);

		RFilePlugin fileplugin(aRequest);
		err = fileplugin.AdoptFromClient();
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL
		
		//write to file
		err = fileplugin.Write(pos, wbuffer);
		_LOG2(_L("CStacked3Plugin::FsFileWriteL, RFilePlugin::Write returned %d"), err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		//read from file		
		err = fileplugin.Read(pos, tempBufPtr);
		_LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		//testing the correct thing has been written to the drive
		err = wbuffer.Compare(tempBufPtr);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		fileplugin.Close();
		CleanupStack::PopAndDestroy();	

		// send request down the stack
		User::Leave(KErrCompletion);	
		}
	}