mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 15:04:36 +00:00
- Save and load session state to remember it over different sessions
This commit is contained in:
parent
e5b6a5605a
commit
3282e1bcc9
@ -642,9 +642,6 @@ void GUI::closeEvent(QCloseEvent *e) {
|
|||||||
}
|
}
|
||||||
// Save window size, columns size
|
// Save window size, columns size
|
||||||
writeSettings();
|
writeSettings();
|
||||||
// Do some BT related saving
|
|
||||||
BTSession->saveDHTEntry();
|
|
||||||
BTSession->saveFastResumeData();
|
|
||||||
// Accept exit
|
// Accept exit
|
||||||
e->accept();
|
e->accept();
|
||||||
qApp->exit();
|
qApp->exit();
|
||||||
|
@ -56,6 +56,8 @@ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false
|
|||||||
// Set severity level of libtorrent session
|
// Set severity level of libtorrent session
|
||||||
//s->set_alert_mask(alert::all_categories & ~alert::progress_notification);
|
//s->set_alert_mask(alert::all_categories & ~alert::progress_notification);
|
||||||
s->set_alert_mask(alert::error_notification | alert::peer_notification | alert::port_mapping_notification | alert::storage_notification | alert::tracker_notification | alert::status_notification | alert::ip_block_notification);
|
s->set_alert_mask(alert::error_notification | alert::peer_notification | alert::port_mapping_notification | alert::storage_notification | alert::tracker_notification | alert::status_notification | alert::ip_block_notification);
|
||||||
|
// Load previous state
|
||||||
|
loadSessionState();
|
||||||
// Enabling metadata plugin
|
// Enabling metadata plugin
|
||||||
s->add_extension(&create_metadata_plugin);
|
s->add_extension(&create_metadata_plugin);
|
||||||
timerAlerts = new QTimer();
|
timerAlerts = new QTimer();
|
||||||
@ -76,15 +78,19 @@ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false
|
|||||||
// Main destructor
|
// Main destructor
|
||||||
bittorrent::~bittorrent() {
|
bittorrent::~bittorrent() {
|
||||||
qDebug("BTSession deletion");
|
qDebug("BTSession deletion");
|
||||||
|
// Do some BT related saving
|
||||||
|
saveDHTEntry();
|
||||||
|
saveSessionState();
|
||||||
|
saveFastResumeData();
|
||||||
// Set Session settings
|
// Set Session settings
|
||||||
session_settings ss;
|
/*session_settings ss;
|
||||||
ss.tracker_receive_timeout = 1;
|
ss.tracker_receive_timeout = 1;
|
||||||
ss.stop_tracker_timeout = 1;
|
ss.stop_tracker_timeout = 1;
|
||||||
ss.tracker_completion_timeout = 1;
|
ss.tracker_completion_timeout = 1;
|
||||||
ss.piece_timeout = 1;
|
ss.piece_timeout = 1;
|
||||||
ss.peer_timeout = 1;
|
ss.peer_timeout = 1;
|
||||||
ss.urlseed_timeout = 1;
|
ss.urlseed_timeout = 1;
|
||||||
s->set_settings(ss);
|
s->set_settings(ss);*/
|
||||||
// Disable directory scanning
|
// Disable directory scanning
|
||||||
disableDirectoryScanning();
|
disableDirectoryScanning();
|
||||||
// Delete our objects
|
// Delete our objects
|
||||||
@ -710,6 +716,24 @@ void bittorrent::enableLSD(bool b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bittorrent::loadSessionState() {
|
||||||
|
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toUtf8().data()
|
||||||
|
, std::ios_base::binary);
|
||||||
|
ses_state_file.unsetf(std::ios_base::skipws);
|
||||||
|
s->load_state(bdecode(
|
||||||
|
std::istream_iterator<char>(ses_state_file)
|
||||||
|
, std::istream_iterator<char>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void bittorrent::saveSessionState() {
|
||||||
|
qDebug("Saving session state to disk...");
|
||||||
|
entry session_state = s->state();
|
||||||
|
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toUtf8().data()
|
||||||
|
, std::ios_base::binary);
|
||||||
|
out.unsetf(std::ios_base::skipws);
|
||||||
|
bencode(std::ostream_iterator<char>(out), session_state);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable DHT
|
// Enable DHT
|
||||||
bool bittorrent::enableDHT(bool b) {
|
bool bittorrent::enableDHT(bool b) {
|
||||||
if(b) {
|
if(b) {
|
||||||
|
@ -113,6 +113,8 @@ class bittorrent : public QObject {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
||||||
|
void loadSessionState();
|
||||||
|
void saveSessionState();
|
||||||
void downloadFromUrl(QString url);
|
void downloadFromUrl(QString url);
|
||||||
void downloadFromURLList(const QStringList& url_list);
|
void downloadFromURLList(const QStringList& url_list);
|
||||||
void deleteTorrent(QString hash, bool permanent = false);
|
void deleteTorrent(QString hash, bool permanent = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user