EXPORT_C TInt CTestConfig::ResolveFile(RFs& aFs, const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut)
	{
	TFileName* savedPath = new TFileName;
	TFileName* fileName = new TFileName;
	if ((savedPath == NULL) || (fileName == NULL))
		{
		delete savedPath;
		delete fileName;
		return KErrNoMemory;
		}

	fileName->Append(KScriptPathSep);
//	fileName->Append(KSmsTestFileInputBase);
//	fileName->Append(KScriptPathSep);
	fileName->Append(aComponent);
	fileName->Append(KScriptPathSep);
	fileName->Append(aFileName);
	
	// file finder will look in the session drive first, then Y->A,Z
	// so set session drive to Y (save old and restore it afterwards)
	aFs.SessionPath(*savedPath);
	_LIT(KTopDrive,"Y:\\");
	aFs.SetSessionPath(KTopDrive);
    TFindFile file_finder(aFs);
    TInt err = file_finder.FindByDir(*fileName,KNullDesC);
	if(err==KErrNone)
		aParseOut.Set(file_finder.File(),NULL,NULL);
	aFs.SetSessionPath(*savedPath);
	delete savedPath;
	delete fileName;
	return(err);
	}
Example #2
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);
	}
EXPORT_C void CIAUpdateXmlParser::ParsePrivateFileL( 
    const TDesC& aFileName )
    {
    RFs fsSession;	
    User::LeaveIfError( fsSession.Connect() );
    CleanupClosePushL( fsSession );

    // This will set the correct drive and private path 
    // for the file server session.    
    SetPrivateDriveL( fsSession, aFileName );

	TFileName configFilePath;    
    User::LeaveIfError( fsSession.SessionPath( configFilePath ) );
    configFilePath.Append( aFileName );
    
    CleanupStack::PopAndDestroy( &fsSession );    

    ParseFileL( configFilePath );    
    }
void CIAUpdateXmlParser::SetPrivateDriveL( 
    RFs& aFs,
    const TDesC& aFileName ) const
    {
    IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() begin: %S", 
                     &aFileName);
    
    // This will set the correct drive and private path 
    // for the file server session.    

    // First try to find the file from the private directory
    // of the drive where the process exists.
    RProcess process;

    // Set the session private path according to 
    // the process file name drive.
    TInt driveNum( 
        SetSessionPrivatePathL( aFs, process.FileName() ) );

    // Get the session path that was set above.
    IAUPDATE_TRACE_1("[IAUPDATE] Find file: %d", driveNum);
    TFileName sessionPath;
    User::LeaveIfError( aFs.SessionPath( sessionPath ) );
    IAUPDATE_TRACE_1("[IAUPDATE] Session path: %S", &sessionPath);

    // Use the file finder to check if the file actually exists 
    // in the given drive path. If it does not, the file finder 
    // will automatically check from other drives. So, here we 
    // should always find the file if any exists.
    TFindFile finder( aFs );
    User::LeaveIfError( finder.FindByDir( aFileName, sessionPath ) );

    // The drive may have changed if the file was not found from
    // the first suggested drive. So, be sure to have the correct
    // private path.
    driveNum = SetSessionPrivatePathL( aFs, finder.File() );

    // Use the drive info to check if the drive is ROM drive.
    // We prefer non ROM drives. But, accept ROM if nothing else is
    // available.
    IAUPDATE_TRACE_1("[IAUPDATE] Check ROM info: %d", driveNum);
    TDriveInfo info;
    User::LeaveIfError( aFs.Drive( info, driveNum ) );
    TBool isRomDrive( info.iDriveAtt & KDriveAttRom );
    if ( !isRomDrive )
        {
        // The current file is not in ROM drive so use that.
        IAUPDATE_TRACE("[IAUPDATE] First file search done. Non ROM found.");
        IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
        return;
        }

    // Because previous finding was ROM file, try to find a non ROM file.
    IAUPDATE_TRACE("[IAUPDATE] Try to find non ROM file.");
    TInt findErrorCode( finder.Find() );
    if ( findErrorCode == KErrNotFound )
        {
        // Because no new file is found, use the current settings.
        IAUPDATE_TRACE("[IAUPDATE] Second search done. No file found.");
        IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
        return;
        }
    User::LeaveIfError( findErrorCode );

    IAUPDATE_TRACE("[IAUPDATE] New file found. Use that.");
    // Update the session path for the correct file.
    SetSessionPrivatePathL( aFs, finder.File() );

    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
    }
// --------------------------------------------------------------------------
// CUPnPFileSharingEngine::StoreSharedContainerIDsL
// Creates main containers and starts sharing them
// --------------------------------------------------------------------------
//
TInt CUpnpSelectionWriter::StoreSharedContainerIDsL() const
    {
    __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );

    // Leave if aIdArray = NULL
    if ( !iFileArray )
        {
        User::Leave(KErrArgument);
        }

    RFs fs;
    RFile file;
    User::LeaveIfError( fs.Connect() );
    CleanupClosePushL(fs);

    TFileName directory;

    // Get private directory path
    fs.SessionPath(directory);

    // Try to create directory
    TInt error = fs.MkDir(directory);
    // it's ok if directory already exists
    if (!(error != KErrNone && error != KErrAlreadyExists))
        {

        // Add file name
        if ( iMediaType == EImageAndVideo )
            {
            directory.Append( KVisualFile );
            }
        else if ( iMediaType == EPlaylist )
            {
            directory.Append( KMusicFile );
            }

        error = file.Replace(fs, directory, EFileWrite );
        if ( !error )
            {
            CleanupClosePushL( file );
            RFileWriteStream writeStream(file);
            CleanupClosePushL( writeStream );

            for (TInt index = 0; index < iFileArray->Count(); index++)
                {
                // check that sharing of the container was succesful
                if ( iOkItems.Find( index ) != KErrNotFound )
                    {
                    // Write identifiers to the file
                    writeStream << iFileArray->MdcaPoint(index);
                    }
                }

            // Clean up
            CleanupStack::PopAndDestroy(&writeStream); // Close writeStream
            CleanupStack::PopAndDestroy(&file); // Close file
            }
        }
    CleanupStack::PopAndDestroy(&fs);
    __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
    return error;
    }
// ---------------------------------------------------------------------------
// CLbtCleanupHandler::ReadCleanupDataFromFileL
// ---------------------------------------------------------------------------
//
void CLbtCleanupHandler::ReadCleanupDataFromFileL()
	{
	FUNC_ENTER("CLbtCleanupHandler::ReadCleanupDataFromFileL");
	
	// First reset the cleanup data 
	iCleanupItems.ResetAndDestroy();
	
	// Open handle to file system
	RFs fs;
	User::LeaveIfError(fs.Connect());
	
	CleanupClosePushL(fs);
	
	// Obtain the file path
    TFileName file;
    
    // Gets the path in which the file can be created
    fs.SessionPath(file);

    // Create the file Directory ie the private directory of the process
    fs.MkDirAll(file);
    
    // Append the name of the file
    file.Append(KLbtAppCleanupFileName);
    
    // Open read stream
    RFileReadStream readStream;
    
    TInt error = readStream.Open( fs, file, EFileRead );
    if( error != KErrNone )
    	{
    	// File may not exists
    	ERROR("Opening of cleanup file failed with : %d", error);
    	readStream.Close();
    	CleanupStack::PopAndDestroy(); //fs
    	return;
    	}
    CleanupClosePushL( readStream );
    
    // Get the count in the cleanup array
    TInt count = readStream.ReadInt16L();    
    for(TInt i=0; i<count; ++i)
    	{
    	RArray<TLbtTriggerId> triggers;
    	CleanupClosePushL(triggers);
    	
    	// Read the trigger ids
    	TInt triggerCount = readStream.ReadInt16L();
    	for(TInt j=0;j<triggerCount;++j)
    		{
    		triggers.Append( readStream.ReadUint32L() );
    		}
    	
    	// Read the universal time
    	TInt year = readStream.ReadInt32L();
    	TMonth month = static_cast<TMonth>( readStream.ReadInt32L() );
    	TInt day = readStream.ReadInt32L();
    	
    	TDateTime dateTime( year,
    						month,
    						day,
    						0,
    						0,
    						0,
    						0 );
    	TTime time( dateTime );
    	
    	CLbtCleanupItem* cleanupItem = new (ELeave) CLbtCleanupItem();
    	cleanupItem->AddCleanupItem( triggers, time );
    	
    	CleanupStack::Pop(); // triggers
    	triggers.Close();
    	
    	// Append cleanup item to the cleaup items array
    	iCleanupItems.Append( cleanupItem );
    	}

    CleanupStack::PopAndDestroy(2); // fs and readStream
	}
// ---------------------------------------------------------------------------
// CLbtCleanupHandler::WriteCleanupDataToFileL
// ---------------------------------------------------------------------------
//
void CLbtCleanupHandler::WriteCleanupDataToFileL()
	{
	FUNC_ENTER("CLbtCleanupHandler::WriteCleanupDataToFileL");	
	
	RFs fs;
	User::LeaveIfError( fs.Connect() );
	
	CleanupClosePushL( fs );
    
    // Obtain the file path
    TFileName file;
    
    // Gets the path in which the file can be created
    fs.SessionPath(file);

    // Create the file Directory ie the private directory of the process
    fs.MkDirAll(file);
    
    // Append the name of the file
    file.Append(KLbtAppCleanupFileName);
    
    // Open write stream to write to the file
    RFileWriteStream writeStream;
    
    // Open the file to replace the contents. If the file is not preset
    // this method will create the file
    TInt error = writeStream.Replace( fs, file, EFileWrite );    
    if( error != KErrNone )
    	{
    	ERROR("Opening of cleanup file failed with : %d", error);
    	writeStream.Close();
    	CleanupStack::PopAndDestroy(); //fs
    	User::Leave(error);
    	}
    CleanupClosePushL( writeStream );
    
    // First write the number of cleanup items
    writeStream.WriteInt16L( iCleanupItems.Count() );

	for(TInt i=0;i<iCleanupItems.Count();++i)
		{
		RArray<TLbtTriggerId>& triggers = iCleanupItems[i]->GetTriggers();
		
		// Write the trigger ids into the file
		writeStream.WriteInt16L( triggers.Count() );
		for(TInt j=0;j<triggers.Count();++j)
			{
			writeStream.WriteUint32L( triggers[j] );
			}
		
		// Write the time into the file
		const TDateTime dateTime = iCleanupItems[i]->GetTime().DateTime();
		
		// Write the year
		writeStream.WriteInt32L( dateTime.Year() );
		
		// Write the month
		writeStream.WriteInt32L( dateTime.Month() );
		
		// Write the day
		writeStream.WriteInt32L( dateTime.Day() );
		}
    
    CleanupStack::PopAndDestroy(2); //fs and writeSteam    
	}