diff options
Diffstat (limited to 'src/TorrentAutoSaveCommand.cc')
| -rw-r--r-- | src/TorrentAutoSaveCommand.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/TorrentAutoSaveCommand.cc b/src/TorrentAutoSaveCommand.cc index 4a767f28..54471a6c 100644 --- a/src/TorrentAutoSaveCommand.cc +++ b/src/TorrentAutoSaveCommand.cc @@ -20,18 +20,28 @@ */ /* copyright --> */ #include "TorrentAutoSaveCommand.h" -#include "SleepCommand.h" +#include "Util.h" -TorrentAutoSaveCommand::TorrentAutoSaveCommand(int cuid, TorrentDownloadEngine* e, int interval):Command(cuid), e(e), interval(interval) {} +TorrentAutoSaveCommand::TorrentAutoSaveCommand(int cuid, TorrentDownloadEngine* e, int interval):Command(cuid), e(e), interval(interval) { + checkPoint.tv_sec = 0; + checkPoint.tv_usec = 0; +} TorrentAutoSaveCommand::~TorrentAutoSaveCommand() {} bool TorrentAutoSaveCommand::execute() { - if(e->torrentMan->downloadComplete()) { + if(e->torrentMan->downloadComplete() || e->torrentMan->isHalt()) { return true; } - e->torrentMan->save(); - SleepCommand* sleepCommand = new SleepCommand(cuid, e, this, interval); - e->commands.push_back(sleepCommand); + struct timeval now; + gettimeofday(&now, NULL); + if(Util::difftvsec(now, checkPoint) >= interval) { + checkPoint = now; + e->torrentMan->save(); + if(e->torrentMan->isHalt()) { + return true; + } + } + e->commands.push_back(this); return false; } |
