chxavfilestore.cpp
来自「著名的 helix realplayer 基于手机 symbian 系统的 播放」· C++ 代码 · 共 1,202 行 · 第 1/3 页
CPP
1,202 行
{
cchRequired += 1; // account for folder suffix that will need to be added
}
return cchRequired <= KMaxFileName;
}
////////////////////////////////////////////////////////////
//
// Allocate full path (file or folder) for given item in
// current path
//
// idxItem - index to an existing item (folder or file)
//
TFileName* CHXAvFileStore::AllocFullPathL(TInt idxItem)
{
HX_ASSERT(idxItem < m_entryInfo.Nelements());
const TEntry& entry = m_entryInfo[idxItem].m_entry;
// allocate fully qualified file or folder name
TFileName* pPath = CHXAvFile::AllocFileNameL(GetFullPath(),
entry.iName, (entry.IsDir() ? CHXAvFile::ntFolder : CHXAvFile::ntFile) );
return pPath;
}
////////////////////////////////////////////////////////////
//
// Allocate full destination path (file or folder) matching
// the given item
//
// targetPath - absolute or relative target folder path
// idxItem - index to an existing item (folder or file)
// targetName - name of target file or folder; zero-length indicates
// use same name as file/folder at given index in current folder
//
//
TFileName* CHXAvFileStore::AllocFullTargetPathL(const TDesC& targetPath,
TInt idxItem, const TDesC& targetName)
{
HX_ASSERT(idxItem < m_entryInfo.Nelements());
const TEntry& entry = m_entryInfo[idxItem].m_entry;
CHXAvFile::NameType type = ( entry.IsDir() ? CHXAvFile::ntFolder : CHXAvFile::ntFile );
TFileName* pPath = 0;
if( 0 == targetName.Length() )
{
// no target name, use same name
pPath = AllocFullPathL(targetPath, entry.iName, type);
}
else
{
pPath = AllocFullPathL(targetPath, targetName, type);
}
return pPath;
}
////////////////////////////////////////////////////////////
//does file or folder matching name associated with item exist in target path
//
// path - relative to root or absolute (if drive specified)
// idxItem - index of item in _current_ folder path
//
//
bool CHXAvFileStore::NameExistsInTargetPathL(const TDesC& targetPath, TInt idxItem)
{
// alloc full file path matching the name associated with the given entry index
HX_ASSERT(idxItem < m_entryInfo.Nelements());
const TEntry& entry = m_entryInfo[idxItem].m_entry;
return NameExistsInTargetPathL(targetPath, entry.iName);
}
////////////////////////////////////////////////////////////
// does file or folder exist with given name in path
//
// * use before moving/renaming an item to the target folder
//
// path - relative to root or absolute (if drive specified)
// name - file or folder name (ok to have folder trailing slash)
//
//
bool CHXAvFileStore::NameExistsInTargetPathL(const TDesC& targetPath, const TDesC& name)
{
// alloc full file path matching the name associated with the given entry index
TFileName* pName = AllocFullPathL(targetPath, name, CHXAvFile::ntFile);
AUTO_PUSH_POP_DEL(pName);
// see if file with given name exists
bool bExists = CHXAvFile::PathExists(*pName);
if( !bExists )
{
// see if folder with given name exists
CHXAvFile::EnsureFolderSuffix(*pName);
bExists = CHXAvFile::PathExists(*pName);
}
return bExists;
}
////////////////////////////////////////////////////////////
// does file or folder (specified) matching name associated with item exists in target path
//
// return true if target path has folder or file having same name
// as entry at given index idxItem in current path
//
bool CHXAvFileStore::NameExistsInTargetPathL(const TDesC& targetPath, TInt idxItem, CHXAvFile::NameType type)
{
HX_ASSERT(idxItem < m_entryInfo.Nelements());
const TEntry& entry = m_entryInfo[idxItem].m_entry;
return PathExistsL(targetPath, entry.iName, type);
}
////////////////////////////////////////////////////////////
// does path exist as file or folder (specified or dedecude based on name)
//
// return true if target path has file or folder having given name
//
bool CHXAvFileStore::PathExistsL(const TDesC& targetPath, const TDesC& name, CHXAvFile::NameType type)
{
TFileName* pName = AllocFullPathL(targetPath, name, type);
AUTO_PUSH_POP_DEL(pName);
return CHXAvFile::PathExists(*pName);
}
////////////////////////////////////////////////////////////
//
TInt CHXAvFileStore::MoveItemL(TInt idxItem,
const TDesC& newName,
bool bAllowOverwrite, bool bRename)
{
return MoveItemL(idxItem, KNullDesC, newName, bAllowOverwrite, bRename);
}
////////////////////////////////////////////////////////////
// move item
//
// return:
// KErrNone if file is moved;
// KErrDiskFull if insufficient space on target
//
// idxItem - index of item in current folder path
// targetPath - relative to root or absolute (or KNullDesC to move within current path, i.e., rename)
// targetName - new name for file or folder;
// for folders, trailing '\' optional
// bRename - uses underlying rename api; doesn't check disk space for copy (probably no difference from move)
//
TInt CHXAvFileStore::MoveItemL(TInt idxItem,
const TDesC& targetPath,
const TDesC& targetName,
bool bAllowOverwrite, bool bRename)
{
// source path
TFileName* pOldPath = AllocFullPathL(idxItem);
AUTO_PUSH_POP_DEL(pOldPath);
// target path
TFileName* pNewPath = 0;
if( targetPath.Length() != 0 )
{
pNewPath = AllocFullTargetPathL(targetPath, idxItem, targetName);
}
else
{
// use current path for target
pNewPath = AllocFullTargetPathL(GetCurrentPath(), idxItem, targetName);
}
AUTO_PUSH_POP_DEL(pNewPath);
TInt err = KErrNone;
if( 0 != pOldPath->CompareF(*pNewPath)) // else, move to self - nothing to do
{
if(!bRename)
{
// see if we are moving across drives...
TInt idxDestDrive = CHXAvFile::GetDriveIndex(*pNewPath);
TInt idxSourceDrive = CHXAvFile::GetDriveIndex(*pOldPath);
if(idxDestDrive != idxSourceDrive)
{
// need to check for disk space on destination drive
err = CHXAvFile::CheckDiskSpaceForCopyL(*pOldPath, idxDestDrive);
}
}
if(KErrNone == err)
{
DPRINTF(SYMP_FILE, ("FileStore::MoveItemL(): moving '%s' -> '%s'\n", dbg::CharPtr(*pOldPath)(), dbg::CharPtr(*pNewPath)()));
TUint flag = CFileMan::ERecurse;
// clear ro attributes for source and dest
CHXAvFile::EnsureClearReadOnlyAttributeL(*pOldPath);
if(PathExistsL(*pNewPath, KNullDesC) && bAllowOverwrite)
{
flag |= CFileMan::EOverWrite;
CHXAvFile::EnsureClearReadOnlyAttributeL(*pNewPath);
}
// folder suffixes cause errors
CHXAvFile::TrimFolderSuffix(pOldPath);
CHXAvFile::TrimFolderSuffix(pNewPath);
if( bRename )
{
err = m_pFileMan->Rename(*pOldPath, *pNewPath, flag);
}
else
{
#if defined(ASYNC_COPYMOVE)
err = m_pFileMan->Move(*pOldPath, *pNewPath, flag, m_pFileOpCompletion->Status());
m_pFileOpCompletion->Activate();
#else
err = m_pFileMan->Move(*pOldPath, *pNewPath, flag);
#endif
}
DPRINTF(SYMP_FILE_UI, ("CHXAvFileStore::MoveItemL: result = %ld\n", err));
if(KErrNone == err)
{
if(PathExistsL(*pOldPath, KNullDesC))
{
DPRINTF(SYMP_FILE_UI, ("CHXAvFileStore::MoveItemL: old path still exists! deleting old item\n"));
// just in case - in case where we overwrite an existing folder the source
// folder is not deleted
HXSYM_LEAVE_IF_ERR(DeleteFileL(*pOldPath));
}
// just in case (we should get event notification from the fs watcher)
m_bNeedRefresh = true;
}
}
}
return err;
}
//////////////////////////////////
//
FileStoreOperationObserver::OperationType
FileStoreOperationObserver::TranslateFileManAction(CFileMan::TAction action)
{
if(action == CFileMan::ECopy)
{
return otCopy;
}
else if(action == CFileMan::EMove)
{
return otMove;
}
else if(action == CFileMan::ERename)
{
return otMove;
}
return otWhoCares;
}
//////////////////////////////////
// called when fileman begins a file operation
//
// called on separate thread if async fileman operations are used
//
MFileManObserver::TControl CHXAvFileStore::NotifyFileManStarted()
{
DPRINTF(SYMP_FILE, ("FileStore::NotifyFileManStarted()\n"));
FileStoreOperationObserver::OperationType type = TranslateFileManAction(m_pFileMan->CurrentAction());
if( type != FileStoreOperationObserver::otWhoCares )
{
TFileName source, dest;
m_pFileMan->GetCurrentSource(source);
m_pFileMan->GetCurrentTarget(dest);
m_cbFileOp = 0;
OnFileOpStart(type, source, dest);
}
// ECopy, EMove, EDelete, ERename, ERmDir
return EContinue;
}
//////////////////////////////////
// called when fileman completes copying a chunk of data (move, copy)
//
// called on separate thread if async fileman operations are used
//
// we can return EContinue,ERetry,EAbort,ECancel
MFileManObserver::TControl CHXAvFileStore::NotifyFileManOperation()
{
DPRINTF(SYMP_FILE, ("FileStore::NotifyFileManOperation()\n"));
MFileManObserver::TControl controlAction = EContinue;
FileStoreOperationObserver::OperationType type = TranslateFileManAction(m_pFileMan->CurrentAction());
if( type != FileStoreOperationObserver::otWhoCares )
{
TFileName source, dest;
m_pFileMan->GetCurrentSource(source);
m_pFileMan->GetCurrentTarget(dest);
TInt cbCopied = m_pFileMan->BytesTransferredByCopyStep();
m_cbFileOp += cbCopied;
bool bContinue = OnFileOpTick(type, source, dest, m_cbFileOp);
if( !bContinue )
{
controlAction = ECancel;
}
}
return controlAction;
}
//////////////////////////////////
// called when fileman completes an operation
//
// called on separate thread if async fileman operations are used
//
MFileManObserver::TControl CHXAvFileStore::NotifyFileManEnded()
{
DPRINTF(SYMP_FILE, ("FileStore::NotifyFileManEnded()\n"));
FileStoreOperationObserver::OperationType type = TranslateFileManAction(m_pFileMan->CurrentAction());
if( type != FileStoreOperationObserver::otWhoCares )
{
TFileName source, dest;
m_pFileMan->GetCurrentSource(source);
m_pFileMan->GetCurrentTarget(dest);
//TInt cbCopied = m_pFileMan->BytesTransferredByCopyStep();
OnFileOpEnd(type, KErrNone, source, dest);
}
return EContinue;
}
#if defined(ASYNC_COPYMOVE)
////////////////////////////////////////
// called when async fileman request completes
void CHXAvFileStore::OnFileOpAsyncComplete(TInt status)
{
DPRINTF(SYMP_FILE, ("FileStore::OnFileOpAsyncComplete(): status = %d\n", status));
}
////////////////////////////////////////
// called when async fileman request is cancelled
void CHXAvFileStore::OnFileOpAsyncCancel(TInt status)
{
DPRINTF(SYMP_FILE, ("FileStore::OnFileOpAsyncCancel(): status = %d\n", status));
}
////////////////////////////////////////
// called to abort/cancel async fileman request
void CHXAvFileStore::CancelAsyncFileOp()
{
DPRINTF(SYMP_FILE, ("FileStore::CancelAsyncFileOp()\n"));
if( m_pFileOpCompletion && m_pFileOpCompletion->IsActive() )
{
m_pFileOpCompletion->Cancel();
}
}
#endif // ASYNC_COPYMOVE
void CHXAvFileStore::OnFileOpStart(FileStoreOperationObserver::OperationType type, const TDesC& source, const TDesC& target)
{
DPRINTF(SYMP_FILE, ("FileStore::OnFileOpStart(): op = %d; src = '%s'; dst = '%s'\n", type, dbg::CharPtr(source)(), dbg::CharPtr(target)()));
if(m_pObserver)
{
m_pObserver->OnFileOpStart(type, source, target);
}
}
bool CHXAvFileStore::OnFileOpTick(FileStoreOperationObserver::OperationType type, const TDesC& source, const TDesC& target, TInt64 cbCopied)
{
DPRINTF(SYMP_FILE, ("FileStore::OnFileOpTick(): op = %d; src = '%s'; dst = '%s'; cb = %lu\n", type, dbg::CharPtr(source)(), dbg::CharPtr(target)(), cbCopied.Low()));
if(m_pObserver)
{
return m_pObserver->OnFileOpTick(type, source, target, m_cbFileOp);
}
return true;
}
void CHXAvFileStore::OnFileOpEnd(FileStoreOperationObserver::OperationType type, TInt err, const TDesC& source, const TDesC& target)
{
DPRINTF(SYMP_FILE, ("FileStore::OnFileOpEnd(): op = %d; err = %d, src = '%s'; dst = '%s'\n", type, err, dbg::CharPtr(source)(), dbg::CharPtr(target)()));
if(m_pObserver)
{
m_pObserver->OnFileOpEnd(type, err, source, target);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?