mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added functionnality to complain when a download is initiated over a file already in download, or in the HD
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2055 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
fee083e6b8
commit
e70e995894
@ -611,6 +611,20 @@ bool ftController::handleAPendingRequest()
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ftController::alreadyHaveFile(const std::string& hash)
|
||||||
|
{
|
||||||
|
FileInfo info ;
|
||||||
|
|
||||||
|
// check for downloads
|
||||||
|
if(FileDetails(hash, info))
|
||||||
|
return true ;
|
||||||
|
|
||||||
|
// check for file lists
|
||||||
|
if (mSearch->search(hash, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA, info))
|
||||||
|
return true ;
|
||||||
|
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
bool ftController::FileRequest(std::string fname, std::string hash,
|
bool ftController::FileRequest(std::string fname, std::string hash,
|
||||||
uint64_t size, std::string dest, uint32_t flags,
|
uint64_t size, std::string dest, uint32_t flags,
|
||||||
@ -634,6 +648,10 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if we have the file */
|
/* check if we have the file */
|
||||||
|
|
||||||
|
if(alreadyHaveFile(hash))
|
||||||
|
return true ;
|
||||||
|
|
||||||
FileInfo info;
|
FileInfo info;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
std::list<TransferInfo>::iterator pit;
|
std::list<TransferInfo>::iterator pit;
|
||||||
@ -666,7 +684,8 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
* This is important as some guis request duplicate files regularly.
|
* This is important as some guis request duplicate files regularly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
{
|
||||||
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator dit;
|
std::map<std::string, ftFileControl>::iterator dit;
|
||||||
dit = mDownloads.find(hash);
|
dit = mDownloads.find(hash);
|
||||||
@ -741,19 +760,6 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mSearch->search(hash, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info))
|
|
||||||
{
|
|
||||||
/* have it already */
|
|
||||||
/* add in as completed transfer */
|
|
||||||
#ifdef CONTROL_DEBUG
|
|
||||||
std::cerr << "ftController::FileRequest() Matches Local File";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "\tNo need to download";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do a source search - for any extra sources */
|
/* do a source search - for any extra sources */
|
||||||
if (mSearch->search(hash, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
if (mSearch->search(hash, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
|
||||||
{
|
{
|
||||||
@ -802,7 +808,8 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
std::string savepath;
|
std::string savepath;
|
||||||
std::string destination;
|
std::string destination;
|
||||||
|
|
||||||
{ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
{
|
||||||
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
savepath = mPartialsPath + "/" + hash;
|
savepath = mPartialsPath + "/" + hash;
|
||||||
destination = dest + "/" + fname;
|
destination = dest + "/" + fname;
|
||||||
|
@ -132,6 +132,9 @@ bool FileRequest(std::string fname, std::string hash,
|
|||||||
uint64_t size, std::string dest, uint32_t flags,
|
uint64_t size, std::string dest, uint32_t flags,
|
||||||
std::list<std::string> &sourceIds);
|
std::list<std::string> &sourceIds);
|
||||||
|
|
||||||
|
/// Do we already have this file, either in download or in file lists ?
|
||||||
|
bool alreadyHaveFile(const std::string& hash) ;
|
||||||
|
|
||||||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||||
|
|
||||||
bool FileCancel(std::string hash);
|
bool FileCancel(std::string hash);
|
||||||
|
@ -245,10 +245,13 @@ void ftServer::run()
|
|||||||
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list<std::string> srcIds)
|
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list<std::string> srcIds)
|
||||||
{
|
{
|
||||||
std::cerr << "Requesting " << fname << std::endl ;
|
std::cerr << "Requesting " << fname << std::endl ;
|
||||||
// return mFtController->FileRequest(fname, hash, size,
|
|
||||||
// dest, flags, srcIds);
|
if(mFtController->alreadyHaveFile(hash))
|
||||||
|
return false ;
|
||||||
|
|
||||||
const DwlDetails details(fname, hash, size, dest, flags, srcIds, Normal);
|
const DwlDetails details(fname, hash, size, dest, flags, srcIds, Normal);
|
||||||
mFtDwlQueue->insertDownload(details);
|
mFtDwlQueue->insertDownload(details);
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,9 @@ virtual ~RsFiles() { return; }
|
|||||||
/***
|
/***
|
||||||
* Control of Downloads.
|
* Control of Downloads.
|
||||||
***/
|
***/
|
||||||
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
|
|
||||||
std::string dest, uint32_t flags, std::list<std::string> srcIds) = 0;
|
/// Returns false is we already have the file. Otherwise, initiates the dl and returns true.
|
||||||
|
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list<std::string> srcIds) = 0;
|
||||||
virtual bool FileCancel(std::string hash) = 0;
|
virtual bool FileCancel(std::string hash) = 0;
|
||||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||||
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
|
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
|
||||||
|
@ -1091,14 +1091,21 @@ void ForumsDialog::anchorClicked (const QUrl& link )
|
|||||||
if (fileName != "" && fileHash != "")
|
if (fileName != "" && fileHash != "")
|
||||||
{
|
{
|
||||||
std::list<std::string> srcIds;
|
std::list<std::string> srcIds;
|
||||||
//srcIds.push_front();
|
|
||||||
rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds);
|
|
||||||
|
|
||||||
|
if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds))
|
||||||
|
{
|
||||||
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
mb.exec();
|
mb.exec();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
|
mb.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
|
@ -810,19 +810,32 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
|||||||
fileHash != "") {
|
fileHash != "") {
|
||||||
std::list<std::string> srcIds;
|
std::list<std::string> srcIds;
|
||||||
srcIds.push_front(dialogId);
|
srcIds.push_front(dialogId);
|
||||||
rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_ASSUME_AVAILABILITY, srcIds);
|
|
||||||
|
|
||||||
|
if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_ASSUME_AVAILABILITY, srcIds))
|
||||||
|
{
|
||||||
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
mb.exec();
|
mb.exec();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it, or you're already downloading it."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
|
mb.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
mb.exec();
|
mb.exec();
|
||||||
}
|
}
|
||||||
} else if (link.scheme() == "http") {
|
}
|
||||||
|
else if (link.scheme() == "http")
|
||||||
QDesktopServices::openUrl(link);
|
QDesktopServices::openUrl(link);
|
||||||
} else if (link.scheme() == "") {
|
else if (link.scheme() == "")
|
||||||
|
{
|
||||||
//it's probably a web adress, let's add http:// at the beginning of the link
|
//it's probably a web adress, let's add http:// at the beginning of the link
|
||||||
QString newAddress = link.toString();
|
QString newAddress = link.toString();
|
||||||
newAddress.prepend("http://");
|
newAddress.prepend("http://");
|
||||||
|
Loading…
Reference in New Issue
Block a user