sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile) sl@0: { sl@0: RFs fs; sl@0: fs.Connect(); sl@0: CleanupClosePushL(fs); sl@0: fs.MkDirAll(aDestFile); sl@0: CFileMan* fileMan = CFileMan::NewL( fs ); sl@0: // Copy feature file to file manager private data cage. sl@0: //Ignore any errors as the file or path may not exist sl@0: fileMan->Copy(aSourceFile, aDestFile); sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: } sl@0: sl@0: void DeleteFileL(const TDesC& aFile) sl@0: { sl@0: RFs fs; sl@0: fs.Connect(); sl@0: CleanupClosePushL(fs); sl@0: fs.SetAtt(aFile, 0, KEntryAttReadOnly); sl@0: //Ignore any errors as the file or path may not exist sl@0: fs.Delete( aFile ); sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: sl@0: } sl@0: sl@0: TInt CheckFile(const TDesC& aFile) sl@0: { sl@0: RFs fs; sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt err = file.Open(fs,aFile,EFileRead); sl@0: if (err!=KErrNotFound) sl@0: { sl@0: file.Close(); sl@0: fs.Close(); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: fs.Close(); sl@0: return KErrNotFound; sl@0: } sl@0: } sl@0: sl@0: TInt ParseSwitch(const TDesC& aSwitch, const TDesC& aFile) sl@0: { sl@0: if (aSwitch==_L("?")) sl@0: return CheckFile(aFile); sl@0: else sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: static void DoMainL() sl@0: { sl@0: HBufC* cmdLine = HBufC::NewL(User::CommandLineLength()); sl@0: CleanupStack::PushL(cmdLine); sl@0: sl@0: TPtr cmdLinePtr(cmdLine->Des()); sl@0: User::CommandLine(cmdLinePtr); sl@0: sl@0: const TInt KMaxNumTokens = 2; sl@0: TPtrC tokens[KMaxNumTokens]; sl@0: TLex lex(cmdLinePtr); sl@0: TInt i; sl@0: for (i = 0; !lex.Eos() && i < KMaxNumTokens; i++) sl@0: { sl@0: tokens[i].Set(lex.NextToken()); sl@0: } sl@0: sl@0: TInt numTokens = i; sl@0: if (numTokens == 1) sl@0: { sl@0: DeleteFileL(tokens[0]); sl@0: } sl@0: else sl@0: if (numTokens == 2) sl@0: { sl@0: if (tokens[0][0]=='-') sl@0: { sl@0: User::LeaveIfError(ParseSwitch(tokens[0].Right(tokens[0].Length()-1),tokens[1])); sl@0: } sl@0: else sl@0: { sl@0: CopyFileL(tokens[0],tokens[1]); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(cmdLine); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: TRAPD(err, ::DoMainL()); sl@0: sl@0: sl@0: delete cleanup; sl@0: sl@0: return(err); sl@0: } sl@0: