From 97f1be2b0586a40ebe08b7b8e109d389ab0cda66 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sat, 8 Sep 2012 18:47:31 +0200 Subject: [PATCH] Testing a third way to solve the path issue --- components/files/fixedpath.hpp | 14 +------------- components/files/linuxpath.cpp | 14 ++++++++++---- components/files/linuxpath.hpp | 4 ++++ components/files/macospath.cpp | 13 +++++++++---- components/files/macospath.hpp | 4 ++++ components/files/windowspath.cpp | 11 ++++++++--- components/files/windowspath.hpp | 9 +++++++++ 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3a2bdd24aa..560a1ab45a 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -69,7 +69,7 @@ struct FixedPath * \param [in] application_name - Name of the application */ FixedPath(const std::string& application_name) - : mPath() + : mPath(application_name) , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) @@ -77,18 +77,6 @@ struct FixedPath , mInstallPath(mPath.getInstallPath()) , mCachePath(mPath.getCachePath()) { - if (!application_name.empty()) - { - boost::filesystem::path suffix(application_name + std::string("/")); - - mUserPath /= suffix; - mGlobalPath /= suffix; - mGlobalDataPath /= suffix; - mCachePath /= suffix; -#ifdef _WIN32 - mCachePath /= "cache"; -#endif - } } /** diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 006749d71e..0746350c8f 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -36,10 +36,15 @@ namespace Files { +LinuxPath::LinuxPath(const std::string& application_name) + : mName(application_name) +{ +} + boost::filesystem::path LinuxPath::getUserPath() const { boost::filesystem::path userPath("."); - boost::filesystem::path suffix("/"); + boost::filesystem::path suffix(mName); const char* theDir = getenv("HOME"); if (theDir == NULL) @@ -65,6 +70,7 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path LinuxPath::getCachePath() const { boost::filesystem::path userPath("."); + boost::filesystem::path suffix(mName); const char* theDir = getenv("HOME"); if (theDir == NULL) @@ -80,7 +86,7 @@ boost::filesystem::path LinuxPath::getCachePath() const { userPath = boost::filesystem::path(theDir); } - userPath /= ".cache"; + userPath /= ".cache" / suffix; return userPath; } @@ -88,7 +94,7 @@ boost::filesystem::path LinuxPath::getCachePath() const boost::filesystem::path LinuxPath::getGlobalPath() const { boost::filesystem::path globalPath("/etc/"); - return globalPath; + return globalPath / mName; } boost::filesystem::path LinuxPath::getLocalPath() const @@ -99,7 +105,7 @@ boost::filesystem::path LinuxPath::getLocalPath() const boost::filesystem::path LinuxPath::getGlobalDataPath() const { boost::filesystem::path globalDataPath("/usr/share/games/"); - return globalDataPath; + return globalDataPath / mName; } boost::filesystem::path LinuxPath::getInstallPath() const diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index ce339a5bf8..09acd2be7f 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -38,6 +38,8 @@ namespace Files */ struct LinuxPath { + LinuxPath(const std::string& application_name); + /** * \brief Return path to the user directory. * @@ -80,6 +82,8 @@ struct LinuxPath * \return boost::filesystem::path */ boost::filesystem::path getInstallPath() const; + + std::string mName; }; } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index b4e0ba1d17..d9ebb2e2df 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -39,10 +39,15 @@ namespace Files { +MacOsPath::MacOsPath(const std::string& application_name) + : mName(application_name) +{ +} + boost::filesystem::path MacOsPath::getUserPath() const { boost::filesystem::path userPath("."); - boost::filesystem::path suffix("/"); + boost::filesystem::path suffix(mName); const char* theDir = getenv("HOME"); if (theDir == NULL) @@ -66,7 +71,7 @@ boost::filesystem::path MacOsPath::getUserPath() const boost::filesystem::path MacOsPath::getGlobalPath() const { boost::filesystem::path globalPath("/Library/Preferences/"); - return globalPath; + return globalPath / mName; } boost::filesystem::path MacOsPath::getCachePath() const @@ -84,7 +89,7 @@ boost::filesystem::path MacOsPath::getCachePath() const } if (theDir != NULL) { - userPath = boost::filesystem::path(theDir) / "Library/Caches"; + userPath = boost::filesystem::path(theDir) / "Library/Caches" / mName; } return userPath; @@ -98,7 +103,7 @@ boost::filesystem::path MacOsPath::getLocalPath() const boost::filesystem::path MacOsPath::getGlobalDataPath() const { boost::filesystem::path globalDataPath("/Library/Application Support/"); - return globalDataPath; + return globalDataPath / mName; } boost::filesystem::path MacOsPath::getInstallPath() const diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 0e91360788..591c978aa7 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -38,6 +38,8 @@ namespace Files */ struct MacOsPath { + MacOsPath(const std::string& application_name); + /** * \brief Return path to the local directory. * @@ -75,6 +77,8 @@ struct MacOsPath boost::filesystem::path getGlobalDataPath() const; boost::filesystem::path getInstallPath() const; + + std::string mName; }; } /* namespace Files */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 672c13c69b..dffe3410fe 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -20,10 +20,15 @@ namespace Files { +WindowsPath::WindowsPath(const std::string& application_name) + : mName(application_name) +{ +} + boost::filesystem::path WindowsPath::getUserPath() const { boost::filesystem::path userPath("."); - boost::filesystem::path suffix("/"); + boost::filesystem::path suffix(mName); TCHAR path[MAX_PATH]; memset(path, 0, sizeof(path)); @@ -42,7 +47,7 @@ boost::filesystem::path WindowsPath::getUserPath() const boost::filesystem::path WindowsPath::getGlobalPath() const { boost::filesystem::path globalPath("."); - boost::filesystem::path suffix("/"); + boost::filesystem::path suffix(mName); TCHAR path[MAX_PATH]; memset(path, 0, sizeof(path)); @@ -69,7 +74,7 @@ boost::filesystem::path WindowsPath::getGlobalDataPath() const boost::filesystem::path WindowsPath::getCachePath() const { - return getUserPath(); + return getUserPath() / "cache"; } boost::filesystem::path WindowsPath::getInstallPath() const diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index fa010730e4..7fe8bc9559 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -38,6 +38,13 @@ namespace Files */ struct WindowsPath { + /** + * \brief WindowsPath constructor. + * + * \param [in] application_name - The name of the application. + */ + WindowsPath(const std::string& application_name); + /** * \brief Returns user path i.e.: * "X:\Documents And Settings\\My Documents\My Games\" @@ -81,6 +88,8 @@ struct WindowsPath * \return boost::filesystem::path */ boost::filesystem::path getInstallPath() const; + + std::string mName; }; } /* namespace Files */