Managing Files

Applications can use the ContentAccess::CManager class to manage files.

Introduction

Some agents may choose to store content files inside their server private directories. In the file system the private directories have the following format:

\private\<process SID>\protectedfile.ext

If an agent want to publish the existence of its private directory, it specify the name of the private directory (the SecureID of the process) in the opaque_data section of the agent's ECom resource file. See Content Access Agent ECOM Resource File.

CAF maps the path to the agent name, so that it is human-readable. For example:

\private\<agent_name>\protectedfile.ext

The agents can advertise the existence of files to applications through their implementation of the ContentAccess::CAgentManager::GetDir() function. When an application opens a file stored in the private directory, CAF selects the agent which handles that content based upon the name in the path. If the file is not stored in a private directory, CAF checks each of the agents whether they support the file. If no agent supports the file, it reads as plaintext using F32Agent.

Required background

Before you start, you must understand:

Procedure

  1. Create a manager object using the CManager::NewL() function.

  2. Perform one or more of the following tasks as per your requirement:

    • Copy a file

    • Move or rename a file

    • Delete a file

    • Create a directory

    • List the contents of a directory

    • Find the real MIME type of the file

    • Get the attributes of the content object

    • Remove a directory

Copy a file

ContentAccess::CManager::CopyFile() allows a user to make a copy of the file. For example, the user may wish to make a copy of the file onto removable media. When copying content managed by a DRM agent, the agent only copies the content, it does not copy the rights.
// create a manager object
CManager *manager = CManager::NewL();

// Use the manager to copy a file
TInt result = manager->CopyFile(source, destination);

Move or rename a file

ContentAccess::CManager::RenameFile() allows a user to move or rename a file. For example, the user may wish to move the file to removable media.
TInt result = manager->RenameFile(oldFilename, newFilename);

Delete a file

ContentAccess::CManager::DeleteFileL() allows a client to delete a specified file managed by a DRM agent.

The agent responsible for the content can display a dialog to confirm that the user wants to delete the file. This is particularly important if the content still has valid rights.

The agent implementation must decide whether to delete the rights or only the content.

TFileName filename;

// Use the manager to delete a file
// CAF asks the agent which actually owns the file to delete it.
TInt result = manager->DeleteFile(filename);

Create a directory

ContentAccess::CManager::MkDir() allows a user to create a directory.

TInt result = manager->MkDir(fullpath);

If one or more of the sub-directories do not exist they are created too using the ContentAccess::CManager::MkDirAll() function.

TInt result = manager->MkDirAll(fullpath);

List the contents of a directory

There are three variations of the ContentAccess::CManager::GetDir() function. They each allow a client to list the contents of an agent's private directory.

As mentioned earlier, it is optional for agents to provide this information.

CDir *aDir;
TInt result = manager->GetDir (aName, aEntryAttMask, aEntrySortKey, aDir);

Find the real MIME type of the file

The CAF Apparc recognizer provides a MIME type that is a combination of the file MIME type and the content within the file. In some cases, such as forwarding DRM content to another device, it is important to make sure the content is sent with the correct MIME type.

Using the "" empty string UniqueId allows an application to determine the MIME type of the file.

TBuf <256> mimeType;
TInt result = manager->GetStringAttribute(EMimeType, mimeType, TVirtualPathPtr(aURI,KNullDesC16()));

Get the attributes of the content object

The CManager API allows applications to retrieve attributes or string attributes from a content object as described in Content Object Attributes.

Remove a directory

ContentAccess::CManager::RmDir() allows a user to remove a directory.

TInt result = manager->RmDir(fullpath);