void CTcFileHandlerSession::DoCopyFileL( const RMessage2& aMessage ) const
    {
    TFileName sourcePath;
    ReadFileNameL( 0, aMessage, sourcePath );
    
    TFileName destinationPath;
    ReadFileNameL( 1, aMessage, destinationPath );
   	
    RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL( fs );
	
	CFileMan* fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan); 
	
	// Make sure path exists, ignore errors since path might exist already
	fs.MkDirAll( destinationPath );	
	
	// Make the destination file writeable, ignore errors since most probably
	// file doesn't exist yet
    fileMan->Attribs( destinationPath, 0, KEntryAttReadOnly, TTime( 0 ), 0 );
    
	User::LeaveIfError( fileMan->Copy( sourcePath, destinationPath ) );
    
	CleanupStack::PopAndDestroy( 2 ); // fileMan, fs
    }
void CJavaDebugAgentSettings::SaveL(const TDesC& aPrefsFile) const
{
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFileWriteStream out;
    out.PushL();
    TInt err = out.Create(fs, aPrefsFile, EFileWrite);
    if (err != KErrNone) {
        // Try to eliminate the problem if we can
        switch (err) {
        case KErrAlreadyExists:
            fs.Delete(aPrefsFile);
            break;
        case KErrPathNotFound:
            fs.MkDirAll(aPrefsFile);
            break;
        default:
            User::Leave(err);
            break;
        }
        User::LeaveIfError(out.Create(fs, aPrefsFile, EFileWrite));
    }

    SaveL(&out);
    out.Close();
    out.Pop();
    CleanupStack::PopAndDestroy(&fs);
}
/**
 @fn void WriteIniFileL()
 Open the ini file and store the values
 */
LOCAL_C void WriteIniFileL()
	{
	RFs fileSession;
	User::LeaveIfError(fileSession.Connect());
	CleanupClosePushL(fileSession);
	
	// create folder path
	fileSession.MkDirAll(IniFileName);
	
	RFileWriteStream fileWriteStream;
	User::LeaveIfError(fileWriteStream.Create(fileSession, IniFileName ,EFileWrite));
	CleanupClosePushL(fileWriteStream);
	
	//write the KEComUid to the stream
	fileWriteStream.WriteInt32L(KEComUid);
	
	//write the KSsaUid to the stream
	fileWriteStream.WriteInt32L(KSsaUid);
	
	//write the SSA value to the stream
	fileWriteStream.WriteInt8L(KSsaDisabled);
	
	//commit changes to the stream
	fileWriteStream.CommitL();

	// close: fileSession, fileWriteStream
	CleanupStack::PopAndDestroy(2);
	}
Esempio n. 4
0
//================================================================================
//convertPathL
//================================================================================
void convertPathL(TDesC& aPath, TDesC& aPathName, RFs& aFs, TDesC& aTargetFile)
	{
	aFs.MkDirAll(aPathName);

	CDir* entryList = NULL;
	TInt error = aFs.GetDir(aPath,KEntryAttMatchMask,ESortByName,entryList);
	User::LeaveIfError(error);

	TInt numberOfFiles = entryList->Count();
	for (TInt i=0; i<numberOfFiles; i++)
		{
		//get the source file
		HBufC* temp=HBufC::NewLC(((*entryList)[i].iName).Length());
		TPtr sourceFileName(temp->Des());
		sourceFileName.Copy((*entryList)[i].iName);

		HBufC* temp2=HBufC::NewLC(((*entryList)[i].iName).Length()+aPathName.Length());
		TPtr sourceFile(temp2->Des());
		sourceFile = aPathName;
		sourceFile.Append(sourceFileName);
		//do the conversion
		synchronousL(sourceFile, aTargetFile);
		//output result
		_LIT(KString,"%S");
		test.Printf(KString,&(sourceFileName));
		test.Printf(_L("\n"));
		CleanupStack::PopAndDestroy(2);//temp, temp2
		}

	delete entryList;
	test.Printf(_L("\n%d files converted\n"),numberOfFiles);
	}
void CCreateFileCertStore::CreateStoreL(const TDesC& aFileName, RFs& aFs)
	{
	aFs.MkDirAll(aFileName);
	RFile file;
	User::LeaveIfError(file.Replace(aFs, aFileName, EFileWrite));

	//TCleanupItem deleteFile(CFileCertStore::DeleteFile, this);//store will revert() if a leave occurs
	//CleanupStack::PushL(deleteFile);

	CPermanentFileStore* store = CPermanentFileStore::NewLC(file);
	store->SetTypeL(KPermanentFileStoreLayoutUid);	

	RStoreWriteStream caCertEntryStream;
	TStreamId caCertEntryStreamId = caCertEntryStream.CreateLC(*store);
	caCertEntryStream.WriteInt32L(0);//we have zero ca certs
	caCertEntryStream.CommitL();
	CleanupStack::PopAndDestroy();

	RStoreWriteStream rootStream;
	TStreamId rootId = rootStream.CreateLC(*store);

	rootStream << caCertEntryStreamId;
	rootStream.CommitL();
	CleanupStack::PopAndDestroy();
	
	store->SetRootL(rootId);							
	store->CommitL();							
	CleanupStack::PopAndDestroy();//store
	}
Esempio n. 6
0
TInt E32Main()
	{
	TInt r;

	 // Turn off lazy dll unloading
	RLoader l;
	if ((r=l.Connect())!=KErrNone)
		return r;
	r = l.CancelLazyDllUnload();
	l.Close();
	if (r!=KErrNone)
		return r;
	
	r = ParseCommandLine();
	if(r!=KErrNone)
		return r;
	r = Fs.Connect();
	if(r!=KErrNone)
		return r;
	r = Fs.MkDirAll(DestinationName.FullName());
	if(r==KErrNone || r==KErrAlreadyExists)
		r = DoIt();
	Fs.Close();
	return r;
	}
void CCmdCustomCommand::WriteHandleToFileL(TInt aHandle)
	{
	const TChar sysDrive = RFs::GetSystemDriveChar();
	RBuf filename;
	filename.CreateL(KNeverUnloadLibHandleFile().Length() + 1);
	filename.Append(sysDrive);
	filename.Append(KNeverUnloadLibHandleFile());
	filename.CleanupClosePushL();
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);

	fs.MkDirAll(filename); // ignore any error
	RFile file;
	CleanupClosePushL(file);
	TInt err=KErrNone;
	TInt pos = 0;
	if(KErrNotFound == (err = file.Open(fs, filename, EFileShareExclusive|EFileStream|EFileWrite)))
		{
		User::LeaveIfError(file.Replace(fs, filename, EFileShareExclusive|EFileStream|EFileWrite));
		}
	else
		{
		User::LeaveIfError(err);
		file.Seek(ESeekEnd, pos);
		}
	RFileWriteStream targetStream;
	targetStream.Attach(file, pos); // file gets closed by this call, but that's okay, we don't need it any more (targetStream has its own copy of this RFile object that it owns)
	CleanupClosePushL(targetStream);
	targetStream.WriteInt32L(aHandle);
	targetStream.CommitL();
	CleanupStack::PopAndDestroy(4); 
	}
// Actual implementation of method
TInt CMMFAacDecoderConfig::SetAudioConfig(TAudioConfig& aAudioConfig)
	{
	RFs		fs;
	RFile	file;
	TInt	err = KErrNone;

	if ( KErrNone != (err = fs.Connect()) )
		{
		return err;
		}

	// this file name will be use on the testStep to compare the stored value.	
	_LIT(KFileName, "c:\\temp\\aacDecoderConfig.txt");
	fs.MkDirAll(KFileName);

	if ( KErrNone != (err = file.Replace(fs, KFileName, EFileWrite)) )
		{
		return err;	
		}

	TBuf8<4> Line;
	Line.Format(_L8("%02d"), aAudioConfig.iAudioObjectType);

	file.Write(Line);
	file.Close();
	fs.Close();

	return err;
	}
void CreateTestEnv()
    {
	TInt err = TheFs.Connect();
	TheTest(err == KErrNone);
	
	err = TheFs.MkDirAll(TheTestFile);
	TEST(err == KErrNone || err == KErrAlreadyExists);
	}
Esempio n. 10
0
// ---------------------------------------------------------------------------
// CGbaServer::EnsurePathL()
// ---------------------------------------------------------------------------
//
void CGbaServer::EnsurePathL( RFs& aFs, const TDesC& aFile ) const
{
    TInt err = aFs.MkDirAll(aFile);
    if (err != KErrNone && err != KErrAlreadyExists)
    {
        User::Leave(err);
    }
}
Esempio n. 11
0
void MakeDir(const TDesC& aDirName)
//
// Make a directory
//
	{
	TInt r=TheFs.MkDirAll(aDirName);
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
	}
Esempio n. 12
0
LOCAL_C TInt MakeFileName(TInt aThreadId, TInt aFileNumber, RFs & aFs, TFileName& aName, TBool aMakeDir)
//
// creates a file name and makes all the directory components, if required
//
	{
	
	TFileName path;
	path.Format(KPath, aThreadId);
	
	TChar driveLetter;
	TInt  r;
	r = aFs.DriveToChar(gDriveNumber, driveLetter);
	if (r != KErrNone)
		{
		LogError(r, KDriveToChar, KNullDesC, driveLetter, 0);
		aFs.Close();
		return(r);
		}
		
	path[0] = (TText) driveLetter;
	r = aFs.SetSessionPath(path);
	if (r != KErrNone)
		{
		LogError(r, KSetSessPath, path, 0, 0);
		aFs.Close();
		return(r);
		}
		
	// add additional directories
	TInt fileNumber;
	fileNumber = aFileNumber;
	r = AppendPath(path, fileNumber, 0);
	if(r != KErrNone)
		{
		LogError(r, KAppendPath, path, fileNumber, 0);
		aFs.Close();
		return(r);
		}
		
	if(aMakeDir)
		{
		r = aFs.MkDirAll(path);
		if (r != KErrNone && r != KErrAlreadyExists)
			{
			LogError(r, KMdAll, path, 0, 0);
			aFs.Close();
			return(r);
			}
		}
		
	// and finally add file name
	path.Append(KFilePrefix);
	path.AppendNum(aFileNumber);

	aName = path;
	return(KErrNone);
	}
Esempio n. 13
0
// -----------------------------------------------------------------------------
// CreateDataBasePath
// Create database with client side database access
// -----------------------------------------------------------------------------
//
LOCAL_C TInt CreateDataBasePath(RFs& aFs)
{
#ifdef _DRM_TESTING
    TRAPD(r,WriteL(_L8("CreateDataBasePath")));
#endif

    TInt err = 0;

#ifndef RD_MULTIPLE_DRIVE

    err = aFs.MkDirAll( DataFile(). DriveAndPath() );

#else //RD_MULTIPLE_DRIVE

    err = aFs.MkDirAll( DataFile( aFs ). DriveAndPath() );

#endif

    return err;
}
Esempio n. 14
0
void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile)
{
   RFs fs;
   fs.Connect();
   CleanupClosePushL(fs);
   fs.MkDirAll(aDestFile);
   CFileMan* fileMan = CFileMan::NewL( fs );
   // Copy feature file to file manager private data cage.
   //Ignore any errors as the file or path may not exist
   fileMan->Copy(aSourceFile, aDestFile);   
   CleanupStack::PopAndDestroy(&fs);
   }
Esempio n. 15
0
void CreateTestDirectory(const TDesC& aSessionPath)
//
// Create directory for test
//
	{
	TParsePtrC path(aSessionPath);
	test(path.DrivePresent()==EFalse);
	TInt r=TheFs.SetSessionPath(aSessionPath);
	test_KErrNone(r);
	r=TheFs.SessionPath(gSessionPath);
	test_KErrNone(r);
	r=TheFs.MkDirAll(gSessionPath);
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
	}
static TInt EnvCreate()
    {
    TInt err = theFs.Connect();
    if(err == KErrNone)
        {
        err = theFs.MkDirAll(KLogEngPrivatePath);
        if(err == KErrAlreadyExists)
            {
            err = KErrNone; 
            }
        }
    if(err != KErrNone)
        {
        RDebug::Print(_L("** t_logHiCapHelper, error %d creating test environment\r\n"), err);
        }
    return err;
    }
void PosLmUnzipUtil::ExtractFileL(RFs& aFs, CZipFileMember* aMember, CZipFile* aZipFile, TFileName* aFileName) 
{
	TInt loop=0;
	HBufC* name = aMember->Name()->AllocLC();
	// Change any instances of '/' to '\' in zipped file paths
	while (loop < name->Length()) 
	{
		if ((*name)[loop] == '/') 
		{
			name->Des()[loop] = '\\';
		}
		loop++;
	}
	//set target path
	TBuf<KMaxDirName> privatePath;
	aFs.PrivatePath(privatePath);
	TFileName fn;
	fn.Append(privatePath);
	fn.Append(KExtractZipPath);
	fn.Append(*name);
	
	//create target path if not exist.
	TInt err = aFs.MkDirAll(fn);
	if (err != KErrNone && err != KErrAlreadyExists) 
	{
		User::Leave(err);
	}
	RFile expandedMember;
	User::LeaveIfError(expandedMember.Replace(aFs, fn, EFileShareAny|EFileWrite));
	CleanupClosePushL(expandedMember);
	RZipFileMemberReaderStream* fileStream; 
	
	// KCompressionMethodNotSupported is possible in decompressing file here
	User::LeaveIfError(aZipFile->GetInputStreamL(aMember, fileStream));
	CleanupStack::PushL(fileStream); 
	
	// Assume file contents are 8-bit data
	TUint32 size = aMember->UncompressedSize();
	HBufC8* bytes = HBufC8::NewLC(size);
	TPtr8 ptr = bytes->Des(); //Obtain a modifiable descriptor
	fileStream->Read(ptr, size); 
	// save the unzipped contents to file
	User::LeaveIfError(expandedMember.Write(ptr));
	expandedMember.Close();
	CleanupStack::PopAndDestroy(4); //bytes, fileStream, expandedMember, name
}
void IntegrityRestoreFileL(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, 
								RLoader& /*aLoader*/, CFileMan& /*aFileMan*/)
	{
	RBuf name;
	name.CreateL(aPath, KMaxFileName);
	CleanupClosePushL(name);
	name.Append(aLeaf->Name());

	// find the peer file, and check it's a backup.
	CIntegrityTreeLeaf* peer = aLeaf->Peer();
	if (peer->Type() != EBackupFile)
		{
		User::Leave(KErrCorrupt);
		}
	
	TParsePtrC parse(peer->Journal());
	RBuf backup;
	backup.CreateL(parse.DriveAndPath(), KMaxFileName);
	CleanupClosePushL(backup);
	backup.Append(parse.Name());
	backup.Append(KPathDelimiter);
	backup.Append(peer->Name());

	TInt err = aFs.MkDirAll(name);
	if(err != KErrNone && err != KErrAlreadyExists)
		{
		User::Leave(err);
		}
			
	err = aFs.Rename(backup, name);
	if (err != KErrNone)
		{
		VerifyDeletionErrorL(err);
		// we may have already moved it back during a previous recovery
		// attempt, check for its presence in the original location
		TEntry restoredEntry;
		User::LeaveIfError(aFs.Entry(name, restoredEntry));
		}
	else
		{
		// prune the backup directory tree if possible.
		RemoveDirectoryTreeL(aFs, backup);
		}
	CleanupStack::PopAndDestroy(2, &name);	// backup
	}
Esempio n. 19
0
void CTestAutoMMCReaderStep::OpenMMCCardReaderDrive()
	{
	INFO_PRINTF1(_L("Testing fix for INC040672 - MMC Card door open causes wrong mime type instead of error code"));
	
	_LIT(KValidFileName, "ValidFileName.jpg");
		
	RFs fs;
	TInt ret = fs.Connect();
	TEST(ret == KErrNone);
	RTestableApaLsSession ls;
	ret = ls.Connect();
	TEST(ret == KErrNone);
		
//	The following steps are to reproduce the removal of MMC card
// 	Loop through drive letters Y -> D to access a file on that drive (any filename)
//	Find a drive letter that returns KErrNotReady , 
//	setup a valid filename with that drive. 

	for (TInt drive = EDriveY; drive >= EDriveD ; drive--)
		{
		TDriveUnit driveUnit(drive);	
		TDriveName driveName = driveUnit.Name();

		TBuf<KDirLength> bufDirName(driveName);
		bufDirName.Append(_L("\\"));
		
		ret = fs.MkDirAll(bufDirName);
		if (ret == KErrNotReady)
			{
			TFileName bufValidFileName(bufDirName);
			bufValidFileName.Append(KValidFileName);
			TDataType dataType;
			TUid uid = KNullUid;
			
			HEAP_TEST_LS_SESSION(ls, 0, 0, ret = ls.AppForDocument(bufValidFileName, uid, dataType), NO_CLEANUP);
			TEST(ret == KErrNotReady);
			TEST(uid == KNullUid);
			TEST(dataType == TDataType());
			break;
			}
		}
	TEST(ret == KErrNotReady);
	ls.Close();
	fs.Close();
	}
Esempio n. 20
0
void CScrHelperSession::GetFileHandleL(RFs& aFs, const RMessage2& aMessage, const TDesC& aFileName)
	{
	DEBUG_PRINTF2(_L("Returning file handle of %S."), &aFileName);
	RBuf filePath;
	filePath.CreateL(aFileName.Length());
	filePath.CleanupClosePushL();
	filePath.Copy(aFileName);
	filePath[0] = aFs.GetSystemDriveChar();
	TInt err = aFs.MkDirAll(filePath);
	if(KErrNone != err && KErrAlreadyExists != err)
		{
		DEBUG_PRINTF3(_L("An error (%d) occured while making all directories of %S."), err, &filePath);
		User::Leave(err);
		}
	
	RFile file;
	TEntry entry;

	if(KErrNone == aFs.Entry(filePath, entry))
		{ // The file exists, just open it.
		User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite));
		}    
	else
		{ // The file doesn't exist. First, check if the requested file is database or journal file.
		if(KScrDatabaseFilePath() == aFileName)
			{ // This is the database file. Copy the default one into the requested location.
			DEBUG_PRINTF(_L8("SCR database file doesn't exist. It is being copied from ROM"));
			CopyDbFromROMToSystemL(aFs, filePath);
			 // Then, open the file.
			User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite));
			}
		else
			{ // This is the journal file, simply create an empty file.
			User::LeaveIfError(file.Create(aFs, filePath, EFileShareAny|EFileWrite));
			}
		}
	CleanupStack::PopAndDestroy(&filePath);
	CleanupClosePushL(file);
	
	// Store the RFile handle into the package buffer in slot 0 and complete the message with the RFs handle
	User::LeaveIfError(file.TransferToClient(aMessage, 0));
	ASSERT(aMessage.IsNull());  // The message should have been completed

	CleanupStack::PopAndDestroy(&file);
	}
/**
 * Creates a file and copies the data in the source file to the destination file. 
 */
TInt RTestStepOggCtrlBase::CopyFile(TPtrC aFileNameSrc, TPtrC aFileNameDst)
	{
	TInt theErr = KErrNone;
	RFs		fs;
	fs.Connect();
	RFile	theFileNew;
	RFile	theFile;

	fs.MkDirAll(aFileNameDst);
	theFile.Open(fs, aFileNameSrc, EFileShareReadersOnly);
	TInt	theSize;
	theFile.Size(theSize);
	
	TBuf8<KSizeBuf>	theBuf;
	TInt	theStep = KSizeBuf;
	if(theStep > theSize)
		{
		theStep = theSize;
		}
	TInt theRes = theFileNew.Create(fs, aFileNameDst, EFileShareAny);
	if(theRes == KErrAlreadyExists)
		{
		theRes = theFileNew.Replace(fs, aFileNameDst, EFileShareAny);	
		}
	if(theRes != KErrNone)
		{
		return theRes;	
		}
	TInt	theCurLength = 0;
	while(theCurLength < theSize)
		{
		theFile.Read(theBuf, theStep);
		theFileNew.Write(theBuf, theStep);
		theCurLength += theStep;
		if(theCurLength + theStep > theSize )
			{
			theStep = theSize - theCurLength;
			}
		}
	theFileNew.Close();
	theFile.Close();
	fs.Close();
	return theErr;
	}
Esempio n. 22
0
void TRepositoryCacheManagerTester::InstallIniFileL( TBorderTestStage aFileSet )
	{
	_LIT( KDriveC, "c:" );
	_LIT( KDriveZ, "z:" );

	TBuf<KMaxFileName> src1;
	TBuf<KMaxFileName> dest1;
	TInt r;

	DeleteFilesL();

	CFileMan* fm = CFileMan::NewL( iFs );
	CleanupStack::PushL( fm );

	if ((aFileSet>=ELastStage)||(aFileSet<0))
		{
		RDebug::Print( _L( "Illegal parameter to function: %d\r\n" ), aFileSet );
		TheTest( EFalse, __LINE__ );
		}
	else
		{
		dest1.Copy( KDriveC );
		dest1.Append( KCacheMgrIniFileFolder );
		dest1.Append( KCacheMgrIniFile );
		r = fm->Delete( dest1 );
		if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
			User::Leave( r );
		r = iFs.MkDirAll( dest1 );
		if ( r != KErrNone && r != KErrAlreadyExists )
			User::Leave( r );
		src1.Copy( KDriveZ );
		src1.Append( KCacheMgrIniFileFolder );
		src1.Append( KCacheMgrIniSrcFile );
		TBuf<2> testNo;
		testNo.Num(aFileSet);
		src1.Append( testNo );
		User::LeaveIfError( fm->Copy( src1, dest1 ) );
		r = fm->Attribs( dest1, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
		TEST2( r, KErrNone );
		}

	CleanupStack::PopAndDestroy( fm );
	}
Esempio n. 23
0
void MakeFile(const TDesC& aFileName,TInt anAttributes)
//
// Make a file and write something in it
//
	{
	RFile file;
	TInt r=file.Replace(TheFs,aFileName,0);
	test_Value(r, r == KErrNone || r==KErrPathNotFound);
	if (r==KErrPathNotFound)
		{
		r=TheFs.MkDirAll(aFileName);
		test_KErrNone(r);
		r=file.Replace(TheFs,aFileName,0);
		test_KErrNone(r);
		}
	file.Close();
	r=TheFs.SetAtt(aFileName,anAttributes,0);
	test_KErrNone(r);
	}
Esempio n. 24
0
void CAppMain::ThreadMainL(){
  CActiveScheduler* activeScheduler=new (ELeave) CActiveScheduler();
  CleanupStack::PushL(activeScheduler);
  CActiveScheduler::Install(activeScheduler);
  RFs fs;
  fs.Connect();
  fs.MkDirAll(KAppFolder);
  fs.Close();
  Log(_L8("Application started\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^"),0);
  
#ifdef __THIRDPARTY_PROTECTED__
  CreateProcess(KINIT_PROTECTED_APP_NAME);
  User::After(5*1000*1000);
#endif
  
  CAppMain::NewLC();
  CActiveScheduler::Start();
  CleanupStack::PopAndDestroy(activeScheduler);
  Log(_L8("CAppMain::ThreadMainL() end"));
}
Esempio n. 25
0
// Copy the files specified.
void CopyFileL(const TDesC& anOld, const TDesC& aNew)
	{	
	RFs fs;
	fs.Connect();	
	CleanupClosePushL(fs);

	CFileMan* fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan); 

	// Check if the destination directory exists, if so then delete files if they are present
	TInt err = fs.MkDirAll(aNew);	
	if (err == KErrAlreadyExists)
		{
		err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
		if ((err != KErrNone) && (err != KErrNotFound))
			{
			User::Leave(err);
			}
		else if(err == KErrNone)
			{
			User::LeaveIfError(fs.Delete(aNew));
			}
		}
	else if (err != KErrNone)
		{
		User::Leave(err);
		}

	// Make the destination file writeable 
    err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
	if ((err != KErrNone) && (err != KErrNotFound))
		{
		User::Leave(err);
		}

	// Do the file copy	
    User::LeaveIfError(fileMan->Copy(anOld, aNew));

	CleanupStack::PopAndDestroy(2); 
	}
void CTcFileHandlerSession::DoCreateFileL( const RMessage2& aMessage ) const
    {
    TFileName destinationPath;
    ReadFileNameL( 0, aMessage, destinationPath );
   	
   	HBufC8* data = ReadLC( 1, aMessage );
   	
   	RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL( fs );
	
	// Make sure path exists, ignore errors since path might exist already
	fs.MkDirAll( destinationPath );	

	RFile out;
	User::LeaveIfError( out.Replace( fs, destinationPath, 
						EFileWrite ) );
	CleanupClosePushL( out );
	User::LeaveIfError( out.Write( *data ) );
	
	CleanupStack::PopAndDestroy( 3 );	// out, fs, data
    }
void CTestMessageConverterManager::TestStartConversion()
	{
	_LIT(KFunction,"TestStartConversion");
	INFO_PRINTF1(KFunction);
	
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CFileMan* fileMngr = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMngr);
	
	TPtrC drive;
	
		// create the directories
	fs.MkDirAll(_L("D:\\private\\1000484b\\mail2\\"));
	fs.MkDirAll(_L("E:\\private\\1000484b\\mail2\\"));
		
	// cleanup mesasging.db in drive D
	TRAPD(err,fileMngr->Delete(KDbFileName));	
	MY_ASSERT_EQUALS(err, KErrNone);
	
	//copy mail2
	TRAP(err, fileMngr->Copy(KConverterMail2Folder,KMail2FolderPathD,2));
	MY_ASSERT_EQUALS(err, KErrNone);
	
	CleanupStack::PopAndDestroy(fileMngr);
	fs.Close();	
	
	_LIT(KStartMessageStoreConversionL,"Starting Conversion on Drive D, this request will be cancelled after some time so that we can resume conversion in the next step");
	INFO_PRINTF1(KStartMessageStoreConversionL);
	
	//Conversion request
	TDriveNumber driveNumber = EDriveD;
	TAny* conversionStatus = &driveNumber;
	
	_LIT(KConverterTestThread,"StartMessageStoreConversion");
	err = iConverterThread.Create(KConverterTestThread, &CMessageConverterManager::StartConversion,KDefaultStackSize*8,KMinHeapSize,0x8000000,conversionStatus,EOwnerThread);

	// Request for notification
	TRAPD(error, iConverterThread.Logon(iActiveWaiter->iStatus);)	
Esempio n. 28
0
void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
//
// Make a file and write uid and data
//
	{
	RFile file;
	TInt r=file.Replace(TheFs,aFileName,0);
	test_Value(r, r == KErrNone || r==KErrPathNotFound);
	if (r==KErrPathNotFound)
		{
		r=TheFs.MkDirAll(aFileName);
		test_KErrNone(r);
		r=file.Replace(TheFs,aFileName,0);
		test_KErrNone(r);
		}
	TCheckedUid checkedUid(aUidType);
	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(uidData);
	test_KErrNone(r);
	r=file.Write(aFileContents);
	test_KErrNone(r);
	file.Close();
	}
Esempio n. 29
0
void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
//
// Make a file and write something in it
//
	{
	RFile file;
	TInt r=file.Replace(TheFs,aFileName,0);
	if(r!=KErrNone && r!=KErrPathNotFound)
		{
		test.Printf(_L("ERROR: r=%d"),r);
		test(EFalse);
		}
	test_Value(r, r == KErrNone || r==KErrPathNotFound);
	if (r==KErrPathNotFound)
		{
		r=TheFs.MkDirAll(aFileName);
		test_KErrNone(r);
		r=file.Replace(TheFs,aFileName,0);
		test_KErrNone(r);
		}
	r=file.Write(aFileContents);
	test_KErrNone(r);
	file.Close();
	}
Esempio n. 30
0
EXPORT_C void CSTPreferences::SaveSettingsL()
{
	if (iPreferencesFileName)
	{
		LWRITELN(iLog, _L("Saving settings"));
		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		
		fs.MkDirAll(*iPreferencesFileName);
		
		RFile file;
		if (file.Replace(fs, *iPreferencesFileName, EFileWrite) == KErrNone)
		{
			LWRITELN(iLog, _L("Settings file replaced"));
			CleanupClosePushL(file);
			
			// DownloadPath
			SaveSettingL(file, KSettingDownloadPath, *iDownloadPath);
			
			// AccessPointName
			SaveSettingL(file, KSettingAccesPointName, *iAccessPointName);
			
			// AccessPointId
			{
				TBuf<16> accesPointId;
				accesPointId.Num(TInt(iAccessPointId));
				SaveSettingL(file, KSettingAccesPointId, accesPointId);	
			}
			
			// Right softkey mode	
			{
				TBuf<16> rsmBuf;
				rsmBuf.Num(TInt(iRightSoftkeyMode));
				SaveSettingL(file, KSettingRightSoftkeyMode, rsmBuf);	
			}
			
			// IncomingPort
			{
				TBuf<16> portBuf;
				portBuf.Num(IncomingPort());
				SaveSettingL(file, KSettingIncomingPort, portBuf);	
			}	
			
			#ifdef EKA2
			// TrackerServicePort
			{
				TBuf<16> trackerBuf;
				trackerBuf.Num(TrackerServicePort());
				SaveSettingL(file, KSettingTrackerServicePort, trackerBuf);	
			}

			// PieceSize
			{
				TBuf<16> pieceBuf;
				pieceBuf.Num(PieceSize());
				SaveSettingL(file, KSettingPieceSize, pieceBuf);	
			}
			
			// DHTEnabled
			{
				if (IsDHTEnabled())
					SaveSettingL(file, KSettingDHTEnabled, _L("1"));	
				else
					SaveSettingL(file, KSettingDHTEnabled, _L("0"));
			}
			#endif
			
			// CloseConnectionAfterDownload
			{
				if (CloseConnectionAfterDownload())
						SaveSettingL(file, KSettingCloseConnectionAfterDownload, _L("1"));	
					else
						SaveSettingL(file, KSettingCloseConnectionAfterDownload, _L("0"));					
			}
			
			// Subpiece size	
			{
				TBuf<16> spsBuf;
				spsBuf.Num(iSubpieceSize);
				SaveSettingL(file, KSettingSubpieceSize, spsBuf);	
			}
				
			// ProxyServicePort
			{
				TBuf<16> servicePortBuf;
				servicePortBuf.Num(iProxyServicePort);
				SaveSettingL(file, KSettingProxyServicePort, servicePortBuf);	
			}
			
			// ProxyConnectionPort
			{
				TBuf<16> connPortBuf;
				connPortBuf.Num(iProxyConnectionPort);
				SaveSettingL(file, KSettingProxyConnectionPort, connPortBuf);	
			}
			
			// ProxyHostName
			SaveSettingL(file, KSettingProxyHostName, ProxyHostName());
			
			// IncomingConnectionsMode
			{
				TBuf<16> icmBuf;
				icmBuf.Num(TInt(iIncomingConnectionsMode));
				SaveSettingL(file, KSettingIncomingConnectionsMode, icmBuf);	
			}
			
			// IsUploadEnabled
			{
				if (iIsUploadEnabled)
					SaveSettingL(file, KSettingUploadEnabled, _L("1"));	
				else
					SaveSettingL(file, KSettingUploadEnabled, _L("0"));
			}
			
			// StartupHashCheck
			{
				if (StartupHashCheck())
					SaveSettingL(file, KSettingStartupHashCheck, _L("1"));	
				else
					SaveSettingL(file, KSettingStartupHashCheck, _L("0"));
			}		

					
			for (TInt i=0; i<iSTorrents->Count(); i++)
				SaveSettingL(file, KSettingSTorrent, (*iSTorrents)[i]);
			
			file.Write(KLit8EndLine);
			CleanupStack::PopAndDestroy(); // file
		}
		else
			LWRITELN(iLog, _L("Failed to replace settings file"));
		
		CleanupStack::PopAndDestroy(); // fs	
	}
}