mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-27 11:45:44 +00:00
Advanced error handling in the event that the previous state fails to load
This commit is contained in:
parent
9010726a41
commit
b9e9599a45
@ -325,6 +325,20 @@ class Manager:
|
||||
except OSError:
|
||||
pass # No file just means it wasn't downloaded, we can continue
|
||||
|
||||
# A function to try and reload a torrent from a previous session. This is
|
||||
# used in the event that Deluge crashes and a blank state is loaded.
|
||||
def add_old_torrent(self, filename, save_dir, compact):
|
||||
if not filename in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR):
|
||||
raise InvalidTorrentError(_("File was not found") + ": " + filename)
|
||||
|
||||
full_new_name = self.base_dir + "/" + TORRENTS_SUBDIR + "/" + filename
|
||||
|
||||
# Create torrent object
|
||||
new_torrent = torrent_info(full_new_name, save_dir, compact)
|
||||
self.state.torrents.append(new_torrent)
|
||||
|
||||
return self.sync()
|
||||
|
||||
# A separate function, because people may want to call it from time to time
|
||||
def save_fastresume_data(self):
|
||||
for unique_ID in self.unique_IDs:
|
||||
|
@ -58,11 +58,12 @@ class DelugeGTK:
|
||||
s = "%s %s"%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION)
|
||||
try:
|
||||
self.manager = deluge.Manager(p, v, s, dcommon.CONFIG_DIR)
|
||||
except AssertionError:
|
||||
except:
|
||||
# If something goes wrong while restoring the session, then load
|
||||
# a blank state rather than crash and exit
|
||||
self.manager = deluge.Manager(p, v, s, dcommon.CONFIG_DIR, blank_slate=True)
|
||||
self.something_screwed_up = True
|
||||
|
||||
else: self.something_screwed_up = False
|
||||
self.plugins = delugeplugins.PluginManager(self.manager, self)
|
||||
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
|
||||
@ -640,8 +641,22 @@ class DelugeGTK:
|
||||
return False
|
||||
|
||||
if self.something_screwed_up:
|
||||
dgtk.show_popup_warning(self.window, "For some reason, the previous state could not be loaded, " + \
|
||||
"so a blank state has been loaded for you.")
|
||||
dgtk.show_popup_warning(self.window,
|
||||
_("For some reason, the previous state could not be loaded, so a blank state has been loaded for you."))
|
||||
restore_torrents = dgtk.show_popup_question(self.window,
|
||||
_("Would you like to attempt to reload the previous session's downloads?"))
|
||||
if restore_torrents:
|
||||
torrent_subdir = self.manager.base_dir + "/" + deluge.TORRENTS_SUBDIR
|
||||
for torrent in os.listdir(torrent_subdir):
|
||||
if torrent.endswith('.torrent'):
|
||||
if self.config.get('use_default_dir', bool, default=False):
|
||||
path = self.config.get('default_download_path', default=os.path.expandvars('$HOME'))
|
||||
else:
|
||||
path = dgtk.show_directory_chooser_dialog(self.window,
|
||||
_("Choose the download directory for") + " " + torrent)
|
||||
if path is not None:
|
||||
unique_id = self.manager.add_old_torrent(torrent, path, self.config.get('use_compact_storage', bool, default=False))
|
||||
self.torrent_model.append(self.get_list_from_unique_id(unique_id))
|
||||
self.something_screwed_up = False
|
||||
|
||||
# Update Statusbar and Tray Tips
|
||||
|
30
src/dgtk.py
30
src/dgtk.py
@ -47,9 +47,29 @@ def show_popup_warning(window, message):
|
||||
warner.run()
|
||||
warner.destroy()
|
||||
|
||||
def show_popup_question(window, message):
|
||||
asker = gtk.MessageDialog(parent = window,
|
||||
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
buttons = gtk.BUTTONS_YES_NO,
|
||||
message_format=message,
|
||||
type=gtk.MESSAGE_QUESTION)
|
||||
result = asker.run()
|
||||
asker.destroy()
|
||||
if result == gtk.RESPONSE_YES:
|
||||
return True
|
||||
elif result == gtk.RESPONSE_NO:
|
||||
return False
|
||||
elif result == gtk.RESPONSE_DELETE_EVENT:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
## Browse for .torrent files
|
||||
def show_file_open_dialog(parent=None):
|
||||
chooser = gtk.FileChooserDialog(_("Choose a .torrent file"), parent, gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
def show_file_open_dialog(parent=None, title=None):
|
||||
if title is None:
|
||||
title = _("Choose a .torrent file")
|
||||
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||
|
||||
f0 = gtk.FileFilter()
|
||||
@ -72,8 +92,10 @@ def show_file_open_dialog(parent=None):
|
||||
chooser.destroy()
|
||||
return result
|
||||
|
||||
def show_directory_chooser_dialog(parent=None):
|
||||
chooser = gtk.FileChooserDialog(_("Choose a download directory"), parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
def show_directory_chooser_dialog(parent=None, title=None):
|
||||
if title is None:
|
||||
title = _("Choose a download directory")
|
||||
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
|
||||
chooser.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
|
||||
chooser.set_property("skip-taskbar-hint", True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user