Merge pull request #1261 from PhenomRetroShare/Add_RsCollAutoDownload

Add RsCollection's content automatically download option.
This commit is contained in:
G10h4ck 2019-02-13 22:22:56 -03:00 committed by GitHub
commit 164a28eb32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 166 additions and 68 deletions

View file

@ -86,6 +86,46 @@ void RsCollection::downloadFiles() const
RsCollectionDialog(_fileName, colFileInfos, false).exec() ;
}
void RsCollection::autoDownloadFiles() const
{
QDomElement docElem = _xml_doc.documentElement();
std::vector<ColFileInfo> colFileInfos;
recursCollectColFileInfos(docElem,colFileInfos,QString(),false);
QString dlDir = QString::fromUtf8(rsFiles->getDownloadDirectory().c_str());
foreach(ColFileInfo colFileInfo, colFileInfos)
{
autoDownloadFiles(colFileInfo, dlDir);
}
}
void RsCollection::autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const
{
if (!colFileInfo.filename_has_wrong_characters)
{
QString cleanPath = dlDir + colFileInfo.path ;
std::cout << "making directory " << cleanPath.toStdString() << std::endl;
if(!QDir(QApplication::applicationDirPath()).mkpath(cleanPath))
std::cerr << "Unable to make path: " + cleanPath.toStdString() << std::endl;
if (colFileInfo.type==DIR_TYPE_FILE)
rsFiles->FileRequest(colFileInfo.name.toUtf8().constData(),
RsFileHash(colFileInfo.hash.toStdString()),
colFileInfo.size,
cleanPath.toUtf8().constData(),
RS_FILE_REQ_ANONYMOUS_ROUTING,
std::list<RsPeerId>());
}
foreach(ColFileInfo colFileInfoChild, colFileInfo.children)
{
autoDownloadFiles(colFileInfoChild, dlDir);
}
}
static QString purifyFileName(const QString& input,bool& bad)
{
static const QString bad_chars = "/\\\"*:?<>|" ;

View file

@ -85,6 +85,8 @@ public:
// Download the content.
void downloadFiles() const ;
// Auto Download all the content.
void autoDownloadFiles() const ;
qulonglong size();
@ -102,6 +104,8 @@ private:
void recursCollectColFileInfos(const QDomElement&,std::vector<ColFileInfo>& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ;
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this
static bool checkFile(const QString &fileName, bool showError);
// Auto Download recursively.
void autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const ;
QDomDocument _xml_doc ;
QString _fileName ;

View file

@ -639,7 +639,7 @@ void RsCollectionDialog::updateSizes()
uint64_t total_size = 0 ;
uint32_t total_count = 0 ;
for(uint32_t i=0;i<ui._fileEntriesTW->topLevelItemCount();++i)
for(int i=0;i<ui._fileEntriesTW->topLevelItemCount();++i)
{
total_size += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_SIZE ,ROLE_SELSIZE ).toULongLong();
total_count += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_FILEC,ROLE_SELFILEC).toULongLong();