Merge pull request #10803 from davidkelly/dk/cacheSwitch

new --cache switch for interface
This commit is contained in:
Howard Stearns 2017-06-27 12:23:23 -07:00 committed by GitHub
commit 20f713a241
9 changed files with 55 additions and 15 deletions

View file

@ -37,8 +37,6 @@
#include <QtQml/QQmlEngine>
#include <QtQuick/QQuickWindow>
#include <QtWebEngineWidgets/QWebEngineProfile>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QMessageBox>

View file

@ -297,6 +297,7 @@ public:
void setAvatarOverrideUrl(const QUrl& url, bool save);
QUrl getAvatarOverrideUrl() { return _avatarOverrideUrl; }
bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
void setCacheOverrideDir(const QString& dirName) { _cacheDir = dirName; }
signals:
void svoImportRequested(const QString& url);
@ -688,5 +689,7 @@ private:
QUrl _avatarOverrideUrl;
bool _saveAvatarOverrideUrl { false };
QString _cacheDir;
};
#endif // hifi_Application_h

View file

@ -23,6 +23,7 @@
#include <gl/OpenGLVersionChecker.h>
#include <SandboxUtils.h>
#include <SharedUtil.h>
#include <NetworkAccessManager.h>
#include "AddressManager.h"
#include "Application.h"
@ -71,15 +72,17 @@ int main(int argc, const char* argv[]) {
QCommandLineOption runServerOption("runServer", "Whether to run the server");
QCommandLineOption serverContentPathOption("serverContentPath", "Where to find server content", "serverContentPath");
QCommandLineOption allowMultipleInstancesOption("allowMultipleInstances", "Allow multiple instances to run");
QCommandLineOption overrideAppLocalDataPathOption("cache", "set test cache <dir>", "dir");
parser.addOption(urlOption);
parser.addOption(noUpdaterOption);
parser.addOption(checkMinSpecOption);
parser.addOption(runServerOption);
parser.addOption(serverContentPathOption);
parser.addOption(overrideAppLocalDataPathOption);
parser.addOption(allowMultipleInstancesOption);
parser.parse(arguments);
const QString& applicationName = getInterfaceSharedMemoryName();
bool instanceMightBeRunning = true;
#ifdef Q_OS_WIN
@ -96,6 +99,19 @@ int main(int argc, const char* argv[]) {
if (allowMultipleInstances) {
instanceMightBeRunning = false;
}
if (parser.isSet(overrideAppLocalDataPathOption)) {
// get dir to use for cache
QString cacheDir = parser.value(overrideAppLocalDataPathOption);
if (!cacheDir.isEmpty()) {
// tell everyone to use the right cache location
//
// this handles data8 and prepared
ResourceManager::setCacheDir(cacheDir);
// this does the ktx_cache
PathUtils::getAppLocalDataPath(cacheDir);
}
}
if (instanceMightBeRunning) {
// Try to connect and send message to existing interface instance
@ -179,7 +195,7 @@ int main(int argc, const char* argv[]) {
QString openvrDllPath = appPath + "/plugins/openvr.dll";
HMODULE openvrDll;
CHECKMINSPECPROC checkMinSpecPtr;
if ((openvrDll = LoadLibrary(openvrDllPath.toLocal8Bit().data())) &&
if ((openvrDll = LoadLibrary(openvrDllPath.toLocal8Bit().data())) &&
(checkMinSpecPtr = (CHECKMINSPECPROC)GetProcAddress(openvrDll, "CheckMinSpec"))) {
if (!checkMinSpecPtr()) {
return -1;

View file

@ -31,7 +31,7 @@
MessageID AssetClient::_currentID = 0;
AssetClient::AssetClient() {
AssetClient::AssetClient(const QString& cacheDir) : _cacheDir(cacheDir) {
setCustomDeleter([](Dependency* dependency){
static_cast<AssetClient*>(dependency)->deleteLater();
});
@ -55,14 +55,15 @@ void AssetClient::init() {
// Setup disk cache if not already
auto& networkAccessManager = NetworkAccessManager::getInstance();
if (!networkAccessManager.cache()) {
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
cachePath = !cachePath.isEmpty() ? cachePath : "interfaceCache";
if (_cacheDir.isEmpty()) {
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
_cacheDir = !cachePath.isEmpty() ? cachePath : "interfaceCache";
}
QNetworkDiskCache* cache = new QNetworkDiskCache();
cache->setMaximumCacheSize(MAXIMUM_CACHE_SIZE);
cache->setCacheDirectory(cachePath);
cache->setCacheDirectory(_cacheDir);
networkAccessManager.setCache(cache);
qInfo() << "ResourceManager disk cache setup at" << cachePath
qInfo() << "ResourceManager disk cache setup at" << _cacheDir
<< "(size:" << MAXIMUM_CACHE_SIZE / BYTES_PER_GIGABYTES << "GB)";
}
}

View file

@ -49,7 +49,7 @@ using ProgressCallback = std::function<void(qint64 totalReceived, qint64 total)>
class AssetClient : public QObject, public Dependency {
Q_OBJECT
public:
AssetClient();
AssetClient(const QString& cacheDir="");
Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path);
Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest();
@ -109,6 +109,8 @@ private:
std::unordered_map<SharedNodePointer, std::unordered_map<MessageID, GetInfoCallback>> _pendingInfoRequests;
std::unordered_map<SharedNodePointer, std::unordered_map<MessageID, UploadResultCallback>> _pendingUploads;
QString _cacheDir;
friend class AssetRequest;
friend class AssetUpload;
friend class MappingRequest;

View file

@ -27,7 +27,7 @@
QThread ResourceManager::_thread;
ResourceManager::PrefixMap ResourceManager::_prefixMap;
QMutex ResourceManager::_prefixMapLock;
QString ResourceManager::_cacheDir;
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
QMutexLocker locker(&_prefixMapLock);
@ -78,7 +78,7 @@ QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) {
void ResourceManager::init() {
_thread.setObjectName("Resource Manager Thread");
auto assetClient = DependencyManager::set<AssetClient>();
auto assetClient = DependencyManager::set<AssetClient>(_cacheDir);
assetClient->moveToThread(&_thread);
QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init);
@ -164,3 +164,7 @@ bool ResourceManager::resourceExists(const QUrl& url) {
return false;
}
void ResourceManager::setCacheDir(const QString& cacheDir) {
// TODO: check for existence?
_cacheDir = cacheDir;
}

View file

@ -40,6 +40,9 @@ public:
// to return to the calling thread so that events can still be processed.
static bool resourceExists(const QUrl& url);
// adjust where we persist the cache
static void setCacheDir(const QString& cacheDir);
private:
static QThread _thread;
@ -47,6 +50,8 @@ private:
static PrefixMap _prefixMap;
static QMutex _prefixMapLock;
static QString _cacheDir;
};
#endif

View file

@ -34,7 +34,18 @@ QString PathUtils::getAppDataPath() {
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
}
QString PathUtils::getAppLocalDataPath() {
QString PathUtils::getAppLocalDataPath(const QString& overridePath /* = "" */) {
static QString overriddenPath = "";
// set the overridden path if one was passed in
if (!overridePath.isEmpty()) {
overriddenPath = overridePath;
}
// return overridden path if set
if (!overriddenPath.isEmpty()) {
return overriddenPath;
}
// otherwise return standard path
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/";
}

View file

@ -28,7 +28,7 @@ public:
static const QString& resourcesPath();
static QString getAppDataPath();
static QString getAppLocalDataPath();
static QString getAppLocalDataPath(const QString& overridePath = "");
static QString getAppDataFilePath(const QString& filename);
static QString getAppLocalDataFilePath(const QString& filename);