chxavfileutil.h

来自「symbian 下的helix player源代码」· C头文件 代码 · 共 277 行

H
277
字号
/*****************************************************************************
 * chxavfileutil.h
 * ---------------
 *
 * Synopsis:
 * File utility namespace.
 *
 * Target:
 * Symbian OS
 *
 *
 * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
 *
 *****************************************************************************/

#ifndef _chxavfileutil_h_
#define _chxavfileutil_h_

// Helix includes...

// Includes from this project...
#include "chxavstringutils.h"
#include "chxavnamedisplaytrait.h"
#include "hxsym_filetype.h"

class TDataType;

struct IHXPreferences;

namespace CHXAvFile
{


enum NameType
{
    ntFile,
    ntFolder,
    ntUnspecified // determine either file or folder operation by presence of path suffix ('/')
};

// for GetFileNameValidity()
enum FileNameValidity
{
    nvInvalidIllegalChars,
    nvInvalidDots,
    nvTooLong,
    nvValid
};

// for GetDriveInfo()
enum DriveState
{
    dsAccessible,
    dsCorrupted,
    dsLocked,
    dsUnknown
};


// for GetDriveInfo()
struct DriveInfo
{
    DriveInfo();

    TInt            idxDrive;
    TMediaType      type;
    DriveState      state;
    bool            bVolInfoValid;
    TVolumeInfo     volInfo; 
};
/////////////////////
// ctor
inline
DriveInfo::DriveInfo()
: idxDrive(-1)
, type(EMediaUnknown)
, state(dsUnknown)
, bVolInfoValid(false)
{
}

// FileInfo
struct FileInfo {
    FileInfo()
	: m_entry(), m_type(ftUnknown) {}
    FileInfo(const TEntry& entry, const FileType& type)
	: m_entry(entry), m_type(type) {}
    TEntry m_entry;
    FileType m_type;
};

//
// parsing, forming paths
//

TFileName* AllocFileNameL(const TDesC& first, const TDesC& second, NameType type = CHXAvFile::ntFile);
TFileName* AllocFileNameL(const TDesC& path, NameType type = CHXAvFile::ntFile);
void AppendPath(TDes& path, const TDesC& name, NameType type);
void EnsureFolderSuffix(TDes& des);
void TrimFolderSuffix(TFileName* pPath);
TPtrC GetFolderPath(const TDesC& path);
TPtrC GetParentFolder(const TDesC& path);
TPtrC GetNakedPathNode(const TDesC& path);
TPtrC GetNakedName(const TDesC& path);
TPtrC GetExtension(const TDesC& path);
TPtrC GetEnsureNoFolderSuffix(const TDesC& path);
bool IsSubPath(const TDesC& parentPath, const TDesC& childPath);
bool HasFolderPrefix(const TDesC& name);
bool HasFolderSuffix(const TDesC& name);
bool HasDriveOrRootPrefix(const TDesC& path);
void EnsureFolderSuffix(TDes& des);
HBufC* AllocFileUrlL(const TDesC& path);
TFileName* AllocAppFolderPathL(const TDesC& path);
TFileName* AllocFullPrefPathL(IHXPreferences* pPrefs, const char* prefKey);



//
// filetype
//

//FileType MimeToFileType(const TDataType& mimeType);
bool IsNanoPlayerFileType(FileType type);
bool IsNanoPlayerFileType(const TDesC& fullPath);
bool IsNanoPlayerFileType(const TDesC& folderPath, const TDesC& itemName);
bool IsValidFileName(const TDesC& name);
FileNameValidity GetFileNameValidity(const TDesC& name);



//
// drive info
//
TInt GetDriveIndex(const TDesC& path);
DriveInfo GetDriveInfo(TInt idxDrive);
DriveInfo GetDriveInfo(const TDesC& path);
bool IsDriveLocked(TInt idxDrive);


//
// filesystem helpers
//
TFileName* AllocUniqueDefaultNameL(const TDesC& basePath, 
                               const TDesC& defaultName, 
                               bool bWantFolder, const CHXAvNameDisplayTrait& nameTrait);
bool PathExists(const TDesC& fullPath);
TInt GetFullPath(RFs& fs, const TDesC& path, TDes& fullPath, bool bAllowWildCard = false);
TInt CheckDiskSpaceForCopyL(const TDesC& fullPathSource, TInt idxDriveDest);
CDesCArrayFlat* AllocFolderListL(const TDesC& parentPath, bool bSorted = true);
TInt GetFileSize(const TDesC& fileName);
TInt EnsureClearReadOnlyAttributeL(const TDesC& fileName);



//
// GetFolderChildCount
//

// filter prototype
typedef bool (*PFNNanoPlayerFilterType)(const TDesC& folderPath, const TDesC& itemName);

// filters for GetFolderChildCount
bool FilterIncludeNanoPlayerFiles(const TDesC& folderPath, const TDesC& itemName);
bool FilterIncludeNoFiles(const TDesC& folderPath, const TDesC& itemName);
bool FilterIncludeAllFiles(const TDesC& folderPath, const TDesC& itemName);

template <typename FileFilter>
TInt GetFolderChildCount(const TDesC& folderPath, 
				 TInt& countOut, bool bWantFolders,
                                 FileFilter isWantedFile);

} // ns CHXAvFile

namespace CHXAvFile
{

//
//    inlines...
//

// GetFolderChildCount
inline
bool FilterIncludeNanoPlayerFiles(const TDesC& folderPath, const TDesC& itemName)
{
    return IsNanoPlayerFileType(folderPath, itemName);
}

// GetFolderChildCount
inline
bool FilterIncludeNoFiles(const TDesC& /*folderPath*/, const TDesC& /*itemName*/)
{
    return false;
}

// GetFolderChildCount
inline
bool FilterIncludeAllFiles(const TDesC& /*folderPath*/, const TDesC& /*itemName*/)
{
    return true;
}

////////////////////////////////////////////////////////
//
inline
bool IsValidFileName(const TDesC& name)
{
    return nvValid == GetFileNameValidity(name);
}

////////////////////////////////////
// return true if file type indicates a 'playable' file
inline
bool IsNanoPlayerFileType(FileType type)
{
    return type != ftFolder && type != ftUnknown;
}

////////////////////////////////////////
// return true if starts with a '\'
inline
bool HasFolderPrefix(const TDesC& name)
{
    return (name.Length() > 0) && (name[0] == KPathDelimiter);
}

////////////////////////////////////////
// return true if ends with a '\'
inline
bool HasFolderSuffix(const TDesC& name)
{
    return (name.Length() > 0) && (name[name.Length() - 1] == KPathDelimiter);
}

////////////////////////////////////////
// add trailing path delimiter if missing
inline
void EnsureFolderSuffix(TDes& des)
{
    if( !HasFolderSuffix(des) )
    {
	des.Append(KPathDelimiter);
    }
}

////////////////////////////////////////
// adjust descriptor
inline
void TrimFolderSuffix(TFileName* pPath)
{
    if(HasFolderSuffix(*pPath) )
    {
        pPath->SetLength(pPath->Length() - 1);
    }
}


inline
DriveInfo GetDriveInfo(const TDesC& path)
{
    return GetDriveInfo(GetDriveIndex(path));
}

////////////////////////////////////////////////////
//
inline
bool IsDriveLocked(TInt idxDrive)
{
    DriveInfo info = GetDriveInfo(idxDrive);
    return info.state == dsLocked;
}

} // CHXAvFile



#endif // EP_FILE_UTIL_INCLUDED

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?