From 4a22fbca1bedcbe1e37cbf37cf776f2e364725f2 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Wed, 5 Jul 2017 17:01:31 -0700 Subject: [PATCH 1/2] redo cache switch --- interface/src/Application.cpp | 10 ++++- interface/src/main.cpp | 16 +------- libraries/networking/src/AssetClient.cpp | 39 ++++++++++--------- libraries/networking/src/AssetClient.h | 2 +- libraries/networking/src/ResourceManager.cpp | 6 +-- libraries/networking/src/ResourceManager.h | 1 - libraries/shared/src/PathUtils.cpp | 9 ++--- libraries/shared/src/PathUtils.h | 2 +- .../shared/src/shared/GlobalAppProperties.cpp | 1 + .../shared/src/shared/GlobalAppProperties.h | 1 + 10 files changed, 38 insertions(+), 49 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 377819c0a0..f9f43757d0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -480,6 +480,12 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { static const auto SUPPRESS_SETTINGS_RESET = "--suppress-settings-reset"; bool suppressPrompt = cmdOptionExists(argc, const_cast(argv), SUPPRESS_SETTINGS_RESET); bool previousSessionCrashed = CrashHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt); + // get dir to use for cache + static const auto CACHE_SWITCH = "--cache"; + QString cacheDir = getCmdOption(argc, const_cast(argv), CACHE_SWITCH); + if (!cacheDir.isEmpty()) { + qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, cacheDir); + } Setting::init(); @@ -1218,8 +1224,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo settingsTimer->stop(); // Delete it (this will trigger the thread destruction settingsTimer->deleteLater(); - // Mark the settings thread as finished, so we know we can safely save in the main application - // shutdown code + // Mark the settings thread as finished, so we know we can safely save in the main application + // shutdown code _settingsGuard.trigger(); }); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 42ceb756b9..a19055d4da 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -101,7 +101,7 @@ int main(int argc, const char* argv[]) { if (allowMultipleInstances) { instanceMightBeRunning = false; } - // this needs to be done here in main, as the mechanism for setting the + // this needs to be done here in main, as the mechanism for setting the // scripts directory appears not to work. See the bug report // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine if (parser.isSet(overrideScriptsPathOption)) { @@ -111,20 +111,6 @@ int main(int argc, const char* argv[]) { } } - 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 - DependencyManager::get()->setCacheDir(cacheDir); - - // this does the ktx_cache - PathUtils::getAppLocalDataPath(cacheDir); - } - } - if (instanceMightBeRunning) { // Try to connect and send message to existing interface instance QLocalSocket socket; diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index e97660da4c..cb0b620a54 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include "AssetRequest.h" #include "AssetUpload.h" #include "AssetUtils.h" @@ -31,11 +33,12 @@ MessageID AssetClient::_currentID = 0; -AssetClient::AssetClient(const QString& cacheDir) : _cacheDir(cacheDir) { +AssetClient::AssetClient() { + _cacheDir = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString(); setCustomDeleter([](Dependency* dependency){ static_cast(dependency)->deleteLater(); }); - + auto nodeList = DependencyManager::get(); auto& packetReceiver = nodeList->getPacketReceiver(); @@ -105,7 +108,7 @@ void AssetClient::handleAssetMappingOperationReply(QSharedPointerreadPrimitive(&messageID); - + AssetServerError error; message->readPrimitive(&error); @@ -132,13 +135,13 @@ void AssetClient::handleAssetMappingOperationReply(QSharedPointer(); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); - + if (!assetServer) { qCWarning(asset_client) << "Could not complete AssetClient operation " << "since you are not currently connected to an asset-server."; return false; } - + return true; } @@ -220,14 +223,14 @@ MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffse SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); if (assetServer) { - + auto messageID = ++_currentID; - + auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(start) + sizeof(end); auto packet = NLPacket::create(PacketType::AssetGet, payloadSize, true); - + qCDebug(asset_client) << "Requesting data from" << start << "to" << end << "of" << hash << "from asset-server."; - + packet->writePrimitive(messageID); packet->write(QByteArray::fromHex(hash.toLatin1())); @@ -254,10 +257,10 @@ MessageID AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callbac if (assetServer) { auto messageID = ++_currentID; - + auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH; auto packet = NLPacket::create(PacketType::AssetGetInfo, payloadSize, true); - + packet->writePrimitive(messageID); packet->write(QByteArray::fromHex(hash.toLatin1())); @@ -278,7 +281,7 @@ void AssetClient::handleAssetGetInfoReply(QSharedPointer messag MessageID messageID; message->readPrimitive(&messageID); auto assetHash = message->read(SHA256_HASH_LENGTH); - + AssetServerError error; message->readPrimitive(&error); @@ -367,7 +370,7 @@ void AssetClient::handleAssetGetReply(QSharedPointer message, S callbacks.completeCallback(true, error, message->readAll()); } - + messageCallbackMap.erase(requestIt); } } @@ -478,7 +481,7 @@ MessageID AssetClient::getAllAssetMappings(MappingOperationCallback callback) { auto nodeList = DependencyManager::get(); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); - + if (assetServer) { auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); @@ -501,7 +504,7 @@ MessageID AssetClient::getAllAssetMappings(MappingOperationCallback callback) { MessageID AssetClient::deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback) { auto nodeList = DependencyManager::get(); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); - + if (assetServer) { auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); @@ -532,7 +535,7 @@ MessageID AssetClient::setAssetMapping(const QString& path, const AssetHash& has auto nodeList = DependencyManager::get(); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); - + if (assetServer) { auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); @@ -644,7 +647,7 @@ MessageID AssetClient::uploadAsset(const QByteArray& data, UploadResultCallback auto nodeList = DependencyManager::get(); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); - + if (assetServer) { auto packetList = NLPacketList::create(PacketType::AssetUpload, QByteArray(), true, true); @@ -682,7 +685,7 @@ void AssetClient::handleAssetUploadReply(QSharedPointer message } else { auto hash = message->read(SHA256_HASH_LENGTH); hashString = hash.toHex(); - + qCDebug(asset_client) << "Successfully uploaded asset to asset-server - SHA256 hash is " << hashString; } diff --git a/libraries/networking/src/AssetClient.h b/libraries/networking/src/AssetClient.h index 2bc694f367..3f6602b76b 100644 --- a/libraries/networking/src/AssetClient.h +++ b/libraries/networking/src/AssetClient.h @@ -49,7 +49,7 @@ using ProgressCallback = std::function class AssetClient : public QObject, public Dependency { Q_OBJECT public: - AssetClient(const QString& cacheDir=""); + AssetClient(); Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path); Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest(); diff --git a/libraries/networking/src/ResourceManager.cpp b/libraries/networking/src/ResourceManager.cpp index e9fe2f1ec1..3ee66f89c1 100644 --- a/libraries/networking/src/ResourceManager.cpp +++ b/libraries/networking/src/ResourceManager.cpp @@ -28,7 +28,7 @@ ResourceManager::ResourceManager() { _thread.setObjectName("Resource Manager Thread"); - auto assetClient = DependencyManager::set(_cacheDir); + auto assetClient = DependencyManager::set(); assetClient->moveToThread(&_thread); QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init); @@ -160,7 +160,3 @@ bool ResourceManager::resourceExists(const QUrl& url) { return false; } -void ResourceManager::setCacheDir(const QString& cacheDir) { - // TODO: check for existence? - _cacheDir = cacheDir; -} diff --git a/libraries/networking/src/ResourceManager.h b/libraries/networking/src/ResourceManager.h index 4e7cd3d92d..fdfd05736e 100644 --- a/libraries/networking/src/ResourceManager.h +++ b/libraries/networking/src/ResourceManager.h @@ -59,7 +59,6 @@ private: PrefixMap _prefixMap; QMutex _prefixMapLock; - QString _cacheDir; }; #endif diff --git a/libraries/shared/src/PathUtils.cpp b/libraries/shared/src/PathUtils.cpp index 1fe9e2f83d..0636411f51 100644 --- a/libraries/shared/src/PathUtils.cpp +++ b/libraries/shared/src/PathUtils.cpp @@ -19,6 +19,7 @@ #include "PathUtils.h" #include #include // std::once +#include "shared/GlobalAppProperties.h" const QString& PathUtils::resourcesPath() { #ifdef Q_OS_MAC @@ -34,12 +35,8 @@ QString PathUtils::getAppDataPath() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/"; } -QString PathUtils::getAppLocalDataPath(const QString& overridePath /* = "" */) { - static QString overriddenPath = ""; - // set the overridden path if one was passed in - if (!overridePath.isEmpty()) { - overriddenPath = overridePath; - } +QString PathUtils::getAppLocalDataPath() { + QString overriddenPath = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString(); // return overridden path if set if (!overriddenPath.isEmpty()) { return overriddenPath; diff --git a/libraries/shared/src/PathUtils.h b/libraries/shared/src/PathUtils.h index 42dd09c8b0..14eb81dd9a 100644 --- a/libraries/shared/src/PathUtils.h +++ b/libraries/shared/src/PathUtils.h @@ -28,7 +28,7 @@ public: static const QString& resourcesPath(); static QString getAppDataPath(); - static QString getAppLocalDataPath(const QString& overridePath = ""); + static QString getAppLocalDataPath(); static QString getAppDataFilePath(const QString& filename); static QString getAppLocalDataFilePath(const QString& filename); diff --git a/libraries/shared/src/shared/GlobalAppProperties.cpp b/libraries/shared/src/shared/GlobalAppProperties.cpp index b0ba0bf83d..6c9f3f9601 100644 --- a/libraries/shared/src/shared/GlobalAppProperties.cpp +++ b/libraries/shared/src/shared/GlobalAppProperties.cpp @@ -17,6 +17,7 @@ namespace hifi { namespace properties { const char* TEST = "com.highfidelity.test"; const char* TRACING = "com.highfidelity.tracing"; const char* HMD = "com.highfidelity.hmd"; + const char* APP_LOCAL_DATA_PATH = "com.highfidelity.appLocalDataPath"; namespace gl { const char* BACKEND = "com.highfidelity.gl.backend"; diff --git a/libraries/shared/src/shared/GlobalAppProperties.h b/libraries/shared/src/shared/GlobalAppProperties.h index b1811586ba..174be61939 100644 --- a/libraries/shared/src/shared/GlobalAppProperties.h +++ b/libraries/shared/src/shared/GlobalAppProperties.h @@ -19,6 +19,7 @@ namespace hifi { namespace properties { extern const char* TEST; extern const char* TRACING; extern const char* HMD; + extern const char* APP_LOCAL_DATA_PATH; namespace gl { extern const char* BACKEND; From 936c21e8497b055feef74de6cbcd8620eda1c91c Mon Sep 17 00:00:00 2001 From: David Kelly Date: Thu, 6 Jul 2017 07:24:58 -0700 Subject: [PATCH 2/2] remove unnecessary cacheDir member --- interface/src/Application.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 28d95a280c..cf0ae91a0f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -299,7 +299,6 @@ 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); @@ -691,6 +690,5 @@ private: QUrl _avatarOverrideUrl; bool _saveAvatarOverrideUrl { false }; - QString _cacheDir; }; #endif // hifi_Application_h