Giter Site home page Giter Site logo

Comments (4)

wasamasa avatar wasamasa commented on May 5, 2024

Here's a patch to make use of XDG for the config file:

3 files changed, 22 insertions(+), 1 deletion(-)
 src/OptionHandlerFactory.cc |  2 +-
 src/util.cc                 | 17 +++++++++++++++++
 src/util.h                  |  4 ++++

    Modified   src/OptionHandlerFactory.cc
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index 768d847..077fc4f 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -174,7 +174,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     OptionHandler* op(new DefaultOptionHandler
                       (PREF_CONF_PATH,
                        TEXT_CONF_PATH,
-                       util::getHomeDir()+"/.aria2/aria2.conf",
+                       util::getConfigFile(),
                        PATH_TO_FILE));
     op->addTag(TAG_ADVANCED);
     handlers.push_back(op);
    Modified   src/util.cc
diff --git a/src/util.cc b/src/util.cc
index 68310aa..16a9ab0 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1336,6 +1336,23 @@ std::string getHomeDir()
 }
 #endif // __MINGW32__

+std::string getXDGConfigHomeDir()
+{
+  const char* p = getenv("XDG_CONFIG_HOME");
+  if (p) {
+    return p;
+  }
+  return getHomeDir()+"/.config";
+}
+
+std::string getConfigFile() {
+  std::string filename = getXDGConfigHomeDir() + "/aria2/aria2.conf";
+  if (File(filename).exists()) {
+    return filename;
+  }
+  return getHomeDir()+"/.aria2/aria2.conf";
+}
+
 int64_t getRealSize(const std::string& sizeWithUnit)
 {
   std::string::size_type p = sizeWithUnit.find_first_of("KMkm");
    Modified   src/util.h
diff --git a/src/util.h b/src/util.h
index 6e5eb8c..a71dbaf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -349,6 +349,10 @@ void setGlobalSignalHandler(int signal, sigset_t* mask,

 std::string getHomeDir();

+std::string getXDGConfigHomeDir();
+
+std::string getConfigFile();
+
 int64_t getRealSize(const std::string& sizeWithUnit);

 std::string abbrevSize(int64_t size);

I'll have to look into corresponding changes for ~/.aria2/dht.dat. ~/.aria2/dht6.dat and the docs.

from aria2.

tatsuhiro-t avatar tatsuhiro-t commented on May 5, 2024

Thank you! This is awesome. Could you send PR for this once you finish the patch? We can discuss this in detail there.

from aria2.

wasamasa avatar wasamasa commented on May 5, 2024

See #395.

from aria2.

tatsuhiro-t avatar tatsuhiro-t commented on May 5, 2024

Fix committed, closing.

from aria2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.