|
|
@ -1362,10 +1362,10 @@ void QBtSession::loadSessionState() { |
|
|
|
QFile state_file(state_path); |
|
|
|
QFile state_file(state_path); |
|
|
|
if(!state_file.open(QIODevice::ReadOnly)) return; |
|
|
|
if(!state_file.open(QIODevice::ReadOnly)) return; |
|
|
|
std::vector<char> in; |
|
|
|
std::vector<char> in; |
|
|
|
const QByteArray content = state_file.readAll(); |
|
|
|
const qint64 content_size = state_file.bytesAvailable(); |
|
|
|
const int content_size = content.size(); |
|
|
|
if(content_size <= 0) return; |
|
|
|
in.resize(content_size); |
|
|
|
in.resize(content_size); |
|
|
|
memcpy(&in[0], content.data(), content_size); |
|
|
|
state_file.read(&in[0], content_size); |
|
|
|
// bdecode
|
|
|
|
// bdecode
|
|
|
|
lazy_entry e; |
|
|
|
lazy_entry e; |
|
|
|
if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) |
|
|
|
if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) |
|
|
@ -1386,14 +1386,13 @@ void QBtSession::saveSessionState() { |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
entry session_state; |
|
|
|
entry session_state; |
|
|
|
s->save_state(session_state); |
|
|
|
s->save_state(session_state); |
|
|
|
std::vector<char> out; |
|
|
|
vector<char> out; |
|
|
|
bencode(std::back_inserter(out), session_state); |
|
|
|
bencode(back_inserter(out), session_state); |
|
|
|
file f; |
|
|
|
QFile session_file(state_path); |
|
|
|
error_code ec; |
|
|
|
if (!out.empty() && session_file.open(QIODevice::WriteOnly)) { |
|
|
|
if (!f.open(state_path.toUtf8().constData(), file::write_only, ec)) return; |
|
|
|
session_file.write(&out[0], out.size()); |
|
|
|
if (ec) return; |
|
|
|
session_file.close(); |
|
|
|
file::iovec_t b = {&out[0], out.size()}; |
|
|
|
} |
|
|
|
f.writev(0, &b, 1, ec); |
|
|
|
|
|
|
|
#else |
|
|
|
#else |
|
|
|
entry session_state = s->state(); |
|
|
|
entry session_state = s->state(); |
|
|
|
boost::filesystem::ofstream out(state_path.toLocal8Bit().constData() |
|
|
|
boost::filesystem::ofstream out(state_path.toLocal8Bit().constData() |
|
|
@ -1538,12 +1537,16 @@ void QBtSession::saveFastResumeData() { |
|
|
|
if(!h.is_valid()) continue; |
|
|
|
if(!h.is_valid()) continue; |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Remove old fastresume file if it exists
|
|
|
|
// Remove old fastresume file if it exists
|
|
|
|
const QString file = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); |
|
|
|
vector<char> out; |
|
|
|
if(QFile::exists(file)) |
|
|
|
bencode(back_inserter(out), *rd->resume_data); |
|
|
|
misc::safeRemove(file); |
|
|
|
const QString filepath = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); |
|
|
|
boost::filesystem::ofstream out(boost::filesystem::path(file.toLocal8Bit().constData()), std::ios_base::binary); |
|
|
|
QFile resume_file(filepath); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
if(resume_file.exists()) |
|
|
|
bencode(std::ostream_iterator<char>(out), *rd->resume_data); |
|
|
|
misc::safeRemove(filepath); |
|
|
|
|
|
|
|
if(!out.empty() && resume_file.open(QIODevice::WriteOnly)) { |
|
|
|
|
|
|
|
resume_file.write(&out[0], out.size()); |
|
|
|
|
|
|
|
resume_file.close(); |
|
|
|
|
|
|
|
} |
|
|
|
// Remove torrent from session
|
|
|
|
// Remove torrent from session
|
|
|
|
s->remove_torrent(rd->handle); |
|
|
|
s->remove_torrent(rd->handle); |
|
|
|
s->pop_alert(); |
|
|
|
s->pop_alert(); |
|
|
@ -2120,16 +2123,17 @@ void QBtSession::readAlerts() { |
|
|
|
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) { |
|
|
|
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) { |
|
|
|
const QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
const QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
const QTorrentHandle h(p->handle); |
|
|
|
const QTorrentHandle h(p->handle); |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid() && p->resume_data) { |
|
|
|
const QString file = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); |
|
|
|
const QString filepath = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); |
|
|
|
// Delete old fastresume file if necessary
|
|
|
|
QFile resume_file(filepath); |
|
|
|
if(QFile::exists(file)) |
|
|
|
if(resume_file.exists()) |
|
|
|
misc::safeRemove(file); |
|
|
|
misc::safeRemove(filepath); |
|
|
|
qDebug("Saving fastresume data in %s", qPrintable(file)); |
|
|
|
qDebug("Saving fastresume data in %s", qPrintable(filepath)); |
|
|
|
if (p->resume_data) { |
|
|
|
vector<char> out; |
|
|
|
boost::filesystem::ofstream out(boost::filesystem::path(file.toUtf8().constData()), std::ios_base::binary); |
|
|
|
bencode(back_inserter(out), *p->resume_data); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
if(!out.empty() && resume_file.open(QIODevice::WriteOnly)) { |
|
|
|
bencode(std::ostream_iterator<char>(out), *p->resume_data); |
|
|
|
resume_file.write(&out[0], out.size()); |
|
|
|
|
|
|
|
resume_file.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|