From fac9cafa963426da8f54e006bd9d39a512ec374a Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Tue, 29 Apr 2014 18:57:36 +0200 Subject: [PATCH] Create the directory where resized textures will be cached. --- src/io/file_manager.cpp | 34 ++++++++++++++++++++++++++++++++++ src/io/file_manager.hpp | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 75565da81..0f5867337 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -192,6 +192,7 @@ FileManager::FileManager() checkAndCreateConfigDir(); checkAndCreateAddonsDir(); checkAndCreateScreenshotDir(); + checkAndCreateCachedTexturesDir(); checkAndCreateGPDir(); #ifdef WIN32 @@ -596,6 +597,14 @@ std::string FileManager::getScreenshotDir() const return m_screenshot_dir; } // getScreenshotDir +//----------------------------------------------------------------------------- +/** Returns the directory in which resized textures should be cached. +*/ +std::string FileManager::getCachedTexturesDir() const +{ + return m_cached_textures_dir; +} // getCachedTexturesDir + //----------------------------------------------------------------------------- /** Returns the directory in which user-defined grand prix should be stored. */ @@ -852,6 +861,31 @@ void FileManager::checkAndCreateScreenshotDir() } // checkAndCreateScreenshotDir +// ---------------------------------------------------------------------------- +/** Creates the directories for cached textures. This will set +* m_cached_textures_dir with the appropriate path. +*/ +void FileManager::checkAndCreateCachedTexturesDir() +{ +#if defined(WIN32) || defined(__CYGWIN__) + m_cached_textures_dir = m_user_config_dir + "resized-textures/"; +#elif defined(__APPLE__) + m_cached_textures_dir = getenv("HOME"); + m_cached_textures_dir += "/Library/Application Support/SuperTuxKart/ResizedTextures/"; +#else + m_cached_textures_dir = checkAndCreateLinuxDir("XDG_CACHE_HOME", "supertuxkart", ".cache/", "."); + m_cached_textures_dir += "resized-textures/"; +#endif + + if (!checkAndCreateDirectory(m_cached_textures_dir)) + { + Log::error("FileManager", "Can not create cached textures directory '%s', " + "falling back to '.'.", m_cached_textures_dir.c_str()); + m_cached_textures_dir = "."; + } + +} // checkAndCreateCachedTexturesDir + // ---------------------------------------------------------------------------- /** Creates the directories for user-defined grand prix. This will set m_gp_dir * with the appropriate path. diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index edde400e9..6fa266b40 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -72,6 +72,9 @@ private: /** Directory to store screenshots in. */ std::string m_screenshot_dir; + /** Directory where resized textures are cached. */ + std::string m_cached_textures_dir; + /** Directory where user-defined grand prix are stored. */ std::string m_gp_dir; @@ -91,6 +94,7 @@ private: bool isDirectory(const std::string &path) const; void checkAndCreateAddonsDir(); void checkAndCreateScreenshotDir(); + void checkAndCreateCachedTexturesDir(); void checkAndCreateGPDir(); #if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__APPLE__) std::string checkAndCreateLinuxDir(const char *env_name, @@ -110,6 +114,7 @@ public: XMLNode *createXMLTreeFromString(const std::string & content); std::string getScreenshotDir() const; + std::string getCachedTexturesDir() const; std::string getGPDir() const; bool checkAndCreateDirectoryP(const std::string &path); const std::string &getAddonsDir() const;