macOS: Fix standardLocations() returns invalid path
The file path included in the return value was
incorrect when giving the following value to the argument of
"QStandardPaths::standardLocations()".
- QStandardPaths::AppDataLocation
- QStandardPaths::AppLocalDataLocation
- QStandardPaths::DataLocation
The function to obtain the path to <AppName>.app changed from
CFURLCopyPath() to CFURLCopyFileSystemPath() by commit id
c0da37a806
.
CFURLCopyPath() returns a value with a path delimiter appended at the
end, but CFURLCopyFileSystemPath() is not.
This is a commit to append '/' to the end of the return value of
CFURLCopyFileSystemPath().
Task-number: QTBUG-61159
Change-Id: Icaebdf09d9cdf992d59c16a398dfe666e6225f99
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
parent
2764d82dc4
commit
aebc9023bb
@ -203,28 +203,17 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
|
||||
if (type == AppDataLocation || type == AppLocalDataLocation) {
|
||||
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
||||
if (mainBundle) {
|
||||
CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);
|
||||
CFStringRef cfBundlePath = CFURLCopyFileSystemPath(bundleUrl, kCFURLPOSIXPathStyle);
|
||||
QString bundlePath = QString::fromCFString(cfBundlePath);
|
||||
CFRelease(cfBundlePath);
|
||||
CFRelease(bundleUrl);
|
||||
|
||||
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(mainBundle);
|
||||
CFStringRef cfResourcesPath = CFURLCopyFileSystemPath(resourcesUrl,
|
||||
kCFURLPOSIXPathStyle);
|
||||
QString resourcesPath = QString::fromCFString(cfResourcesPath);
|
||||
CFRelease(cfResourcesPath);
|
||||
CFRelease(resourcesUrl);
|
||||
|
||||
// Handle bundled vs unbundled executables. CFBundleGetMainBundle() returns
|
||||
// a valid bundle in both cases. CFBundleCopyResourcesDirectoryURL() returns
|
||||
// an absolute path for unbundled executables.
|
||||
if (resourcesPath.startsWith(QLatin1Char('/')))
|
||||
dirs.append(resourcesPath);
|
||||
else
|
||||
dirs.append(bundlePath + resourcesPath);
|
||||
if (QCFType<CFURLRef> resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle)) {
|
||||
if (QCFType<CFURLRef> absoluteResouresURL = CFURLCopyAbsoluteURL(resourcesURL)) {
|
||||
if (QCFType<CFStringRef> path = CFURLCopyFileSystemPath(absoluteResouresURL,
|
||||
kCFURLPOSIXPathStyle)) {
|
||||
dirs.append(QString::fromCFString(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QString localDir = writableLocation(type);
|
||||
if (!localDir.isEmpty())
|
||||
dirs.prepend(localDir);
|
||||
|
Loading…
Reference in New Issue
Block a user