os/persistentdata/featuremgmt/featuremgr/test/helper/pluginhelper/src/pluginhelper.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/test/helper/pluginhelper/src/pluginhelper.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +#include <f32file.h>
    1.25 +#include <e32cmn.h>
    1.26 +#include <e32std.h>
    1.27 +#include <e32const.h>
    1.28 +#include <e32def_private.h>
    1.29 +
    1.30 +void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile)
    1.31 +{
    1.32 +   RFs fs;
    1.33 +   fs.Connect();
    1.34 +   CleanupClosePushL(fs);
    1.35 +   fs.MkDirAll(aDestFile);
    1.36 +   CFileMan* fileMan = CFileMan::NewL( fs );
    1.37 +   // Copy feature file to file manager private data cage.
    1.38 +   //Ignore any errors as the file or path may not exist
    1.39 +   fileMan->Copy(aSourceFile, aDestFile);   
    1.40 +   CleanupStack::PopAndDestroy(&fs);
    1.41 +   }
    1.42 +    
    1.43 +void DeleteFileL(const TDesC& aFile)
    1.44 +   {
    1.45 +   RFs fs;
    1.46 +   fs.Connect();
    1.47 +   CleanupClosePushL(fs);	
    1.48 +   fs.SetAtt(aFile, 0, KEntryAttReadOnly);
    1.49 +   //Ignore any errors as the file or path may not exist
    1.50 +   fs.Delete( aFile );
    1.51 +   CleanupStack::PopAndDestroy(&fs);
    1.52 +   
    1.53 +   }
    1.54 +
    1.55 +TInt CheckFile(const TDesC& aFile)
    1.56 +	{
    1.57 +	RFs fs;
    1.58 +	fs.Connect();
    1.59 +	RFile file;
    1.60 +	TInt err = file.Open(fs,aFile,EFileRead);	   
    1.61 +	if (err!=KErrNotFound)
    1.62 +		{
    1.63 +		file.Close();
    1.64 +		fs.Close();
    1.65 +		return KErrNone;
    1.66 +		}
    1.67 +	else
    1.68 +		{
    1.69 +		fs.Close();
    1.70 +		return KErrNotFound;
    1.71 +		}
    1.72 +	}
    1.73 +
    1.74 +TInt ParseSwitch(const TDesC& aSwitch, const TDesC& aFile)
    1.75 +	{
    1.76 +	if (aSwitch==_L("?"))
    1.77 +		return CheckFile(aFile);
    1.78 +	else 
    1.79 +		return KErrNotSupported;
    1.80 +	}
    1.81 +
    1.82 +static void DoMainL()
    1.83 +{
    1.84 +	HBufC* cmdLine = HBufC::NewL(User::CommandLineLength());
    1.85 +   CleanupStack::PushL(cmdLine);
    1.86 +   
    1.87 +   TPtr cmdLinePtr(cmdLine->Des());
    1.88 +   User::CommandLine(cmdLinePtr);
    1.89 +   
    1.90 +   const TInt KMaxNumTokens = 2; 
    1.91 +   TPtrC tokens[KMaxNumTokens];
    1.92 +   TLex lex(cmdLinePtr);
    1.93 +   TInt i;
    1.94 +   for (i = 0; !lex.Eos() && i < KMaxNumTokens; i++)
    1.95 +      {
    1.96 +      tokens[i].Set(lex.NextToken());
    1.97 +      }
    1.98 +
    1.99 +   TInt numTokens = i;
   1.100 +   if (numTokens == 1)
   1.101 +	   {        
   1.102 +	   DeleteFileL(tokens[0]);    
   1.103 +	   }
   1.104 +   else 
   1.105 +   if (numTokens == 2)
   1.106 +	   {
   1.107 +	   if (tokens[0][0]=='-')
   1.108 +		   {
   1.109 +		   User::LeaveIfError(ParseSwitch(tokens[0].Right(tokens[0].Length()-1),tokens[1]));
   1.110 +		   }
   1.111 +	   else
   1.112 +		   {
   1.113 +		   CopyFileL(tokens[0],tokens[1]);
   1.114 +		   }
   1.115 +	   }
   1.116 +
   1.117 +   CleanupStack::PopAndDestroy(cmdLine);	
   1.118 +}
   1.119 +
   1.120 +TInt E32Main()
   1.121 +   {    
   1.122 +   CTrapCleanup* cleanup = CTrapCleanup::New();
   1.123 +
   1.124 +   TRAPD(err, ::DoMainL());	
   1.125 +   
   1.126 +
   1.127 +   delete cleanup;
   1.128 +   
   1.129 +   return(err);
   1.130 +   }
   1.131 +