comparison base/ResourceFinder.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents 5ac102155409
children 57833933cc75
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
33 33
34 #include <cstdlib> 34 #include <cstdlib>
35 #include <iostream> 35 #include <iostream>
36 #include <stdexcept> 36 #include <stdexcept>
37 37
38 #include "system/System.h"
39
38 /** 40 /**
39 Resource files may be found in three places: 41 Resource files may be found in three places:
40 42
41 * Bundled into the application as Qt4 resources. These may be 43 * Bundled into the application as Qt4 resources. These may be
42 opened using Qt classes such as QFile, with "fake" file paths 44 opened using Qt classes such as QFile, with "fake" file paths
65 // returned in order of priority 67 // returned in order of priority
66 68
67 QStringList list; 69 QStringList list;
68 70
69 #ifdef Q_OS_WIN32 71 #ifdef Q_OS_WIN32
70 char *programFiles = getenv("ProgramFiles"); 72 std::string programFiles;
71 if (programFiles && programFiles[0]) { 73 (void)getEnvUtf8("ProgramFiles", programFiles);
74 if (programFiles != "") {
72 list << QString("%1/%2/%3") 75 list << QString("%1/%2/%3")
73 .arg(programFiles) 76 .arg(QString::fromStdString(programFiles))
74 .arg(qApp->organizationName()) 77 .arg(qApp->organizationName())
75 .arg(qApp->applicationName()); 78 .arg(qApp->applicationName());
76 } else { 79 } else {
77 list << QString("C:/Program Files/%1/%2") 80 list << QString("C:/Program Files/%1/%2")
78 .arg(qApp->organizationName()) 81 .arg(qApp->organizationName())
131 cerr << "ERROR: Can't use ResourceFinder before setting application name" << endl; 134 cerr << "ERROR: Can't use ResourceFinder before setting application name" << endl;
132 throw std::logic_error("Can't use ResourceFinder before setting application name"); 135 throw std::logic_error("Can't use ResourceFinder before setting application name");
133 } 136 }
134 137
135 #if QT_VERSION >= 0x050000 138 #if QT_VERSION >= 0x050000
139
136 // This is expected to be much more reliable than 140 // This is expected to be much more reliable than
137 // getOldStyleUserResourcePrefix(), but it returns a different 141 // getOldStyleUserResourcePrefix(), but it returns a different
138 // directory because it includes the organisation name (which is 142 // directory because it includes the organisation name (which is
139 // fair enough). Hence migrateOldStyleResources() which moves 143 // fair enough). Hence migrateOldStyleResources() which moves
140 // across any resources found in the old-style path the first time 144 // across any resources found in the old-style path the first time
141 // we look for the new-style one 145 // we look for the new-style one
146 #if QT_VERSION >= 0x050400
142 return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); 147 return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
143 #else 148 #else
149 cerr << "WARNING: ResourceFinder::getOldStyleUserResourcePrefix: Building with older version of Qt (pre 5.4), resource location may be incompatible with future versions" << endl;
150 return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
151 #endif
152
153 #else
154 cerr << "WARNING: ResourceFinder::getOldStyleUserResourcePrefix: Building with very old version of Qt (pre 5.0?), resource location may be incompatible with future versions" << endl;
144 return getOldStyleUserResourcePrefix(); 155 return getOldStyleUserResourcePrefix();
145 #endif 156 #endif
146 } 157 }
147 158
148 static void 159 static void
237 for (QStringList::const_iterator i = prefixes.begin(); 248 for (QStringList::const_iterator i = prefixes.begin();
238 i != prefixes.end(); ++i) { 249 i != prefixes.end(); ++i) {
239 250
240 QString prefix = *i; 251 QString prefix = *i;
241 252
242 SVDEBUG << "ResourceFinder::getResourcePath: Looking up file \"" << fileName << "\" for category \"" << resourceCat << "\" in prefix \"" << prefix << "\"" << endl; 253 // cerr << "ResourceFinder::getResourcePath: Looking up file \"" << fileName << "\" for category \"" << resourceCat << "\" in prefix \"" << prefix << "\"" << endl;
243 254
244 QString path = 255 QString path =
245 QString("%1%2/%3").arg(prefix).arg(resourceCat).arg(fileName); 256 QString("%1%2/%3").arg(prefix).arg(resourceCat).arg(fileName);
246 if (QFileInfo(path).exists() && QFileInfo(path).isReadable()) { 257 if (QFileInfo(path).exists() && QFileInfo(path).isReadable()) {
247 cerr << "Found it!" << endl; 258 // cerr << "Found it!" << endl;
248 return path; 259 return path;
249 } 260 }
250 } 261 }
251 262
252 return ""; 263 return "";