Add saving/loading of lt session state

This commit is contained in:
Andrew Resch 2008-08-24 04:52:14 +00:00
parent 8a39b7dcd5
commit 36118b3d02
1 changed files with 22 additions and 4 deletions

View File

@ -167,6 +167,9 @@ class Core(
log.debug("Starting libtorrent session..")
self.session = lt.session(fingerprint)
# Load the session state if available
self.load_session_state()
# Set the user agent
self.settings = lt.session_settings()
self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
@ -233,6 +236,9 @@ class Core(
if self.config["dht"]:
self.save_dht_state()
# Save the libtorrent session state
self.save_session_state()
# Shutdown the socket
try:
self.socket.shutdown(socket.SHUT_RDWR)
@ -251,10 +257,22 @@ class Core(
del deluge.configmanager
del self.session
self.loop.quit()
def save_session_state(self):
"""Saves the libtorrent session state"""
try:
self.gnome_client.disconnect()
except:
pass
open(deluge.common.get_default_config_dir("session.state"), "wb").write(
lt.bencode(self.session.state()))
except Exception, e:
log.warning("Failed to save lt state: %s", e)
def load_session_state(self):
"""Loads the libtorrent session state"""
try:
self.session.load_state(lt.bdecode(
open(deluge.common.get_default_config_dir("session.state"), "rb").read()))
except Exception, e:
log.warning("Failed to load lt state: %s", e)
def save_dht_state(self):
"""Saves the dht state to a file"""