本文整理汇总了C++中FSPath::Count方法的典型用法代码示例。如果您正苦于以下问题:C++ FSPath::Count方法的具体用法?C++ FSPath::Count怎么用?C++ FSPath::Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FSPath
的用法示例。
在下文中一共展示了FSPath::Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FSArch
clPtr<FS> clArchPlugin::OpenFS( clPtr<FS> Fs, FSPath& Path ) const
{
FSString Uri = Fs->Uri( Path );
struct archive* Arch = ArchOpen( Uri.GetUtf8() );
if ( Arch == nullptr )
{
return nullptr;
}
FSArchNode RootDir;
RootDir.fsStat.mode = S_IFDIR;
FSPath NodePath;
struct archive_entry* entry = archive_entry_new2( Arch );
int Res;
while ( ( Res = archive_read_next_header2( Arch, entry ) ) == ARCHIVE_OK )
{
NodePath.Set( CS_UTF8, archive_entry_pathname( entry ) );
FSString* ItemName = NodePath.GetItem( NodePath.Count() - 1 );
if ( NodePath.Count() == 1 && ( ItemName->IsDot() || ItemName->IsEmpty() ) )
{
// skip root dir
continue;
}
const mode_t Mode = archive_entry_mode( entry );
const int64_t Size = archive_entry_size( entry );
RootDir.entryOffset += Size;
FSStat ItemStat;
ItemStat.mode = S_ISREG( Mode ) ? Mode : S_IFDIR;
ItemStat.size = Size;
ItemStat.m_CreationTime = archive_entry_ctime( entry );
ItemStat.m_LastAccessTime = archive_entry_atime( entry );
ItemStat.m_LastWriteTime = archive_entry_mtime( entry );
ItemStat.m_ChangeTime = ItemStat.m_LastWriteTime;
FSArchNode* Dir = ArchGetParentDir( &RootDir, NodePath, ItemStat );
FSArchNode* Item = Dir->Add( FSArchNode( ItemName->GetUtf8(), ItemStat ) );
if (Item) {
Item->entryOffset = archive_read_header_position( Arch );
}
}
if ( Res != ARCHIVE_EOF )
{
dbg_printf( "Couldn't read archive entry: %s\n", archive_error_string( Arch ) );
}
archive_entry_free( entry );
ArchClose( Arch );
return new FSArch( RootDir, Uri );
}
示例2: Copy
bool OperCFThread::Copy(FS *srcFs, FSPath &__srcPath, FSList *list, FS *destFs, FSPath &__destPath, cstrhash<bool,unicode_t> &resList)
{
if (list->Count()<=0) return true;
FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
FSPath destPath = __destPath; int destPos = destPath.Count();
FSStat st;
int ret_error;
int res = destFs->Stat(__destPath, &st, &ret_error, Info());
if (res == -2) return false;
if (res && !destFs->IsENOENT(ret_error))
{
RedMessage( _LT("Can't copy to:\n"), destFs->Uri(destPath).GetUtf8(), bOk, destFs->StrError(ret_error).GetUtf8());
return false;
}
bool exist = (res == 0);
if (list->Count()>1)
{
//если файлов >1 то копировать можно только в каталог
if (!exist) {
RedMessage( _LT("Can't copy files, destination is not found:\n"), destFs->Uri(__destPath).GetUtf8(), bOk);
return false;
}
if (!st.IsDir())
{
RedMessage( _LT("Destination is not directory:\n"), destFs->Uri(__destPath).GetUtf8(), bOk);
return false;
}
for (FSNode *node = list->First(); node; node = node->next)
{
if (Info()->Stopped()) return false;
srcPath.SetItemStr(srcPos, node->Name());
destPath.SetItemStr(destPos, node->Name());
if (!CopyNode(srcFs, srcPath, node, destFs, destPath, false)) return false;
resList[node->Name().GetUnicode()] = true;
}
} else {
// 1 element
if (exist && st.IsDir())
destPath.SetItemStr(destPos, list->First()->Name());
srcPath.SetItemStr(srcPos, list->First()->Name());
if (!CopyNode(srcFs, srcPath, list->First(), destFs, destPath, false)) return false;
resList[list->First()->Name().GetUnicode()] = true;
};
return true;
}
示例3: Move
bool OperCFThread::Move(FS *srcFs, FSPath &__srcPath, FSList *list, FS *destFs, FSPath &__destPath)
{
if (list->Count()<=0) return true;
FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
FSPath destPath = __destPath; int destPos = destPath.Count();
FSStat st;
int ret_error;
int r = destFs->Stat(__destPath, &st, &ret_error, Info());
if (r == -2) return false;
if (list->Count()>1)
{
//если файлов >1 то копировать можно только в каталог
if (r) {
RedMessage( _LT("Can't move files, bad destination directory:\n"), destFs->Uri(__destPath).GetUtf8(), bOk, destFs->StrError(ret_error).GetUtf8());
return false;
}
if (!st.IsDir())
{
RedMessage( _LT("Destination is not directory:\n"), destFs->Uri(__destPath).GetUtf8(), bOk);
return false;
}
for (FSNode *node = list->First(); node; node = node->next)
{
srcPath.SetItemStr(srcPos, node->Name());
destPath.SetItemStr(destPos, node->Name());
//printf("MOVE '%s'\n", srcPath.GetUtf8());
if (!MoveNode(srcFs, srcPath, node, destFs, destPath)) return false;
}
} else {
// 1 element
if (r && !destFs->IsENOENT(ret_error))
{
RedMessage( _LT("Can't move to:\n"), destFs->Uri(destPath).GetUtf8(), bOk, destFs->StrError(ret_error).GetUtf8());
return false;
}
if (!r && st.IsDir())
destPath.SetItemStr(destPos, list->First()->Name());
FSNode *node = list->First();
srcPath.SetItemStr(srcPos, list->First()->Name());
if (!MoveNode(srcFs, srcPath, list->First(), destFs, destPath)) return false;
}
return true;
}
示例4: MkDir
int FSTmp::MkDir(FSPath& path, int mode, int* err, FSCInfo* info)
{
FSPath parentPath;
parentPath.Copy(path, path.Count() - 1);
FSTmpNode* parent = rootDir.findByFsPath(&parentPath);
if (!parent)
return SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);
FSTmpNode* parentDir = parent;
FSTmpNode fsTmpNode(path.GetItem(path.Count() - 1)->GetUnicode(), parentDir);
parentDir->Add(&fsTmpNode);
return SetError(err, 0);
}
示例5: stripPathFromLastItem
static void stripPathFromLastItem(FSPath& path)
{
FSString* lastItem = path.GetItem(path.Count() - 1);
if (lastItem)
{
const unicode_t* lastU = lastItem->GetUnicode();
const unicode_t* lastDelim = unicode_strrchr(lastU, DIR_SPLITTER);
if (lastDelim != 0)
{
path.SetItemStr(path.Count() - 1,FSString(lastDelim + 1));
}
}
}
示例6: Stat
int FSSys::Stat( FSPath& path, FSStat* fsStat, int* err, FSCInfo* info )
{
if ( _drive >= 0 && path.Count() == 1 || _drive == -1 && path.Count() == 3 )
{
//pseudo stat
fsStat->size = 0;
fsStat->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
fsStat->mode = S_IFDIR;
fsStat->mtime = 0;
fsStat->mode |= 0664;
return 0;
}
WIN32_FIND_DATAW ent;
HANDLE handle = FindFirstFileW( SysPathStr( _drive, path.GetUnicode() ).data(), &ent );
if ( handle == INVALID_HANDLE_VALUE )
{
SetError( err, GetLastError() );
return -1;
}
try
{
fsStat->size = ( seek_t( ent.nFileSizeHigh ) << 32 ) + ent.nFileSizeLow;
fsStat->dwFileAttributes = ent.dwFileAttributes;
fsStat->mtime = ent.ftLastWriteTime;
if ( ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
fsStat->mode = S_IFDIR;
}
else
{
fsStat->mode = S_IFREG;
}
fsStat->mode |= 0664;
FindClose( handle );
return 0;
}
catch ( ... )
{
FindClose( handle );
throw;
}
//...
SetError( err, 50 );
return -1;
}
示例7: Copy
void FSPath::Copy(const FSPath& a, int elementCount)
{
cacheCs = -2;
data.clear();
if (elementCount<0 || elementCount>a.Count())
elementCount = a.Count();
for (int i = 0; i < elementCount; i++)
{
FSString s;
s.Copy(a.data.const_item(i));
data.append(s);
}
}
示例8: DeleteListRecursively
bool DeleteListRecursively( FS* fs, FSPath path, FSList& list )
{
const int cnt = path.Count();
int ret_err;
for ( FSNode* node = list.First(); node; node = node->next )
{
if ( node->extType )
{
continue;
}
path.SetItemStr( cnt, node->Name() );
if ( node->IsDir() && !node->st.IsLnk() )
{
if ( !DeleteDirRecursively( fs, path ) )
{
return false;
}
}
else if ( fs->Delete( path, &ret_err, nullptr ) != 0 )
{
return false;
}
}
return true;
}
示例9: Delete
int FSTmp::Delete(FSPath& path, int* err, FSCInfo* info)
{
FSString* dName = path.GetItem(path.Count() - 1);
FSTmpNode* n = rootDir.findByName(dName);
if (n == 0)
{
return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);;
}
else
{
/*
if (n->nodeType == FSTmpNode::NODE_FILE)
{ // remove file at base FS
int ret = baseFS->Delete(n->baseFSPath, err, info);
if (ret != 0)
return ret;
}
*/
// remove from tmpfs list
for (auto it = n->parentDir->content.begin(); it != n->parentDir->content.end(); ++it)
{
if ((*it).name.Cmp(*dName) == 0)
{
n->parentDir->content.erase(it);
return FS::SetError(err, 0);
}
}
return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);;
}
}
示例10: CreateDirectory
void OperCFThread::CreateDirectory( FS* fs, FSPath& srcPath, FSPath& destPath, bool processMultipleFolders )
{
if ( processMultipleFolders )
{
const int DirIndex = srcPath.GetFirstUnmatchedItem( destPath );
FSPath Path;
for ( int i = 0; i < destPath.Count(); i++ )
{
// get next dir
Path.PushStr( *destPath.GetItem( i ) );
int ret_err;
// try to create dir
if ( i >= DirIndex && fs->MkDir( Path, 0777, &ret_err, Info() ) )
{
// skip "already exists" error
if ( !fs->IsEEXIST( ret_err ) )
{
throw_msg( "%s", fs->StrError( ret_err ).GetUtf8() );
}
}
}
}
else
{
int ret_err;
if ( fs->MkDir( destPath, 0777, &ret_err, Info() ) )
{
throw_msg( "%s", fs->StrError( ret_err ).GetUtf8() );
}
}
}
示例11: ParzeLink
bool ParzeLink( FSPath& path, FSString& link )
{
FSPath t( link );
if ( !path.IsAbsolute() && !t.IsAbsolute() ) { return false; } //не абсолютный путь
int first = 0;
if ( t.IsAbsolute() )
{
path.Clear();
path.PushStr( FSString( "" ) );
first = 1;
}
for ( int i = first; i < t.Count(); i++ )
{
FSString p = *( t.GetItem( i ) );
if ( p.IsDot() ) { continue; }
if ( p.Is2Dot() )
{
if ( path.Count() > 1 ) { path.Pop(); }
}
else
{
path.PushStr( p );
}
}
return true;
}
示例12: DeleteList
bool OperCFThread::DeleteList( FS* fs, FSPath& _path, FSList& list )
{
if ( Info()->Stopped() ) { return false; }
FSPath path = _path;
int cnt = path.Count();
for ( FSNode* node = list.First(); node; node = node->next )
{
if ( node->extType ) { continue; }
path.SetItemStr( cnt, node->Name() );
if ( node->IsDir() && !node->st.IsLnk() )
{
if ( !DeleteDir( fs, path ) ) { return false; }
if ( !RmDir( fs, path ) ) { return false; }
continue;
}
if ( !DeleteFile( fs, path ) ) { return false; }
}
return true;
}
示例13: CopyDir
bool OperCFThread::CopyDir(FS *srcFs, FSPath &__srcPath, FSNode *srcNode, FS *destFs, FSPath &__destPath, bool move)
{
if (Info()->Stopped()) return false;
FSList list;
int ret_error;
while (true) {
int ret = srcFs->ReadDir(&list, __srcPath, &ret_error, Info());
if (ret == -2) return false;
if (!ret) break;
switch ( RedMessage( _LT("Can`t open directory:\n") , srcFs->Uri(__srcPath).GetUtf8(), bRetrySkipCancel, srcFs->StrError(ret_error).GetUtf8()) ) {
case CMD_SKIP: return true;
case CMD_RETRY: continue;
default: return false;
}
}
while (destFs->MkDir(__destPath, MkDirMode, &ret_error, Info()) && !destFs->IsEEXIST(ret_error)) {
switch (RedMessage( _LT("Can't create the directory:\n"), destFs->Uri(__destPath).GetUtf8(), bRetrySkipCancel, destFs->StrError(ret_error).GetUtf8())) {
case CMD_CANCEL: return false;
case CMD_SKIP: return true;
}
}
FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
FSPath destPath = __destPath; int destPos = destPath.Count();
for (FSNode *node = list.First(); node; node = node->next)
{
if (Info()->Stopped()) return false;
srcPath.SetItemStr(srcPos, node->Name());
destPath.SetItemStr(destPos, node->Name());
if (!CopyNode(srcFs, srcPath, node, destFs, destPath, move)) return false;
}
destFs->SetFileTime(destPath, srcNode->st.mtime, srcNode->st.mtime, 0, Info());
return !move || RmDir(srcFs, __srcPath);
}
示例14: Rename
int FSTmp::Rename(FSPath& oldpath, FSPath& newpath, int* err, FSCInfo* info)
{
FSTmpNode* n = rootDir.findByName(oldpath.GetItem(oldpath.Count() - 1));
if (n == 0)
{
return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);
}
else
{
if (n->nodeType == FSTmpNode::NODE_FILE)
{
int ret = baseFS->Rename(n->baseFSPath, newpath, err, info);
if (ret != 0)
return ret;
n->name = newpath.GetUnicode();
return SetError(err, 0);
}
else
{// XXX ??? add case when new and old path are in different dirs
((FSTmpNode*)(n))->name = *newpath.GetItem(newpath.Count() - 1);
return SetError(err, 0);
}
}
}
示例15: RmDir
int FSTmp::RmDir(FSPath& path, int* err, FSCInfo* info)
{
FSTmpNode* n = rootDir.findByFsPath(&path);
FSString* dirName = path.GetItem(path.Count() - 1);
for (auto it = n->parentDir->content.begin(); it != n->parentDir->content.end(); ++it)
{
if ((*it).name.Cmp(*dirName) == 0)
{
n->parentDir->content.erase(it);
return FS::SetError(err, 0);
}
}
return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);
}