瀏覽代碼

2008-01-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Added --no-conf and --conf-path command-line option.
	--no-conf option disables loading aria2.conf file.
	--conf-path option changes the configuration file path. The 
default
	file path is $HOME/.aria2/aria2.conf
	Added a warning message when the configuration file is not 
found.
	* src/HelpItemFactory.cc
	* src/option_processing.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 18 年之前
父節點
當前提交
eafabe2d44
共有 5 個文件被更改,包括 59 次插入10 次删除
  1. 12 0
      ChangeLog
  2. 11 1
      src/HelpItemFactory.cc
  3. 28 9
      src/option_processing.cc
  4. 4 0
      src/prefs.h
  5. 4 0
      src/usage_text.h

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2008-01-11  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Added --no-conf and --conf-path command-line option.
+	--no-conf option disables loading aria2.conf file.
+	--conf-path option changes the configuration file path. The default
+	file path is $HOME/.aria2/aria2.conf
+	Added a warning message when the configuration file is not found.
+	* src/HelpItemFactory.cc
+	* src/option_processing.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2008-01-11  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Added the message to inform users that other help categories are

+ 11 - 1
src/HelpItemFactory.cc

@@ -388,6 +388,16 @@ TagContainerHandle HelpItemFactory::createHelpItems()
     item->addTag(TAG_BASIC);
     tc->addItem(item);
   }
+  {
+    HelpItemHandle item = new HelpItem("no-conf", TEXT_NO_CONF);
+    item->addTag(TAG_ADVANCED);
+    tc->addItem(item);
+  }
+  {
+    HelpItemHandle item = new HelpItem("conf-path", TEXT_CONF_PATH, "$HOME/.aria2/aria2.conf");
+    item->addTag(TAG_ADVANCED);
+    tc->addItem(item);
+  }
   {
     HelpItemHandle item = new HelpItem("help", TEXT_HELP, TAG_BASIC);
     char buf[64];
@@ -395,6 +405,6 @@ TagContainerHandle HelpItemFactory::createHelpItems()
     item->setAvailableValues(buf);
     item->addTag(TAG_BASIC);
     tc->addItem(item);
-  }    
+  }
   return tc;
 }

+ 28 - 9
src/option_processing.cc

@@ -42,6 +42,7 @@
 #include "Exception.h"
 #include "a2io.h"
 #include "help_tags.h"
+#include "LogFactory.h"
 #include <fstream>
 #include <sstream>
 
@@ -132,6 +133,11 @@ Option* option_processing(int argc, char* const argv[])
   op->put(PREF_METALINK_PREFERRED_PROTOCOL, V_NONE);
   op->put(PREF_ENABLE_PEER_EXCHANGE, V_TRUE);
   op->put(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL, V_TRUE);
+
+  // following options are not parsed by OptionHandler and not stored in Option.
+  bool noConf = false;
+  string cfname = Util::getHomeDir()+"/.aria2/aria2.conf";
+
   while(1) {
     int optIndex = 0;
     int lopt;
@@ -184,6 +190,8 @@ Option* option_processing(int argc, char* const argv[])
       { PREF_ENABLE_DIRECT_IO, optional_argument, &lopt, 210 },
 #endif // ENABLE_DIRECT_IO
       { PREF_ALLOW_PIECE_LENGTH_CHANGE, required_argument, &lopt, 211 },
+      { PREF_NO_CONF, no_argument, &lopt, 212 },
+      { PREF_CONF_PATH, required_argument, &lopt, 213 },
 #if defined ENABLE_BITTORRENT || ENABLE_METALINK
       { "show-files", no_argument, NULL, 'S' },
       { "select-file", required_argument, &lopt, 21 },
@@ -353,6 +361,12 @@ Option* option_processing(int argc, char* const argv[])
       case 211:
 	cmdstream << PREF_ALLOW_PIECE_LENGTH_CHANGE << "=" << optarg << "\n";
 	break;
+      case 212:
+	noConf = true;
+	break;
+      case 213:
+	cfname = optarg;
+	break;
       }
       break;
     }
@@ -440,15 +454,20 @@ Option* option_processing(int argc, char* const argv[])
   {
     OptionParser oparser;
     oparser.setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
-    string cfname = Util::getHomeDir()+"/.aria2/aria2.conf";
-    ifstream cfstream(cfname.c_str());
-    try {
-      oparser.parse(op, cfstream);
-    } catch(Exception* e) {
-      cerr << "Parse error in " << cfname << endl;
-      cerr << *e << endl;
-      delete e;
-      exit(EXIT_FAILURE);
+    if(!noConf) {
+      if(File(cfname).isFile()) {
+	ifstream cfstream(cfname.c_str());
+	try {
+	  oparser.parse(op, cfstream);
+	} catch(Exception* e) {
+	  cerr << "Parse error in " << cfname << endl;
+	  cerr << *e << endl;
+	  delete e;
+	  exit(EXIT_FAILURE);
+	}
+      } else {
+	LogFactory::getInstance()->warn("Configuration file %s is not found.", cfname.c_str());
+      }
     }
     try {
       oparser.parse(op, cmdstream);

+ 4 - 0
src/prefs.h

@@ -120,6 +120,10 @@
 #define PREF_ENABLE_DIRECT_IO "enable-direct-io"
 // value: true | false
 #define PREF_ALLOW_PIECE_LENGTH_CHANGE "allow-piece-length-change"
+// value: true | false
+#define PREF_NO_CONF "no-conf"
+// value: string
+#define PREF_CONF_PATH "conf-path"
 
 /**
  * FTP related preferences

+ 4 - 0
src/usage_text.h

@@ -302,3 +302,7 @@ _(" -h, --help[=CATEGORY]        Print usage and exit.\n"\
   "                              http. If no matching category is found, search\n"\
   "                              option name in forward match and print the\n"\
   "                              result.")
+#define TEXT_NO_CONF \
+_(" --no-conf                    Disable loading aria2.conf file.")
+#define TEXT_CONF_PATH \
+_(" --conf-path=PATH             Change the configuration file path to PATH.")