From 8e63bad2da930c80d8f049376e61bd7152038ced Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 10 Jan 2013 00:12:53 +0900 Subject: Added --save-session-interval option --save-session-interval option saves error/unfinished downloads to a file specified by --save-session option every SEC seconds. If 0 is given, file will be saved only when aria2 exits. --- src/SaveSessionCommand.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/SaveSessionCommand.cc (limited to 'src/SaveSessionCommand.cc') diff --git a/src/SaveSessionCommand.cc b/src/SaveSessionCommand.cc new file mode 100644 index 00000000..2d990532 --- /dev/null +++ b/src/SaveSessionCommand.cc @@ -0,0 +1,78 @@ +/* */ +#include "SaveSessionCommand.h" +#include "DownloadEngine.h" +#include "RequestGroupMan.h" +#include "SessionSerializer.h" +#include "prefs.h" +#include "fmt.h" +#include "LogFactory.h" +#include "Option.h" + +namespace aria2 { + +SaveSessionCommand::SaveSessionCommand +(cuid_t cuid, DownloadEngine* e, time_t interval) + : TimeBasedCommand(cuid, e, interval, true) +{} + +SaveSessionCommand::~SaveSessionCommand() {} + +void SaveSessionCommand::preProcess() +{ + if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() || + getDownloadEngine()->isHaltRequested()) { + enableExit(); + } +} + +void SaveSessionCommand::process() +{ + const std::string& filename = getDownloadEngine()->getOption() + ->get(PREF_SAVE_SESSION); + if(!filename.empty()) { + SessionSerializer sessionSerializer(getDownloadEngine()-> + getRequestGroupMan()); + if(sessionSerializer.save(filename)) { + A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), + filename.c_str())); + } else { + A2_LOG_NOTICE(fmt(_("Failed to serialize session to '%s'."), + filename.c_str())); + } + } +} + +} // namespace aria2 -- cgit