allow json for uses /~/ for file paths

This commit is contained in:
Dante Ruiz 2018-02-20 11:20:42 -08:00
parent 563c19bb91
commit 8fc50222f5
3 changed files with 10 additions and 4 deletions

View file

@ -17,6 +17,7 @@
#include <StatTracker.h>
#include <shared/FileUtils.h>
#include <pathUtils.h>
#include "ResourceManager.h"
@ -28,7 +29,7 @@ void FileResourceRequest::doSend() {
if (_url.scheme() == URL_SCHEME_QRC) {
filename = ":/" + _url.path();
} else {
filename = _url.toLocalFile();
filename = PathUtils::expandToAppAbsolutePath(_url.toLocalFile(), true);
// sometimes on windows, we see the toLocalFile() return null,
// in this case we will attempt to simply use the url as a string
if (filename.isEmpty()) {

View file

@ -133,10 +133,15 @@ QUrl PathUtils::resourcesUrl(const QString& relativeUrl) {
return QUrl(resourcesUrl() + relativeUrl);
}
QString PathUtils::expandToAppAbsolutePath(const QString& filePath) {
QString PathUtils::expandToAppAbsolutePath(const QString& filePath, bool localPath) {
QString path = filePath;
if (path.startsWith("/~/")) {
path.replace(1, 2, applicationAbsolutePath());
QString absolutePath = applicationAbsolutePath();
if (localPath) {
path.replace(0, 3, absolutePath);
} else {
path.replace(1, 2, absolutePath);
}
}
return path;
}

View file

@ -37,7 +37,7 @@ public:
static QUrl resourcesUrl(const QString& relative);
static const QString& resourcesPath();
static const QString& qmlBaseUrl();
static QString expandToAppAbsolutePath(const QString& filePath);
static QString expandToAppAbsolutePath(const QString& filePath, bool localPath = false);
static QUrl qmlUrl(const QString& relative);
#ifdef DEV_BUILD
static const QString& projectRootPath();