comparison base/TempDirectory.cpp @ 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 29efe322ab47
children b4a8d8221eaf
comparison
equal deleted inserted replaced
679:c8badbd4c005 680:27cdabba2d3e
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "TempDirectory.h" 16 #include "TempDirectory.h"
17 #include "ResourceFinder.h"
17 #include "system/System.h" 18 #include "system/System.h"
18 #include "Exceptions.h" 19 #include "Exceptions.h"
19 20
20 #include <QDir> 21 #include <QDir>
21 #include <QFile> 22 #include <QFile>
56 57
57 QString 58 QString
58 TempDirectory::getContainingPath() 59 TempDirectory::getContainingPath()
59 { 60 {
60 QMutexLocker locker(&m_mutex); 61 QMutexLocker locker(&m_mutex);
61 62
62 QSettings settings; 63 QSettings settings;
63 settings.beginGroup("TempDirectory"); 64 settings.beginGroup("TempDirectory");
64 QString svDirParent = settings.value("create-in", "$HOME").toString(); 65 QString svDirParent = settings.value("create-in", "$HOME").toString();
65 settings.endGroup(); 66 settings.endGroup();
66 67
67 #ifdef Q_OS_WIN32 68 QString svDir = ResourceFinder().getUserResourcePrefix();
68 char *homedrive = getenv("HOMEDRIVE"); 69 if (svDirParent != "$HOME") {
69 char *homepath = getenv("HOMEPATH"); 70 //!!! iffy
70 if (homedrive && homepath) { 71 svDir.replace(QDir::home().absolutePath(), svDirParent);
71 svDirParent.replace("$HOME", QString("%1%2").arg(homedrive).arg(homepath)); 72 }
72 } else { 73
73 svDirParent.replace("$HOME", QDir::home().absolutePath());
74 }
75 #else
76 svDirParent.replace("$HOME", QDir::home().absolutePath());
77 #endif
78
79 QString svDirBase = ".sv1";
80 QString svDir = QDir(svDirParent).filePath(svDirBase);
81 if (!QFileInfo(svDir).exists()) { 74 if (!QFileInfo(svDir).exists()) {
82 if (!QDir(svDirParent).mkdir(svDirBase)) { 75 if (!QDir(svDirParent).mkdir(svDir)) {
83 throw DirectoryCreationFailed(QString("%1 directory in %2") 76 throw DirectoryCreationFailed(QString("%1 directory in %2")
84 .arg(svDirBase).arg(svDirParent)); 77 .arg(svDir).arg(svDirParent));
85 } 78 }
86 } else if (!QFileInfo(svDir).isDir()) { 79 } else if (!QFileInfo(svDir).isDir()) {
87 throw DirectoryCreationFailed(QString("%1/%2 is not a directory") 80 throw DirectoryCreationFailed(QString("%1 is not a directory")
88 .arg(svDirParent).arg(svDirBase)); 81 .arg(svDir));
89 } 82 }
90 83
91 cleanupAbandonedDirectories(svDir); 84 cleanupAbandonedDirectories(svDir);
92 85
93 return svDir; 86 return svDir;