diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 8a1f11fc5..92ee6a362 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -1,5 +1,6 @@ #include #include +#include #include "file_sharing_defaults.h" #include "filelist_io.h" @@ -30,12 +31,16 @@ FileTree *FileTree::create(const std::string& radix64_string) return ft ; } -void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote) +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) ; - ft.mDirs[index].name = dd.name ; + 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(); @@ -62,7 +67,7 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di 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) ; + recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote,remove_top_dirs) ; } else std::cerr << "(EE) Unsupported DirDetails type." << std::endl; @@ -86,11 +91,11 @@ bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vec return true ; } -FileTree *FileTree::create(const DirDetails& dd, bool remote) +FileTree *FileTree::create(const DirDetails& dd, bool remote,bool remove_top_dirs) { FileTreeImpl *ft = new FileTreeImpl ; - FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote) ; + FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote,remove_top_dirs) ; return ft ; } diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index 5f94bdf48..8aaa9dff6 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -19,7 +19,7 @@ public: protected: void recurs_print(uint32_t index,const std::string& indent) const; - static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote); + static void recurs_buildFileTree(FileTreeImpl& ft, uint32_t index, const DirDetails& dd, bool remote, bool remove_top_dirs); struct DirData { std::string name; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 64af23885..d7efb2937 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -144,7 +144,7 @@ class FileTree public: virtual ~FileTree() {} - static FileTree *create(const DirDetails& dd, bool remote) ; + static FileTree *create(const DirDetails& dd, bool remote, bool remove_top_dirs = true) ; static FileTree *create(const std::string& radix64_string) ; virtual std::string toRadix64() const =0 ;