mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 18:04:32 +00:00
Use the same save path editing behaviour in properties panel as in torrent addition dialog
This commit is contained in:
parent
c01f7102e6
commit
9f5d31b2b1
@ -2014,17 +2014,23 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||||||
}
|
}
|
||||||
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a.get())) {
|
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a.get())) {
|
||||||
QTorrentHandle h(p->handle);
|
QTorrentHandle h(p->handle);
|
||||||
if(h.is_valid() && h.num_files() > 1) {
|
if(h.is_valid()) {
|
||||||
// Check if folders were renamed
|
if(h.num_files() > 1) {
|
||||||
QStringList old_path_parts = misc::toQStringU(h.get_torrent_info().orig_files().at(p->index).path.string()).split("/");
|
// Check if folders were renamed
|
||||||
old_path_parts.removeLast();
|
QStringList old_path_parts = misc::toQStringU(h.get_torrent_info().orig_files().at(p->index).path.string()).split("/");
|
||||||
QString old_path = old_path_parts.join("/");
|
old_path_parts.removeLast();
|
||||||
QStringList new_path_parts = misc::toQStringU(p->name).split("/");
|
QString old_path = old_path_parts.join("/");
|
||||||
new_path_parts.removeLast();
|
QStringList new_path_parts = misc::toQStringU(p->name).split("/");
|
||||||
if(old_path != new_path_parts.join("/")) {
|
new_path_parts.removeLast();
|
||||||
old_path = h.save_path()+"/"+old_path;
|
if(old_path != new_path_parts.join("/")) {
|
||||||
qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path));
|
old_path = h.save_path()+"/"+old_path;
|
||||||
QDir().rmpath(old_path);
|
qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path));
|
||||||
|
QDir().rmpath(old_path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Single-file torrent
|
||||||
|
// Renaming a file corresponds to changing the save path
|
||||||
|
emit savePathChanged(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2204,297 +2210,297 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||||||
QString msg = QString::fromLocal8Bit(p->message().c_str());
|
QString msg = QString::fromLocal8Bit(p->message().c_str());
|
||||||
if(msg.contains("filesize", Qt::CaseInsensitive) && msg.contains("mismatch", Qt::CaseInsensitive)) {
|
if(msg.contains("filesize", Qt::CaseInsensitive) && msg.contains("mismatch", Qt::CaseInsensitive)) {
|
||||||
#else
|
#else
|
||||||
if(p->error.value() == 134) {
|
if(p->error.value() == 134) {
|
||||||
#endif
|
#endif
|
||||||
// Mismatching file size (files were probably moved
|
// Mismatching file size (files were probably moved
|
||||||
addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()));
|
addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()));
|
||||||
pauseTorrent(h.hash());
|
pauseTorrent(h.hash());
|
||||||
} else {
|
} else {
|
||||||
addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red"));
|
addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red"));
|
||||||
addConsoleMessage(tr("Reason: %1").arg(misc::toQString(p->message())));
|
addConsoleMessage(tr("Reason: %1").arg(misc::toQString(p->message())));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a.get())) {
|
|
||||||
addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(misc::toQString(p->url)).arg(misc::toQString(p->message())), QString::fromUtf8("red"));
|
|
||||||
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
|
|
||||||
}
|
|
||||||
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
|
|
||||||
QTorrentHandle h(p->handle);
|
|
||||||
if(h.is_valid()){
|
|
||||||
const QString &hash = h.hash();
|
|
||||||
qDebug("%s have just finished checking", qPrintable(hash));
|
|
||||||
// Save seed status
|
|
||||||
TorrentPersistentData::saveSeedStatus(h);
|
|
||||||
// Move to temp directory if necessary
|
|
||||||
if(!h.is_seed() && !defaultTempPath.isEmpty()) {
|
|
||||||
// Check if directory is different
|
|
||||||
const QDir current_dir(h.save_path());
|
|
||||||
const QDir save_dir(getSavePath(h.hash()));
|
|
||||||
if(current_dir == save_dir) {
|
|
||||||
h.move_storage(defaultTempPath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit torrentFinishedChecking(h);
|
}
|
||||||
if(torrentsToPausedAfterChecking.contains(hash)) {
|
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a.get())) {
|
||||||
torrentsToPausedAfterChecking.removeOne(hash);
|
addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(misc::toQString(p->url)).arg(misc::toQString(p->message())), QString::fromUtf8("red"));
|
||||||
h.pause();
|
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
|
||||||
emit pausedTorrent(h);
|
}
|
||||||
|
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
|
||||||
|
QTorrentHandle h(p->handle);
|
||||||
|
if(h.is_valid()){
|
||||||
|
const QString &hash = h.hash();
|
||||||
|
qDebug("%s have just finished checking", qPrintable(hash));
|
||||||
|
// Save seed status
|
||||||
|
TorrentPersistentData::saveSeedStatus(h);
|
||||||
|
// Move to temp directory if necessary
|
||||||
|
if(!h.is_seed() && !defaultTempPath.isEmpty()) {
|
||||||
|
// Check if directory is different
|
||||||
|
const QDir current_dir(h.save_path());
|
||||||
|
const QDir save_dir(getSavePath(h.hash()));
|
||||||
|
if(current_dir == save_dir) {
|
||||||
|
h.move_storage(defaultTempPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit torrentFinishedChecking(h);
|
||||||
|
if(torrentsToPausedAfterChecking.contains(hash)) {
|
||||||
|
torrentsToPausedAfterChecking.removeOne(hash);
|
||||||
|
h.pause();
|
||||||
|
emit pausedTorrent(h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
a = s->pop_alert();
|
||||||
}
|
}
|
||||||
a = s->pop_alert();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Bittorrent::recheckTorrent(QString hash) {
|
void Bittorrent::recheckTorrent(QString hash) {
|
||||||
QTorrentHandle h = getTorrentHandle(hash);
|
QTorrentHandle h = getTorrentHandle(hash);
|
||||||
if(h.is_valid() && h.has_metadata()) {
|
if(h.is_valid() && h.has_metadata()) {
|
||||||
if(h.is_paused()) {
|
if(h.is_paused()) {
|
||||||
if(!torrentsToPausedAfterChecking.contains(h.hash())) {
|
if(!torrentsToPausedAfterChecking.contains(h.hash())) {
|
||||||
torrentsToPausedAfterChecking << h.hash();
|
torrentsToPausedAfterChecking << h.hash();
|
||||||
h.resume();
|
h.resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
h.force_recheck();
|
||||||
}
|
}
|
||||||
h.force_recheck();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{
|
QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{
|
||||||
return trackersInfos.value(hash, QHash<QString, TrackerInfos>());
|
return trackersInfos.value(hash, QHash<QString, TrackerInfos>());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bittorrent::getListenPort() const{
|
int Bittorrent::getListenPort() const{
|
||||||
qDebug("LISTEN PORT: %d", s->listen_port());
|
qDebug("LISTEN PORT: %d", s->listen_port());
|
||||||
return s->listen_port();
|
return s->listen_port();
|
||||||
}
|
}
|
||||||
|
|
||||||
session_status Bittorrent::getSessionStatus() const{
|
session_status Bittorrent::getSessionStatus() const{
|
||||||
return s->status();
|
return s->status();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath, QString root_folder) {
|
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath, QString root_folder) {
|
||||||
QString savePath;
|
QString savePath;
|
||||||
if(TorrentTempData::hasTempData(hash)) {
|
if(TorrentTempData::hasTempData(hash)) {
|
||||||
savePath = TorrentTempData::getSavePath(hash);
|
savePath = TorrentTempData::getSavePath(hash);
|
||||||
if(savePath.isEmpty()) {
|
if(savePath.isEmpty()) {
|
||||||
savePath = defaultSavePath;
|
|
||||||
}
|
|
||||||
if(appendLabelToSavePath) {
|
|
||||||
qDebug("appendLabelToSavePath is true");
|
|
||||||
const QString &label = TorrentTempData::getLabel(hash);
|
|
||||||
if(!label.isEmpty()) {
|
|
||||||
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
|
|
||||||
} else {
|
|
||||||
savePath = TorrentPersistentData::getSavePath(hash);
|
|
||||||
qDebug("SavePath got from persistant data is %s", qPrintable(savePath));
|
|
||||||
bool append_root_folder = false;
|
|
||||||
if(savePath.isEmpty()) {
|
|
||||||
if(fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath))
|
|
||||||
savePath = QFileInfo(filePath).dir().path();
|
|
||||||
else {
|
|
||||||
savePath = defaultSavePath;
|
savePath = defaultSavePath;
|
||||||
append_root_folder = true;
|
|
||||||
}
|
}
|
||||||
|
if(appendLabelToSavePath) {
|
||||||
|
qDebug("appendLabelToSavePath is true");
|
||||||
|
const QString &label = TorrentTempData::getLabel(hash);
|
||||||
|
if(!label.isEmpty()) {
|
||||||
|
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
|
||||||
} else {
|
} else {
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
savePath = TorrentPersistentData::getSavePath(hash);
|
||||||
if(!settings.value("ported_to_new_savepath_system", false).toBool()) {
|
qDebug("SavePath got from persistant data is %s", qPrintable(savePath));
|
||||||
append_root_folder = true;
|
bool append_root_folder = false;
|
||||||
}
|
if(savePath.isEmpty()) {
|
||||||
}
|
if(fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath))
|
||||||
if(!fromScanDir && appendLabelToSavePath) {
|
savePath = QFileInfo(filePath).dir().path();
|
||||||
const QString &label = TorrentPersistentData::getLabel(hash);
|
else {
|
||||||
if(!label.isEmpty()) {
|
savePath = defaultSavePath;
|
||||||
qDebug("Torrent label is %s", qPrintable(label));
|
append_root_folder = true;
|
||||||
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if(append_root_folder && !root_folder.isEmpty()) {
|
|
||||||
// Append torrent root folder to the save path
|
|
||||||
if(!savePath.endsWith(QDir::separator()))
|
|
||||||
savePath += QDir::separator();
|
|
||||||
savePath += root_folder;
|
|
||||||
qDebug("Torrent root folder is %s", qPrintable(root_folder));
|
|
||||||
TorrentPersistentData::saveSavePath(hash, savePath);
|
|
||||||
}
|
|
||||||
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath));
|
|
||||||
}
|
|
||||||
// Clean path
|
|
||||||
savePath = misc::expandPath(savePath);
|
|
||||||
// Checking if savePath Dir exists
|
|
||||||
// create it if it is not
|
|
||||||
QDir saveDir(savePath);
|
|
||||||
if(!saveDir.exists()) {
|
|
||||||
if(!saveDir.mkpath(saveDir.absolutePath())) {
|
|
||||||
std::cerr << "Couldn't create the save directory: " << qPrintable(saveDir.path()) << "\n";
|
|
||||||
// XXX: Do something else?
|
|
||||||
} else {
|
|
||||||
qDebug("Created save folder at %s", qPrintable(saveDir.path()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return savePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take an url string to a torrent file,
|
|
||||||
// download the torrent file to a tmp location, then
|
|
||||||
// add it to download list
|
|
||||||
void Bittorrent::downloadFromUrl(QString url) {
|
|
||||||
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
|
|
||||||
#ifndef DISABLE_GUI
|
|
||||||
, QPalette::WindowText
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
//emit aboutToDownloadFromUrl(url);
|
|
||||||
// Launch downloader thread
|
|
||||||
downloader->downloadTorrentUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bittorrent::downloadFromURLList(const QStringList& urls) {
|
|
||||||
foreach(const QString &url, urls) {
|
|
||||||
downloadFromUrl(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bittorrent::addMagnetSkipAddDlg(QString uri) {
|
|
||||||
addMagnetUri(uri, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
|
||||||
//emit aboutToDownloadFromUrl(url);
|
|
||||||
const QUrl &qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
|
||||||
if(!save_path.isEmpty())
|
|
||||||
savepath_fromurl[qurl] = save_path;
|
|
||||||
url_skippingDlg << qurl;
|
|
||||||
// Launch downloader thread
|
|
||||||
downloader->downloadUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to Bittorrent session the downloaded torrent file
|
|
||||||
void Bittorrent::processDownloadedFile(QString url, QString file_path) {
|
|
||||||
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
|
|
||||||
if(index < 0) {
|
|
||||||
// Add file to torrent download list
|
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
// Windows hack
|
|
||||||
if(!file_path.endsWith(".torrent")) {
|
|
||||||
Q_ASSERT(QFile::exists(file_path));
|
|
||||||
qDebug("Torrent name does not end with .torrent, fixing...");
|
|
||||||
if(QFile::rename(file_path, file_path+".torrent")) {
|
|
||||||
file_path += ".torrent";
|
|
||||||
} else {
|
} else {
|
||||||
qDebug("Failed to rename torrent file!");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
if(!settings.value("ported_to_new_savepath_system", false).toBool()) {
|
||||||
|
append_root_folder = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!fromScanDir && appendLabelToSavePath) {
|
||||||
|
const QString &label = TorrentPersistentData::getLabel(hash);
|
||||||
|
if(!label.isEmpty()) {
|
||||||
|
qDebug("Torrent label is %s", qPrintable(label));
|
||||||
|
savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(append_root_folder && !root_folder.isEmpty()) {
|
||||||
|
// Append torrent root folder to the save path
|
||||||
|
if(!savePath.endsWith(QDir::separator()))
|
||||||
|
savePath += QDir::separator();
|
||||||
|
savePath += root_folder;
|
||||||
|
qDebug("Torrent root folder is %s", qPrintable(root_folder));
|
||||||
|
TorrentPersistentData::saveSavePath(hash, savePath);
|
||||||
|
}
|
||||||
|
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath));
|
||||||
|
}
|
||||||
|
// Clean path
|
||||||
|
savePath = misc::expandPath(savePath);
|
||||||
|
// Checking if savePath Dir exists
|
||||||
|
// create it if it is not
|
||||||
|
QDir saveDir(savePath);
|
||||||
|
if(!saveDir.exists()) {
|
||||||
|
if(!saveDir.mkpath(saveDir.absolutePath())) {
|
||||||
|
std::cerr << "Couldn't create the save directory: " << qPrintable(saveDir.path()) << "\n";
|
||||||
|
// XXX: Do something else?
|
||||||
|
} else {
|
||||||
|
qDebug("Created save folder at %s", qPrintable(saveDir.path()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug("Downloading torrent at path: %s", qPrintable(file_path));
|
return savePath;
|
||||||
#endif
|
|
||||||
emit newDownloadedTorrent(file_path, url);
|
|
||||||
} else {
|
|
||||||
url_skippingDlg.removeAt(index);
|
|
||||||
addTorrent(file_path, false, url, false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Return current download rate for the BT
|
// Take an url string to a torrent file,
|
||||||
// session. Payload means that it only take into
|
// download the torrent file to a tmp location, then
|
||||||
// account "useful" part of the rate
|
// add it to download list
|
||||||
float Bittorrent::getPayloadDownloadRate() const{
|
void Bittorrent::downloadFromUrl(QString url) {
|
||||||
const session_status &sessionStatus = s->status();
|
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
|
||||||
return sessionStatus.payload_download_rate;
|
#ifndef DISABLE_GUI
|
||||||
}
|
, QPalette::WindowText
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
//emit aboutToDownloadFromUrl(url);
|
||||||
|
// Launch downloader thread
|
||||||
|
downloader->downloadTorrentUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
// Return current upload rate for the BT
|
void Bittorrent::downloadFromURLList(const QStringList& urls) {
|
||||||
// session. Payload means that it only take into
|
foreach(const QString &url, urls) {
|
||||||
// account "useful" part of the rate
|
downloadFromUrl(url);
|
||||||
float Bittorrent::getPayloadUploadRate() const{
|
}
|
||||||
const session_status &sessionStatus = s->status();
|
}
|
||||||
return sessionStatus.payload_upload_rate;
|
|
||||||
}
|
void Bittorrent::addMagnetSkipAddDlg(QString uri) {
|
||||||
|
addMagnetUri(uri, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
|
||||||
|
//emit aboutToDownloadFromUrl(url);
|
||||||
|
const QUrl &qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
||||||
|
if(!save_path.isEmpty())
|
||||||
|
savepath_fromurl[qurl] = save_path;
|
||||||
|
url_skippingDlg << qurl;
|
||||||
|
// Launch downloader thread
|
||||||
|
downloader->downloadUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to Bittorrent session the downloaded torrent file
|
||||||
|
void Bittorrent::processDownloadedFile(QString url, QString file_path) {
|
||||||
|
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
|
||||||
|
if(index < 0) {
|
||||||
|
// Add file to torrent download list
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
// Windows hack
|
||||||
|
if(!file_path.endsWith(".torrent")) {
|
||||||
|
Q_ASSERT(QFile::exists(file_path));
|
||||||
|
qDebug("Torrent name does not end with .torrent, fixing...");
|
||||||
|
if(QFile::rename(file_path, file_path+".torrent")) {
|
||||||
|
file_path += ".torrent";
|
||||||
|
} else {
|
||||||
|
qDebug("Failed to rename torrent file!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("Downloading torrent at path: %s", qPrintable(file_path));
|
||||||
|
#endif
|
||||||
|
emit newDownloadedTorrent(file_path, url);
|
||||||
|
} else {
|
||||||
|
url_skippingDlg.removeAt(index);
|
||||||
|
addTorrent(file_path, false, url, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return current download rate for the BT
|
||||||
|
// session. Payload means that it only take into
|
||||||
|
// account "useful" part of the rate
|
||||||
|
float Bittorrent::getPayloadDownloadRate() const{
|
||||||
|
const session_status &sessionStatus = s->status();
|
||||||
|
return sessionStatus.payload_download_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return current upload rate for the BT
|
||||||
|
// session. Payload means that it only take into
|
||||||
|
// account "useful" part of the rate
|
||||||
|
float Bittorrent::getPayloadUploadRate() const{
|
||||||
|
const session_status &sessionStatus = s->status();
|
||||||
|
return sessionStatus.payload_upload_rate;
|
||||||
|
}
|
||||||
|
|
||||||
#if LIBTORRENT_VERSION_MINOR < 15
|
#if LIBTORRENT_VERSION_MINOR < 15
|
||||||
// Save DHT entry to hard drive
|
// Save DHT entry to hard drive
|
||||||
void Bittorrent::saveDHTEntry() {
|
void Bittorrent::saveDHTEntry() {
|
||||||
// Save DHT entry
|
// Save DHT entry
|
||||||
if(DHTEnabled) {
|
if(DHTEnabled) {
|
||||||
try{
|
try{
|
||||||
entry dht_state = s->dht_state();
|
entry dht_state = s->dht_state();
|
||||||
const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
|
const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
|
||||||
boost::filesystem::ofstream out(dht_path.toLocal8Bit().constData(), std::ios_base::binary);
|
boost::filesystem::ofstream out(dht_path.toLocal8Bit().constData(), std::ios_base::binary);
|
||||||
out.unsetf(std::ios_base::skipws);
|
out.unsetf(std::ios_base::skipws);
|
||||||
bencode(std::ostream_iterator<char>(out), dht_state);
|
bencode(std::ostream_iterator<char>(out), dht_state);
|
||||||
qDebug("DHT entry saved");
|
qDebug("DHT entry saved");
|
||||||
}catch (std::exception& e) {
|
}catch (std::exception& e) {
|
||||||
std::cerr << e.what() << "\n";
|
std::cerr << e.what() << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Bittorrent::applyEncryptionSettings(pe_settings se) {
|
void Bittorrent::applyEncryptionSettings(pe_settings se) {
|
||||||
qDebug("Applying encryption settings");
|
qDebug("Applying encryption settings");
|
||||||
s->set_pe_settings(se);
|
s->set_pe_settings(se);
|
||||||
}
|
|
||||||
|
|
||||||
// Will fast resume torrents in
|
|
||||||
// backup directory
|
|
||||||
void Bittorrent::startUpTorrents() {
|
|
||||||
qDebug("Resuming unfinished torrents");
|
|
||||||
const QDir torrentBackup(misc::BTBackupLocation());
|
|
||||||
const QStringList &known_torrents = TorrentPersistentData::knownTorrents();
|
|
||||||
|
|
||||||
// Safety measure because some people reported torrent loss since
|
|
||||||
// we switch the v1.5 way of resuming torrents on startup
|
|
||||||
QStringList filters;
|
|
||||||
filters << "*.torrent";
|
|
||||||
const QStringList &torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
|
||||||
foreach(QString hash, torrents_on_hd) {
|
|
||||||
qDebug("found torrent with hash: %s on hard disk", qPrintable(hash));
|
|
||||||
hash.chop(8); // remove trailing .torrent
|
|
||||||
if(!known_torrents.contains(hash)) {
|
|
||||||
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl;
|
|
||||||
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// End of safety measure
|
|
||||||
|
|
||||||
qDebug("Starting up torrents");
|
// Will fast resume torrents in
|
||||||
if(isQueueingEnabled()) {
|
// backup directory
|
||||||
priority_queue<QPair<int, QString>, vector<QPair<int, QString> >, std::greater<QPair<int, QString> > > torrent_queue;
|
void Bittorrent::startUpTorrents() {
|
||||||
foreach(const QString &hash, known_torrents) {
|
qDebug("Resuming unfinished torrents");
|
||||||
QString filePath;
|
const QDir torrentBackup(misc::BTBackupLocation());
|
||||||
if(TorrentPersistentData::isMagnet(hash)) {
|
const QStringList &known_torrents = TorrentPersistentData::knownTorrents();
|
||||||
filePath = TorrentPersistentData::getMagnetUri(hash);
|
|
||||||
} else {
|
// Safety measure because some people reported torrent loss since
|
||||||
filePath = torrentBackup.path()+QDir::separator()+hash+".torrent";
|
// we switch the v1.5 way of resuming torrents on startup
|
||||||
}
|
QStringList filters;
|
||||||
const int prio = TorrentPersistentData::getPriority(hash);
|
filters << "*.torrent";
|
||||||
torrent_queue.push(qMakePair(prio, hash));
|
const QStringList &torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||||
}
|
foreach(QString hash, torrents_on_hd) {
|
||||||
qDebug("Priority_queue size: %ld", (long)torrent_queue.size());
|
qDebug("found torrent with hash: %s on hard disk", qPrintable(hash));
|
||||||
// Resume downloads
|
hash.chop(8); // remove trailing .torrent
|
||||||
while(!torrent_queue.empty()) {
|
if(!known_torrents.contains(hash)) {
|
||||||
const QString hash = torrent_queue.top().second;
|
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl;
|
||||||
torrent_queue.pop();
|
|
||||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
|
||||||
if(TorrentPersistentData::isMagnet(hash)) {
|
|
||||||
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
|
||||||
} else {
|
|
||||||
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
// End of safety measure
|
||||||
// Resume downloads
|
|
||||||
foreach(const QString &hash, known_torrents) {
|
qDebug("Starting up torrents");
|
||||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
if(isQueueingEnabled()) {
|
||||||
if(TorrentPersistentData::isMagnet(hash))
|
priority_queue<QPair<int, QString>, vector<QPair<int, QString> >, std::greater<QPair<int, QString> > > torrent_queue;
|
||||||
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
foreach(const QString &hash, known_torrents) {
|
||||||
else
|
QString filePath;
|
||||||
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
if(TorrentPersistentData::isMagnet(hash)) {
|
||||||
|
filePath = TorrentPersistentData::getMagnetUri(hash);
|
||||||
|
} else {
|
||||||
|
filePath = torrentBackup.path()+QDir::separator()+hash+".torrent";
|
||||||
|
}
|
||||||
|
const int prio = TorrentPersistentData::getPriority(hash);
|
||||||
|
torrent_queue.push(qMakePair(prio, hash));
|
||||||
|
}
|
||||||
|
qDebug("Priority_queue size: %ld", (long)torrent_queue.size());
|
||||||
|
// Resume downloads
|
||||||
|
while(!torrent_queue.empty()) {
|
||||||
|
const QString hash = torrent_queue.top().second;
|
||||||
|
torrent_queue.pop();
|
||||||
|
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||||
|
if(TorrentPersistentData::isMagnet(hash)) {
|
||||||
|
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
||||||
|
} else {
|
||||||
|
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Resume downloads
|
||||||
|
foreach(const QString &hash, known_torrents) {
|
||||||
|
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||||
|
if(TorrentPersistentData::isMagnet(hash))
|
||||||
|
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
|
||||||
|
else
|
||||||
|
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
settings.setValue("ported_to_new_savepath_system", true);
|
||||||
|
qDebug("Unfinished torrents resumed");
|
||||||
}
|
}
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
|
||||||
settings.setValue("ported_to_new_savepath_system", true);
|
|
||||||
qDebug("Unfinished torrents resumed");
|
|
||||||
}
|
|
||||||
|
@ -210,9 +210,14 @@ Bittorrent* PropertiesWidget::getBTSession() const {
|
|||||||
|
|
||||||
void PropertiesWidget::updateSavePath(QTorrentHandle& _h) {
|
void PropertiesWidget::updateSavePath(QTorrentHandle& _h) {
|
||||||
if(h.is_valid() && h == _h) {
|
if(h.is_valid() && h == _h) {
|
||||||
QString p = TorrentPersistentData::getSavePath(h.hash());
|
QString p;
|
||||||
if(p.isEmpty())
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
p = h.save_path();
|
p = h.firstFileSavePath();
|
||||||
|
} else {
|
||||||
|
p = TorrentPersistentData::getSavePath(h.hash());
|
||||||
|
if(p.isEmpty())
|
||||||
|
p = h.save_path();
|
||||||
|
}
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
p = p.replace("/", "\\");
|
p = p.replace("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
@ -237,9 +242,14 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Save path
|
// Save path
|
||||||
QString p = TorrentPersistentData::getSavePath(h.hash());
|
QString p;
|
||||||
if(p.isEmpty())
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
p = h.save_path();
|
p = h.firstFileSavePath();
|
||||||
|
} else {
|
||||||
|
p = TorrentPersistentData::getSavePath(h.hash());
|
||||||
|
if(p.isEmpty())
|
||||||
|
p = h.save_path();
|
||||||
|
}
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
p = p.replace("/", "\\");
|
p = p.replace("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
@ -699,8 +709,8 @@ void PropertiesWidget::renameSelectedFile() {
|
|||||||
bool ok;
|
bool ok;
|
||||||
// Ask user for a new url seed
|
// Ask user for a new url seed
|
||||||
const QString &url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
const QString &url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
||||||
tr("New url seed:"), QLineEdit::Normal,
|
tr("New url seed:"), QLineEdit::Normal,
|
||||||
QString::fromUtf8("http://www."), &ok);
|
QString::fromUtf8("http://www."), &ok);
|
||||||
if(!ok) return;
|
if(!ok) return;
|
||||||
qDebug("Adding %s web seed", qPrintable(url_seed));
|
qDebug("Adding %s web seed", qPrintable(url_seed));
|
||||||
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
||||||
@ -747,16 +757,27 @@ void PropertiesWidget::renameSelectedFile() {
|
|||||||
|
|
||||||
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
||||||
if(!h.is_valid()) return;
|
if(!h.is_valid()) return;
|
||||||
QString dir;
|
QString new_path;
|
||||||
const QDir saveDir(h.save_path());
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
if(saveDir.exists()){
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath());
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
} else {
|
||||||
}else{
|
const QDir saveDir(h.save_path());
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
if(saveDir.exists()){
|
||||||
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
||||||
|
}else{
|
||||||
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!dir.isEmpty()){
|
if(!new_path.isEmpty()){
|
||||||
// Check if savePath exists
|
// Check if savePath exists
|
||||||
QDir savePath(misc::expandPath(dir));
|
QString save_path_dir = new_path.replace("\\", "/");
|
||||||
|
QString new_file_name;
|
||||||
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
|
QStringList parts = save_path_dir.split("/");
|
||||||
|
new_file_name = parts.takeLast(); // Skip file name
|
||||||
|
save_path_dir = parts.join("/");
|
||||||
|
}
|
||||||
|
QDir savePath(misc::expandPath(save_path_dir));
|
||||||
if(!savePath.exists()){
|
if(!savePath.exists()){
|
||||||
if(!savePath.mkpath(savePath.absolutePath())){
|
if(!savePath.mkpath(savePath.absolutePath())){
|
||||||
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
||||||
@ -767,7 +788,24 @@ void PropertiesWidget::renameSelectedFile() {
|
|||||||
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
||||||
h.move_storage(savePath.absolutePath());
|
h.move_storage(savePath.absolutePath());
|
||||||
// Update save_path in dialog
|
// Update save_path in dialog
|
||||||
QString display_path = savePath.absolutePath();
|
QString display_path;
|
||||||
|
if(h.has_metadata() && h.num_files() == 1) {
|
||||||
|
// Rename the file
|
||||||
|
Q_ASSERT(!new_file_name.isEmpty());
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
|
if(h.file_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) {
|
||||||
|
#else
|
||||||
|
if(h.file_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) {
|
||||||
|
#endif
|
||||||
|
qDebug("Renaming single file to %s", qPrintable(new_file_name));
|
||||||
|
h.rename_file(0, new_file_name);
|
||||||
|
// Also rename it in the files list model
|
||||||
|
PropListModel->setData(PropListModel->index(0, 0), new_file_name);
|
||||||
|
}
|
||||||
|
display_path = new_path;
|
||||||
|
} else {
|
||||||
|
display_path = savePath.absolutePath();
|
||||||
|
}
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
display_path = display_path.replace("/", "\\");
|
display_path = display_path.replace("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
|
@ -459,6 +459,19 @@ QString QTorrentHandle::root_path() const {
|
|||||||
return save_path();
|
return save_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QTorrentHandle::firstFileSavePath() const {
|
||||||
|
Q_ASSERT(h.is_valid());
|
||||||
|
Q_ASSERT(has_metadata());
|
||||||
|
QString fsave_path = TorrentPersistentData::getSavePath(hash());
|
||||||
|
if(fsave_path.isEmpty())
|
||||||
|
fsave_path = save_path();
|
||||||
|
fsave_path = fsave_path.replace("\\", "/");
|
||||||
|
if(!fsave_path.endsWith("/"))
|
||||||
|
fsave_path += "/";
|
||||||
|
fsave_path += misc::toQStringU(h.get_torrent_info().file_at(0).path.string());
|
||||||
|
return fsave_path;
|
||||||
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::has_error() const {
|
bool QTorrentHandle::has_error() const {
|
||||||
Q_ASSERT(h.is_valid());
|
Q_ASSERT(h.is_valid());
|
||||||
return h.is_paused() && !h.status().error.empty();
|
return h.is_paused() && !h.status().error.empty();
|
||||||
|
@ -131,6 +131,7 @@ class QTorrentHandle {
|
|||||||
bool priv() const;
|
bool priv() const;
|
||||||
bool first_last_piece_first() const;
|
bool first_last_piece_first() const;
|
||||||
QString root_path() const;
|
QString root_path() const;
|
||||||
|
QString firstFileSavePath() const;
|
||||||
bool has_error() const;
|
bool has_error() const;
|
||||||
QString error() const;
|
QString error() const;
|
||||||
void downloading_pieces(bitfield &bf) const;
|
void downloading_pieces(bitfield &bf) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user