mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
- Import torrents from v1.4.x (or earlier) in order not to lose them when updating
This commit is contained in:
parent
4e10a8dbf7
commit
c1378450fc
3 changed files with 126 additions and 2 deletions
|
@ -60,7 +60,7 @@ bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(
|
||||||
// To avoid some exceptions
|
// To avoid some exceptions
|
||||||
fs::path::default_name_check(fs::no_check);
|
fs::path::default_name_check(fs::no_check);
|
||||||
// Creating bittorrent session
|
// Creating bittorrent session
|
||||||
// Check if we should spoof azureus
|
// Check if we should spoof utorrent
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
if(settings.value(QString::fromUtf8("AzureusSpoof"), false).toBool()) {
|
if(settings.value(QString::fromUtf8("AzureusSpoof"), false).toBool()) {
|
||||||
s = new session(fingerprint("UT", 1, 8, 3, 0), 0);
|
s = new session(fingerprint("UT", 1, 8, 3, 0), 0);
|
||||||
|
@ -574,6 +574,11 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||||
} else {
|
} else {
|
||||||
p.save_path = defaultTempPath.toLocal8Bit().data();
|
p.save_path = defaultTempPath.toLocal8Bit().data();
|
||||||
}
|
}
|
||||||
|
// TODO: Remove in v1.6.0: For backward compatibility only
|
||||||
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) {
|
||||||
|
p.save_path = savePath.toLocal8Bit().data();
|
||||||
|
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished");
|
||||||
|
}
|
||||||
p.ti = t;
|
p.ti = t;
|
||||||
// Preallocate all?
|
// Preallocate all?
|
||||||
if(preAllocateAll)
|
if(preAllocateAll)
|
||||||
|
@ -659,6 +664,117 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces
|
||||||
|
// TODO: Remove in qBittorrent v1.6.0
|
||||||
|
void bittorrent::importOldTempData(QString torrent_path) {
|
||||||
|
// Create torrent hash
|
||||||
|
boost::intrusive_ptr<torrent_info> t;
|
||||||
|
try {
|
||||||
|
t = new torrent_info(torrent_path.toLocal8Bit().data());
|
||||||
|
QString hash = misc::toQString(t->info_hash());
|
||||||
|
// Load save path
|
||||||
|
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath");
|
||||||
|
QByteArray line;
|
||||||
|
QString savePath;
|
||||||
|
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
line = savepath_file.readAll();
|
||||||
|
savepath_file.close();
|
||||||
|
qDebug(" -> Save path: %s", line.data());
|
||||||
|
savePath = QString::fromUtf8(line.data());
|
||||||
|
qDebug("Imported the following save path: %s", savePath.toLocal8Bit().data());
|
||||||
|
TorrentTempData::setSavePath(hash, savePath);
|
||||||
|
// Clean up
|
||||||
|
savepath_file.remove();
|
||||||
|
}
|
||||||
|
// Load pieces priority
|
||||||
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities");
|
||||||
|
if(pieces_file.exists()){
|
||||||
|
// Read saved file
|
||||||
|
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QByteArray pieces_priorities = pieces_file.readAll();
|
||||||
|
pieces_file.close();
|
||||||
|
QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
|
||||||
|
std::vector<int> pp;
|
||||||
|
for(int i=0; i<t->num_files(); ++i) {
|
||||||
|
int priority = pieces_priorities_list.at(i).toInt();
|
||||||
|
if( priority < 0 || priority > 7) {
|
||||||
|
priority = 1;
|
||||||
|
}
|
||||||
|
qDebug("Setting piece piority to %d", priority);
|
||||||
|
pp.push_back(priority);
|
||||||
|
}
|
||||||
|
TorrentTempData::setFilesPriority(hash, pp);
|
||||||
|
qDebug("Successfuly imported pieces_priority");
|
||||||
|
}
|
||||||
|
// Clean up
|
||||||
|
pieces_file.remove();
|
||||||
|
}
|
||||||
|
// Load sequential
|
||||||
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) {
|
||||||
|
qDebug("Imported torrent was sequential");
|
||||||
|
TorrentTempData::setSequential(hash, true);
|
||||||
|
// Cleanup
|
||||||
|
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental");
|
||||||
|
}
|
||||||
|
} catch(std::exception&) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import torrents from v1.4.0 or earlier
|
||||||
|
// TODO: Remove in qBittorrent v1.6.0
|
||||||
|
void bittorrent::importOldTorrents() {
|
||||||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
|
if(!settings.value("v1_4_x_torrent_imported", false).toBool()) {
|
||||||
|
// Import old torrent
|
||||||
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
|
||||||
|
QStringList fileNames;
|
||||||
|
QStringList filters;
|
||||||
|
filters << "*.torrent";
|
||||||
|
fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||||
|
if(isQueueingEnabled()) {
|
||||||
|
QList<QPair<int, QString> > filePaths;
|
||||||
|
foreach(const QString &fileName, fileNames) {
|
||||||
|
QString filePath = torrentBackup.path()+QDir::separator()+fileName;
|
||||||
|
int prio = 99999;
|
||||||
|
// Get priority
|
||||||
|
QString prioPath = filePath;
|
||||||
|
prioPath.replace(".torrent", ".prio");
|
||||||
|
if(QFile::exists(prioPath)) {
|
||||||
|
QFile prio_file(prioPath);
|
||||||
|
if(prio_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
bool ok = false;
|
||||||
|
prio = prio_file.readAll().toInt(&ok);
|
||||||
|
if(!ok)
|
||||||
|
prio = 99999;
|
||||||
|
prio_file.close();
|
||||||
|
// Clean up
|
||||||
|
prio_file.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
misc::insertSort2<QString>(filePaths, qMakePair(prio, filePath));
|
||||||
|
}
|
||||||
|
// Resume downloads
|
||||||
|
QPair<int, QString> fileName;
|
||||||
|
foreach(fileName, filePaths) {
|
||||||
|
importOldTempData(fileName.second);
|
||||||
|
addTorrent(fileName.second, false, QString(), true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QStringList filePaths;
|
||||||
|
foreach(const QString &fileName, fileNames) {
|
||||||
|
filePaths.append(torrentBackup.path()+QDir::separator()+fileName);
|
||||||
|
}
|
||||||
|
// Resume downloads
|
||||||
|
foreach(const QString &fileName, filePaths) {
|
||||||
|
importOldTempData(fileName);
|
||||||
|
addTorrent(fileName, false, QString(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings.setValue("v1_4_x_torrent_imported", true);
|
||||||
|
std::cout << "Successfully imported torrents from v1.4.x (or previous) instance" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the user filtered files in this torrent.
|
// Check if the user filtered files in this torrent.
|
||||||
bool bittorrent::has_filtered_files(QString hash) const{
|
bool bittorrent::has_filtered_files(QString hash) const{
|
||||||
QVariantList files_priority = TorrentPersistentData::getFilesPriority(hash);
|
QVariantList files_priority = TorrentPersistentData::getFilesPriority(hash);
|
||||||
|
@ -1515,6 +1631,12 @@ void bittorrent::startUpTorrents() {
|
||||||
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
|
||||||
QStringList fileNames;
|
QStringList fileNames;
|
||||||
QStringList known_torrents = TorrentPersistentData::knownTorrents();
|
QStringList known_torrents = TorrentPersistentData::knownTorrents();
|
||||||
|
if(known_torrents.empty()) {
|
||||||
|
qDebug("No known torrent, importing old torrents");
|
||||||
|
importOldTorrents();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug("Starting up torrents");
|
||||||
if(isQueueingEnabled()) {
|
if(isQueueingEnabled()) {
|
||||||
QList<QPair<int, QString> > hashes;
|
QList<QPair<int, QString> > hashes;
|
||||||
foreach(const QString &hash, known_torrents) {
|
foreach(const QString &hash, known_torrents) {
|
||||||
|
|
|
@ -114,6 +114,8 @@ class bittorrent : public QObject {
|
||||||
public slots:
|
public slots:
|
||||||
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
||||||
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
||||||
|
void importOldTorrents();
|
||||||
|
void importOldTempData(QString torrent_path);
|
||||||
void loadSessionState();
|
void loadSessionState();
|
||||||
void saveSessionState();
|
void saveSessionState();
|
||||||
void downloadFromUrl(QString url);
|
void downloadFromUrl(QString url);
|
||||||
|
|
|
@ -3,7 +3,7 @@ LANG_PATH = lang
|
||||||
ICONS_PATH = Icons
|
ICONS_PATH = Icons
|
||||||
|
|
||||||
# Set the following variable to 1 to enable debug
|
# Set the following variable to 1 to enable debug
|
||||||
DEBUG_MODE = 0
|
DEBUG_MODE = 1
|
||||||
|
|
||||||
# Global
|
# Global
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue