Browse Source

Added --pause option.

This option pauses download after added. This option is effective only
when --enable-rpc=true is given.  When --save-session option is used
and there are paused downloads, they are saved with --pause=true so
that it will become paused state when the session is recovered.
Tatsuhiro Tsujikawa 14 years ago
parent
commit
d5c2ef4ce9

+ 2 - 0
src/Metalink2RequestGroup.cc

@@ -312,6 +312,8 @@ Metalink2RequestGroup::createRequestGroup
       rg->setNumConcurrentCommand(option->getAsInt(PREF_METALINK_SERVERS));
       rg->setNumConcurrentCommand(option->getAsInt(PREF_METALINK_SERVERS));
     }
     }
     rg->setDownloadContext(dctx);
     rg->setDownloadContext(dctx);
+    rg->setPauseRequested(option->getAsBool(PREF_PAUSE));
+    removeOneshotOption(rg->getOption());
     // remove "metalink" from Accept Type list to avoid loop in
     // remove "metalink" from Accept Type list to avoid loop in
     // tranparent metalink
     // tranparent metalink
     util::removeMetalinkContentTypes(rg);
     util::removeMetalinkContentTypes(rg);

+ 10 - 0
src/OptionHandlerFactory.cc

@@ -514,6 +514,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_ADVANCED);
     op->addTag(TAG_ADVANCED);
     handlers.push_back(op);
     handlers.push_back(op);
   }
   }
+  {
+    SharedHandle<OptionHandler> op(new BooleanOptionHandler
+                                   (PREF_PAUSE,
+                                    TEXT_PAUSE,
+                                    A2_V_FALSE,
+                                    OptionHandler::OPT_ARG));
+    op->addTag(TAG_ADVANCED);
+    op->addTag(TAG_RPC);
+    handlers.push_back(op);
+  }
   {
   {
     SharedHandle<OptionHandler> op(new BooleanOptionHandler
     SharedHandle<OptionHandler> op(new BooleanOptionHandler
                                    (PREF_QUIET,
                                    (PREF_QUIET,

+ 2 - 1
src/RequestGroupMan.cc

@@ -500,7 +500,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
     reservedGroups_.pop_front();
     reservedGroups_.pop_front();
     std::vector<Command*> commands;
     std::vector<Command*> commands;
     try {
     try {
-      if(groupToAdd->isPauseRequested()||!groupToAdd->isDependencyResolved()) {
+      if((rpc_ && groupToAdd->isPauseRequested()) ||
+         !groupToAdd->isDependencyResolved()) {
         temp.push_back(groupToAdd);
         temp.push_back(groupToAdd);
         continue;
         continue;
       }
       }

+ 5 - 0
src/SessionSerializer.cc

@@ -192,6 +192,11 @@ void SessionSerializer::save(std::ostream& out) const
           groups.begin(), eoi = groups.end(); itr != eoi; ++itr) {
           groups.begin(), eoi = groups.end(); itr != eoi; ++itr) {
       SharedHandle<DownloadResult> result = (*itr)->createDownloadResult();
       SharedHandle<DownloadResult> result = (*itr)->createDownloadResult();
       writeDownloadResult(out, metainfoCache, result);
       writeDownloadResult(out, metainfoCache, result);
+      // PREF_PAUSE was removed from option, so save it here looking
+      // property separately.
+      if((*itr)->isPauseRequested()) {
+        out << " " << PREF_PAUSE << "=true" << "\n";
+      }
     }
     }
   }
   }
 }
 }

+ 13 - 1
src/download_helper.cc

@@ -167,7 +167,8 @@ const std::set<std::string>& listRequestOptions()
     PREF_BT_TRACKER,
     PREF_BT_TRACKER,
     PREF_BT_EXCLUDE_TRACKER,
     PREF_BT_EXCLUDE_TRACKER,
     PREF_RETRY_WAIT,
     PREF_RETRY_WAIT,
-    PREF_METALINK_BASE_URI
+    PREF_METALINK_BASE_URI,
+    PREF_PAUSE
   };
   };
   static std::set<std::string> requestOptions
   static std::set<std::string> requestOptions
     (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));
     (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));
@@ -228,6 +229,8 @@ SharedHandle<RequestGroup> createRequestGroup
   dctx->getFirstFileEntry()->setMaxConnectionPerServer
   dctx->getFirstFileEntry()->setMaxConnectionPerServer
     (option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
     (option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
   rg->setDownloadContext(dctx);
   rg->setDownloadContext(dctx);
+  rg->setPauseRequested(option->getAsBool(PREF_PAUSE));
+  removeOneshotOption(rg->getOption());
   return rg;
   return rg;
 }
 }
 } // namespace
 } // namespace
@@ -282,9 +285,11 @@ createBtRequestGroup(const std::string& torrentFilePath,
       ((*i).first, util::applyDir(option->get(PREF_DIR), (*i).second));
       ((*i).first, util::applyDir(option->get(PREF_DIR), (*i).second));
   }
   }
   rg->setDownloadContext(dctx);
   rg->setDownloadContext(dctx);
+  rg->setPauseRequested(option->getAsBool(PREF_PAUSE));
   // Remove "metalink" from Accept Type list to avoid server from
   // Remove "metalink" from Accept Type list to avoid server from
   // responding Metalink file for web-seeding URIs.
   // responding Metalink file for web-seeding URIs.
   util::removeMetalinkContentTypes(rg);
   util::removeMetalinkContentTypes(rg);
+  removeOneshotOption(rg->getOption());
   return rg;
   return rg;
 }
 }
 } // namespace
 } // namespace
@@ -316,6 +321,8 @@ createBtMagnetRequestGroup(const std::string& magnetLink,
     (SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
     (SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
   rg->setMetadataInfo(createMetadataInfo(magnetLink));
   rg->setMetadataInfo(createMetadataInfo(magnetLink));
   rg->markInMemoryDownload();
   rg->markInMemoryDownload();
+  rg->setPauseRequested(option->getAsBool(PREF_PAUSE));
+  removeOneshotOption(rg->getOption());
   return rg;
   return rg;
 }
 }
 } // namespace
 } // namespace
@@ -555,4 +562,9 @@ createMetadataInfoFromFirstFileEntry(const SharedHandle<DownloadContext>& dctx)
   }
   }
 }
 }
 
 
+void removeOneshotOption(const SharedHandle<Option>& option)
+{
+  option->remove(PREF_PAUSE);
+}
+
 } // namespace aria2
 } // namespace aria2

+ 4 - 0
src/download_helper.h

@@ -112,6 +112,10 @@ void setMetadataInfo
 SharedHandle<MetadataInfo>
 SharedHandle<MetadataInfo>
 createMetadataInfoFromFirstFileEntry(const SharedHandle<DownloadContext>& dctx);
 createMetadataInfoFromFirstFileEntry(const SharedHandle<DownloadContext>& dctx);
 
 
+// Removes option value which is only effective at the first
+// construction time.
+void removeOneshotOption(const SharedHandle<Option>& option);
+
 } // namespace aria2
 } // namespace aria2
 
 
 #endif // D_DOWNLOAD_HELPER_H
 #endif // D_DOWNLOAD_HELPER_H

+ 1 - 0
src/main.cc

@@ -267,6 +267,7 @@ error_code::Value main(int argc, char* argv[])
   op->remove(PREF_INPUT_FILE);
   op->remove(PREF_INPUT_FILE);
   op->remove(PREF_INDEX_OUT);
   op->remove(PREF_INDEX_OUT);
   op->remove(PREF_SELECT_FILE);
   op->remove(PREF_SELECT_FILE);
+  op->remove(PREF_PAUSE);
   if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty()) {
   if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty()) {
     std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl;
     std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl;
   } else {
   } else {

+ 2 - 0
src/prefs.cc

@@ -226,6 +226,8 @@ const std::string PREF_SHOW_CONSOLE_READOUT("show-console-readout");
 const std::string PREF_STREAM_PIECE_SELECTOR("stream-piece-selector");
 const std::string PREF_STREAM_PIECE_SELECTOR("stream-piece-selector");
 // value: true | false
 // value: true | false
 const std::string PREF_TRUNCATE_CONSOLE_READOUT("truncate-console-readout");
 const std::string PREF_TRUNCATE_CONSOLE_READOUT("truncate-console-readout");
+// value: true | false
+const std::string PREF_PAUSE("pause");
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -229,6 +229,8 @@ extern const std::string PREF_SHOW_CONSOLE_READOUT;
 extern const std::string PREF_STREAM_PIECE_SELECTOR;
 extern const std::string PREF_STREAM_PIECE_SELECTOR;
 // value: true | false
 // value: true | false
 extern const std::string PREF_TRUNCATE_CONSOLE_READOUT;
 extern const std::string PREF_TRUNCATE_CONSOLE_READOUT;
+// value: true | false
+extern const std::string PREF_PAUSE;
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 3 - 0
src/usage_text.h

@@ -812,3 +812,6 @@
 #define TEXT_TRUNCATE_CONSOLE_READOUT                                   \
 #define TEXT_TRUNCATE_CONSOLE_READOUT                                   \
   _(" --truncate-console-readout[=true|false] Truncate console readout to fit in\n"\
   _(" --truncate-console-readout[=true|false] Truncate console readout to fit in\n"\
     "                              a single line.")
     "                              a single line.")
+#define TEXT_PAUSE                              \
+  _(" --pause[=true|false]         Pause download after added. This option is\n" \
+    "                              effective only when --enable-rpc=true is given.")