|
From: Yoda-JM <yo...@us...> - 2010-07-14 17:59:31
|
Module: performous
Branch: svg_caching
Commit: 3edb9cec23efbedc484730b24c7f2dc800388035
Author: Vincent Le Ligeour <yo...@us...>
Date: Wed Jul 14 19:59:08 2010 +0200
Used XDG cache directory for svg caching to keep themes directory clean
---
game/fs.cc | 13 ++++++++++++-
game/fs.hh | 3 +++
game/surface.cc | 2 +-
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/game/fs.cc b/game/fs.cc
index 8349f1c..d356d8b 100644
--- a/game/fs.cc
+++ b/game/fs.cc
@@ -36,7 +36,6 @@ fs::path getLocaleDir() {
}
fs::path getConfigDir() {
-
static fs::path dir;
static bool initialized = false;
if (!initialized) {
@@ -82,6 +81,18 @@ fs::path getDataDir() {
#endif
}
+fs::path getCacheDir() {
+#ifdef _WIN32
+ return getConfigDir() / "cache"; // APPDATA/performous
+#else
+ fs::path shortDir = "performous";
+ fs::path shareDir = SHARED_DATA_DIR;
+ char const* xdg_cache_home = getenv("XDG_CACHE_HOME");
+ // FIXME: Should this use "games" or not?
+ return (xdg_cache_home ? xdg_cache_home / shortDir : getHomeDir() / ".cache" / shareDir);
+#endif
+}
+
fs::path getThemeDir() {
std::string theme = config["game/theme"].s();
static const std::string defaultTheme = "default";
diff --git a/game/fs.hh b/game/fs.hh
index 3d38eed..6d8baa2 100644
--- a/game/fs.hh
+++ b/game/fs.hh
@@ -15,6 +15,9 @@ fs::path getConfigDir();
/** Get the users data folder **/
fs::path getDataDir();
+/** Get the users cache folder **/
+fs::path getCacheDir();
+
/** Get the users theme folder **/
fs::path getThemeDir();
diff --git a/game/surface.cc b/game/surface.cc
index ee01d4c..47468ec 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -46,7 +46,7 @@ template <typename T> void loader(T& target, fs::path name) {
loadSVG(target, filename);
} else {
std::string cache_basename = name.filename() + ".cache_" + (boost::format("%.2f") % config["graphic/svg_lod"].f()).str() + ".png";
- fs::path cache_filename = getThemeDir() / cache_basename;
+ fs::path cache_filename = getCacheDir() / cache_basename;
if(fs::exists(cache_filename)) {
if(fs::last_write_time(filename) > fs::last_write_time(cache_filename)) {
// SVG file is newer we should update cache
|