added copy links from file hierarchy

This commit is contained in:
csoler 2017-10-18 22:32:15 +02:00
parent f98edd400e
commit e1d5014288
4 changed files with 74 additions and 10 deletions

View File

@ -30,15 +30,63 @@ FileTree *FileTree::create(const std::string& radix64_string)
return ft ;
}
static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,void *ref)
void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote)
{
if(ft.mDirs.size() <= index)
ft.mDirs.resize(index+1) ;
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;i<dd.children.size();++i)
if(rsFiles->RequestDirDetails(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) ;
}
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) ;
}
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;
}
FileTree *FileTree::create(void *ref)
bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const
{
if(index >= mDirs.size())
return false ;
subdirs = mDirs[index].subdirs ;
subfiles.clear() ;
for(uint32_t i=0;i<mDirs[index].subfiles.size();++i)
subfiles.push_back(mFiles[mDirs[index].subfiles[i]]);
return true ;
}
FileTree *FileTree::create(const DirDetails& dd, bool remote)
{
FileTreeImpl *ft = new FileTreeImpl ;
recurs_buildFileTree(*ft,0,ref) ;
FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote) ;
return ft ;
}
@ -81,16 +129,12 @@ bool FileTreeImpl::deserialise(unsigned char *buffer,uint32_t buffer_size)
if(FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY,node_section_data,node_section_size))
{
std::string file_name ;
uint64_t file_size ;
RsFileHash file_hash ;
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ,mFiles[i].name )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ) ;
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,mFiles[i].size )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ) ;
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH,mFiles[i].hash )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH) ;
mTotalFiles++ ;
mTotalSize += file_size ;
mTotalSize += mFiles[i].size ;
}
else
throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY) ;

View File

@ -15,6 +15,8 @@ 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);
struct DirData {
std::string name;
std::vector<uint32_t> subdirs ;
@ -22,4 +24,6 @@ protected:
};
std::vector<FileData> mFiles ;
std::vector<DirData> mDirs ;
friend class FileTree ;
};

View File

@ -144,7 +144,7 @@ class FileTree
public:
virtual ~FileTree() {}
static FileTree *create(void *ref) ;
static FileTree *create(const DirDetails& dd, bool remote) ;
static FileTree *create(const std::string& radix64_string) ;
virtual std::string toRadix64() const =0 ;
@ -160,6 +160,8 @@ public:
virtual uint32_t root() const { return 0;}
virtual bool getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const = 0;
virtual void print() const=0;
uint32_t mTotalFiles ;
uint64_t mTotalSize ;
};

View File

@ -511,7 +511,8 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ;
contextMnu.addAction( downloadAct) ;
if ( type == DIR_TYPE_FILE ) {
//if ( type == DIR_TYPE_FILE )
{
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addAction( copylinkAct) ;
contextMnu.addAction( sendlinkAct) ;
@ -572,6 +573,18 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
if (details.type == DIR_TYPE_DIR)
{
FileTree *ft = FileTree::create(details,remote) ;
std::cerr << "Created collection file tree:" << std::endl;
ft->print();
RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()), details.count,QString::fromStdString(ft->toRadix64())) ;
if(link.valid())
urls.push_back(link) ;
delete ft ;
#ifdef TO_REMOVE
for(uint32_t j=0;j<details.children.size();++j)
{
const DirStub& dirStub = details.children[j];
@ -594,6 +607,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
urls.push_back(link) ;
}
}
#endif
}
else
{