/******************************************************************************* * libretroshare/src/file_sharing: file_tree.cc * * * * libretroshare: retroshare core library * * * * Copyright 2018 by Retroshare Team * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program. If not, see . * * * ******************************************************************************/ #include #include #include #include "file_sharing_defaults.h" #include "filelist_io.h" #include "file_tree.h" std::string FileTreeImpl::toRadix64() const { unsigned char *buff = NULL ; uint32_t size = 0 ; serialise(buff,size) ; std::string res ; Radix64::encode(buff,size,res) ; free(buff) ; return res ; } FileTree *FileTree::create(const std::string& radix64_string) { FileTreeImpl *ft = new FileTreeImpl ; std::vector mem = Radix64::decode(radix64_string); ft->deserialise(mem.data(),mem.size()) ; return ft ; } void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote,bool remove_top_dirs) { if(ft.mDirs.size() <= index) ft.mDirs.resize(index+1) ; if(remove_top_dirs) ft.mDirs[index].name = RsDirUtil::getTopDir(dd.name) ; else ft.mDirs[index].name = dd.name ; ft.mDirs[index].subfiles.clear(); ft.mDirs[index].subdirs.clear(); DirDetails dd2 ; FileSearchFlags flags = remote?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ; for(uint32_t i=0;iRequestDirDetails(dd.children[i].ref,dd2,flags)) { if(dd.children[i].type == DIR_TYPE_FILE) { FileTree::FileData f ; f.name = dd2.name ; f.size = dd2.count ; f.hash = dd2.hash ; ft.mDirs[index].subfiles.push_back(ft.mFiles.size()) ; ft.mFiles.push_back(f) ; ft.mTotalFiles++ ; ft.mTotalSize += f.size ; } else if(dd.children[i].type == DIR_TYPE_DIR) { ft.mDirs[index].subdirs.push_back(ft.mDirs.size()); recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote,remove_top_dirs) ; } else std::cerr << "(EE) Unsupported DirDetails type." << std::endl; } else std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl; } bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const { if(index >= mDirs.size()) return false ; name = mDirs[index].name; subdirs = mDirs[index].subdirs ; subfiles.clear() ; for(uint32_t i=0;i= mDirs.size()) { std::cerr << "(EE) inconsistent FileTree structure" << std::endl; return; } std::cerr << indent << mDirs[index].name << std::endl; for(uint32_t i=0;i