From 5845b069a3d71c6eae9a0a3d2ae0fee00ce8e717 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 4 Aug 2012 17:16:06 +0100 Subject: [PATCH] =?UTF-8?q?Use=20a=20sensible=20spotify=20settings=20direc?= =?UTF-8?q?tory=20on=20Windows=20instead=20of=20C:\HKEY=5FCURRENT=5FUSER\.?= =?UTF-8?q?..=20=E0=B2=A0=5F=E0=B2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spotify_utilities.cpp | 45 +++++++++---------- .../spotify_utilities.h | 5 ++- .../spotify_utilities.mm | 2 +- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/ext/clementine-spotifyblob/spotify_utilities.cpp b/ext/clementine-spotifyblob/spotify_utilities.cpp index 96a81d671..d49676c85 100644 --- a/ext/clementine-spotifyblob/spotify_utilities.cpp +++ b/ext/clementine-spotifyblob/spotify_utilities.cpp @@ -29,39 +29,36 @@ namespace utilities { +QString GetCacheDirectory() { + QString user_cache = GetUserDataDirectory(); + return user_cache + "/" + QCoreApplication::applicationName() + "/spotify-cache"; +} + #ifndef Q_OS_DARWIN // See spotify_utilities.mm for Mac implementation. -QString GetUserCacheDirectory() { -#ifndef Q_OS_WINDOWS +QString GetUserDataDirectory() { const char* xdg_cache_dir = getenv("XDG_CACHE_HOME"); if (!xdg_cache_dir) { return QDir::homePath() + "/.config"; } return QString::fromLocal8Bit(xdg_cache_dir); - -#else // Q_OS_WINDOWS - const char* cache_dir = getenv("APPDATA"); - if (!cache_dir) { - return QDir::homePath() + "/.config/"; - } - return QDir::fromNativeSeparators(QString::fromLocal8Bit(cache_dir)); -#endif // Q_OS_WINDOWS -} -#endif // Q_OS_DARWIN - -QString GetCacheDirectory() { - QString user_cache = GetUserCacheDirectory(); - return user_cache + "/" + QCoreApplication::applicationName() + "/spotify-cache"; } -#ifndef Q_OS_DARWIN QString GetSettingsDirectory() { - QSettings settings; - QString file_name = settings.fileName(); - QFileInfo info(file_name); - QDir dir = info.dir(); - dir.mkdir("spotify-settings"); - return info.absolutePath() + "/spotify-settings"; + QString ret; + +#ifdef Q_OS_WIN32 + ret = GetUserDataDirectory() + "/" + QCoreApplication::applicationName() + "/spotify-settings"; +#else + ret = QFileInfo(QSettings().fileName()).absolutePath() + "/spotify-settings"; +#endif // Q_OS_WIN32 + + // Create the directory + QDir dir; + dir.mkpath(ret); + + return ret; } -#endif + +#endif // Q_OS_DARWIN } // namespace utilities diff --git a/ext/clementine-spotifyblob/spotify_utilities.h b/ext/clementine-spotifyblob/spotify_utilities.h index 97aeefb43..77481a540 100644 --- a/ext/clementine-spotifyblob/spotify_utilities.h +++ b/ext/clementine-spotifyblob/spotify_utilities.h @@ -25,8 +25,9 @@ namespace utilities { -// Get the path to the current user's local cache for all apps. -QString GetUserCacheDirectory(); +// Get the path to the current user's data directory for all apps. +QString GetUserDataDirectory(); + // Get the path for Clementine's cache. QString GetCacheDirectory(); diff --git a/ext/clementine-spotifyblob/spotify_utilities.mm b/ext/clementine-spotifyblob/spotify_utilities.mm index 7e6cf5568..dcfad233b 100644 --- a/ext/clementine-spotifyblob/spotify_utilities.mm +++ b/ext/clementine-spotifyblob/spotify_utilities.mm @@ -6,7 +6,7 @@ namespace utilities { -QString GetUserCacheDirectory() { +QString GetUserDataDirectory() { NSAutoreleasePool* pool = [NSAutoreleasePool alloc]; [pool init];