Mercurial > hg > svcore
changeset 680:27cdabba2d3e
Better system-specific unbundle locations for ResourceFinder; use same location for TempDirectory
author | Chris Cannam |
---|---|
date | Mon, 09 May 2011 16:58:24 +0100 |
parents | c8badbd4c005 |
children | 6097aacd7ba3 |
files | base/ResourceFinder.cpp base/ResourceFinder.h base/TempDirectory.cpp |
diffstat | 3 files changed, 41 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/base/ResourceFinder.cpp Wed May 04 14:05:08 2011 +0100 +++ b/base/ResourceFinder.cpp Mon May 09 16:58:24 2011 +0100 @@ -47,7 +47,7 @@ - on OS/X, in $HOME/Library/Application Support/<appname> - on Windows, in %ProgramFiles%/<company>/<appname> - - on Windows, in (where?) + - on Windows, in (where?) something from http://msdn.microsoft.com/en-us/library/dd378457%28v=vs.85%29.aspx ? These locations are searched in reverse order (user-installed copies take priority over system-installed copies take priority @@ -92,12 +92,20 @@ QString ResourceFinder::getUserResourcePrefix() { +#ifdef Q_OS_WIN32 + char *homedrive = getenv("HOMEDRIVE"); + char *homepath = getenv("HOMEPATH"); + QString home; + if (homedrive && homepath) { + home = QString("%1%2").arg(homedrive).arg(homepath); + } else { + home = QDir::home().absolutePath(); + } + if (home == "") return ""; + return QString("%1/.%2").arg(qApp->applicationName()); //!!! wrong +#else char *home = getenv("HOME"); if (!home || !home[0]) return ""; - -#ifdef Q_OS_WIN32 - return QString(); //!!!??? -#else #ifdef Q_OS_MAC return QString("%1/Library/Application Support/%2/%3") .arg(home)
--- a/base/ResourceFinder.h Wed May 04 14:05:08 2011 +0100 +++ b/base/ResourceFinder.h Mon May 09 16:58:24 2011 +0100 @@ -106,9 +106,26 @@ */ bool unbundleResource(QString resourceCat, QString fileName); -protected: + /** + * Return the root path for user-specific resource installation + * for this application (i.e. resources beneath the user's home + * directory). + */ QString getUserResourcePrefix(); + + /** + * Return the root paths for systemwide resource installations for + * this application. + */ QStringList getSystemResourcePrefixList(); + + /** + * Return all root paths for resource installations for this + * application, in the order in which they will be searched. This + * list consists of the user-specific path + * (getUserResourcePrefix()) followed by the systemwide paths + * (getSystemResourcePrefixList()). + */ QStringList getResourcePrefixList(); };
--- a/base/TempDirectory.cpp Wed May 04 14:05:08 2011 +0100 +++ b/base/TempDirectory.cpp Mon May 09 16:58:24 2011 +0100 @@ -14,6 +14,7 @@ */ #include "TempDirectory.h" +#include "ResourceFinder.h" #include "system/System.h" #include "Exceptions.h" @@ -58,34 +59,26 @@ TempDirectory::getContainingPath() { QMutexLocker locker(&m_mutex); - + QSettings settings; settings.beginGroup("TempDirectory"); QString svDirParent = settings.value("create-in", "$HOME").toString(); settings.endGroup(); -#ifdef Q_OS_WIN32 - char *homedrive = getenv("HOMEDRIVE"); - char *homepath = getenv("HOMEPATH"); - if (homedrive && homepath) { - svDirParent.replace("$HOME", QString("%1%2").arg(homedrive).arg(homepath)); - } else { - svDirParent.replace("$HOME", QDir::home().absolutePath()); + QString svDir = ResourceFinder().getUserResourcePrefix(); + if (svDirParent != "$HOME") { + //!!! iffy + svDir.replace(QDir::home().absolutePath(), svDirParent); } -#else - svDirParent.replace("$HOME", QDir::home().absolutePath()); -#endif - QString svDirBase = ".sv1"; - QString svDir = QDir(svDirParent).filePath(svDirBase); if (!QFileInfo(svDir).exists()) { - if (!QDir(svDirParent).mkdir(svDirBase)) { + if (!QDir(svDirParent).mkdir(svDir)) { throw DirectoryCreationFailed(QString("%1 directory in %2") - .arg(svDirBase).arg(svDirParent)); + .arg(svDir).arg(svDirParent)); } } else if (!QFileInfo(svDir).isDir()) { - throw DirectoryCreationFailed(QString("%1/%2 is not a directory") - .arg(svDirParent).arg(svDirBase)); + throw DirectoryCreationFailed(QString("%1 is not a directory") + .arg(svDir)); } cleanupAbandonedDirectories(svDir);