From eafabe2d44b11cf16f7dfa7abea993a004eac4be Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 11 Jan 2008 14:50:34 +0000 Subject: [PATCH] 2008-01-11 Tatsuhiro Tsujikawa 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 --- ChangeLog | 12 ++++++++++++ src/HelpItemFactory.cc | 12 +++++++++++- src/option_processing.cc | 37 ++++++++++++++++++++++++++++--------- src/prefs.h | 4 ++++ src/usage_text.h | 4 ++++ 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea0cd7a6..5e64b8fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-01-11 Tatsuhiro Tsujikawa + + 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 Added the message to inform users that other help categories are diff --git a/src/HelpItemFactory.cc b/src/HelpItemFactory.cc index 78027166..72540044 100644 --- a/src/HelpItemFactory.cc +++ b/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; } diff --git a/src/option_processing.cc b/src/option_processing.cc index bb8699d2..3b50c14f 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -42,6 +42,7 @@ #include "Exception.h" #include "a2io.h" #include "help_tags.h" +#include "LogFactory.h" #include #include @@ -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); diff --git a/src/prefs.h b/src/prefs.h index cb6c62c3..3a76b46b 100644 --- a/src/prefs.h +++ b/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 diff --git a/src/usage_text.h b/src/usage_text.h index c76a6329..d6dfcae1 100644 --- a/src/usage_text.h +++ b/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.")