/* */ #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