redo cache switch

This commit is contained in:
David Kelly 2017-07-05 17:01:31 -07:00
parent 64a443ee0d
commit 4a22fbca1b
10 changed files with 38 additions and 49 deletions

View file

@ -480,6 +480,12 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
static const auto SUPPRESS_SETTINGS_RESET = "--suppress-settings-reset"; static const auto SUPPRESS_SETTINGS_RESET = "--suppress-settings-reset";
bool suppressPrompt = cmdOptionExists(argc, const_cast<const char**>(argv), SUPPRESS_SETTINGS_RESET); bool suppressPrompt = cmdOptionExists(argc, const_cast<const char**>(argv), SUPPRESS_SETTINGS_RESET);
bool previousSessionCrashed = CrashHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt); bool previousSessionCrashed = CrashHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt);
// get dir to use for cache
static const auto CACHE_SWITCH = "--cache";
QString cacheDir = getCmdOption(argc, const_cast<const char**>(argv), CACHE_SWITCH);
if (!cacheDir.isEmpty()) {
qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, cacheDir);
}
Setting::init(); Setting::init();
@ -1218,8 +1224,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
settingsTimer->stop(); settingsTimer->stop();
// Delete it (this will trigger the thread destruction // Delete it (this will trigger the thread destruction
settingsTimer->deleteLater(); settingsTimer->deleteLater();
// Mark the settings thread as finished, so we know we can safely save in the main application // Mark the settings thread as finished, so we know we can safely save in the main application
// shutdown code // shutdown code
_settingsGuard.trigger(); _settingsGuard.trigger();
}); });

View file

@ -101,7 +101,7 @@ int main(int argc, const char* argv[]) {
if (allowMultipleInstances) { if (allowMultipleInstances) {
instanceMightBeRunning = false; 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 // scripts directory appears not to work. See the bug report
// https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine
if (parser.isSet(overrideScriptsPathOption)) { 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<ResourceManager>()->setCacheDir(cacheDir);
// this does the ktx_cache
PathUtils::getAppLocalDataPath(cacheDir);
}
}
if (instanceMightBeRunning) { if (instanceMightBeRunning) {
// Try to connect and send message to existing interface instance // Try to connect and send message to existing interface instance
QLocalSocket socket; QLocalSocket socket;

View file

@ -19,6 +19,8 @@
#include <QtScript/QScriptEngine> #include <QtScript/QScriptEngine>
#include <QtNetwork/QNetworkDiskCache> #include <QtNetwork/QNetworkDiskCache>
#include <shared/GlobalAppProperties.h>
#include "AssetRequest.h" #include "AssetRequest.h"
#include "AssetUpload.h" #include "AssetUpload.h"
#include "AssetUtils.h" #include "AssetUtils.h"
@ -31,11 +33,12 @@
MessageID AssetClient::_currentID = 0; 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){ setCustomDeleter([](Dependency* dependency){
static_cast<AssetClient*>(dependency)->deleteLater(); static_cast<AssetClient*>(dependency)->deleteLater();
}); });
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
auto& packetReceiver = nodeList->getPacketReceiver(); auto& packetReceiver = nodeList->getPacketReceiver();
@ -105,7 +108,7 @@ void AssetClient::handleAssetMappingOperationReply(QSharedPointer<ReceivedMessag
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
AssetServerError error; AssetServerError error;
message->readPrimitive(&error); message->readPrimitive(&error);
@ -132,13 +135,13 @@ void AssetClient::handleAssetMappingOperationReply(QSharedPointer<ReceivedMessag
bool haveAssetServer() { bool haveAssetServer() {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (!assetServer) { if (!assetServer) {
qCWarning(asset_client) << "Could not complete AssetClient operation " qCWarning(asset_client) << "Could not complete AssetClient operation "
<< "since you are not currently connected to an asset-server."; << "since you are not currently connected to an asset-server.";
return false; return false;
} }
return true; return true;
} }
@ -220,14 +223,14 @@ MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffse
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) { if (assetServer) {
auto messageID = ++_currentID; auto messageID = ++_currentID;
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(start) + sizeof(end); auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(start) + sizeof(end);
auto packet = NLPacket::create(PacketType::AssetGet, payloadSize, true); auto packet = NLPacket::create(PacketType::AssetGet, payloadSize, true);
qCDebug(asset_client) << "Requesting data from" << start << "to" << end << "of" << hash << "from asset-server."; qCDebug(asset_client) << "Requesting data from" << start << "to" << end << "of" << hash << "from asset-server.";
packet->writePrimitive(messageID); packet->writePrimitive(messageID);
packet->write(QByteArray::fromHex(hash.toLatin1())); packet->write(QByteArray::fromHex(hash.toLatin1()));
@ -254,10 +257,10 @@ MessageID AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callbac
if (assetServer) { if (assetServer) {
auto messageID = ++_currentID; auto messageID = ++_currentID;
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH; auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH;
auto packet = NLPacket::create(PacketType::AssetGetInfo, payloadSize, true); auto packet = NLPacket::create(PacketType::AssetGetInfo, payloadSize, true);
packet->writePrimitive(messageID); packet->writePrimitive(messageID);
packet->write(QByteArray::fromHex(hash.toLatin1())); packet->write(QByteArray::fromHex(hash.toLatin1()));
@ -278,7 +281,7 @@ void AssetClient::handleAssetGetInfoReply(QSharedPointer<ReceivedMessage> messag
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
auto assetHash = message->read(SHA256_HASH_LENGTH); auto assetHash = message->read(SHA256_HASH_LENGTH);
AssetServerError error; AssetServerError error;
message->readPrimitive(&error); message->readPrimitive(&error);
@ -367,7 +370,7 @@ void AssetClient::handleAssetGetReply(QSharedPointer<ReceivedMessage> message, S
callbacks.completeCallback(true, error, message->readAll()); callbacks.completeCallback(true, error, message->readAll());
} }
messageCallbackMap.erase(requestIt); messageCallbackMap.erase(requestIt);
} }
} }
@ -478,7 +481,7 @@ MessageID AssetClient::getAllAssetMappings(MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) { if (assetServer) {
auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); 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) { MessageID AssetClient::deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) { if (assetServer) {
auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); 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<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) { if (assetServer) {
auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true); auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true);
@ -644,7 +647,7 @@ MessageID AssetClient::uploadAsset(const QByteArray& data, UploadResultCallback
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) { if (assetServer) {
auto packetList = NLPacketList::create(PacketType::AssetUpload, QByteArray(), true, true); auto packetList = NLPacketList::create(PacketType::AssetUpload, QByteArray(), true, true);
@ -682,7 +685,7 @@ void AssetClient::handleAssetUploadReply(QSharedPointer<ReceivedMessage> message
} else { } else {
auto hash = message->read(SHA256_HASH_LENGTH); auto hash = message->read(SHA256_HASH_LENGTH);
hashString = hash.toHex(); hashString = hash.toHex();
qCDebug(asset_client) << "Successfully uploaded asset to asset-server - SHA256 hash is " << hashString; qCDebug(asset_client) << "Successfully uploaded asset to asset-server - SHA256 hash is " << hashString;
} }

View file

@ -49,7 +49,7 @@ using ProgressCallback = std::function<void(qint64 totalReceived, qint64 total)>
class AssetClient : public QObject, public Dependency { class AssetClient : public QObject, public Dependency {
Q_OBJECT Q_OBJECT
public: public:
AssetClient(const QString& cacheDir=""); AssetClient();
Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path); Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path);
Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest(); Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest();

View file

@ -28,7 +28,7 @@
ResourceManager::ResourceManager() { ResourceManager::ResourceManager() {
_thread.setObjectName("Resource Manager Thread"); _thread.setObjectName("Resource Manager Thread");
auto assetClient = DependencyManager::set<AssetClient>(_cacheDir); auto assetClient = DependencyManager::set<AssetClient>();
assetClient->moveToThread(&_thread); assetClient->moveToThread(&_thread);
QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init); QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::init);
@ -160,7 +160,3 @@ bool ResourceManager::resourceExists(const QUrl& url) {
return false; return false;
} }
void ResourceManager::setCacheDir(const QString& cacheDir) {
// TODO: check for existence?
_cacheDir = cacheDir;
}

View file

@ -59,7 +59,6 @@ private:
PrefixMap _prefixMap; PrefixMap _prefixMap;
QMutex _prefixMapLock; QMutex _prefixMapLock;
QString _cacheDir;
}; };
#endif #endif

View file

@ -19,6 +19,7 @@
#include "PathUtils.h" #include "PathUtils.h"
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
#include <mutex> // std::once #include <mutex> // std::once
#include "shared/GlobalAppProperties.h"
const QString& PathUtils::resourcesPath() { const QString& PathUtils::resourcesPath() {
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -34,12 +35,8 @@ QString PathUtils::getAppDataPath() {
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/"; return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
} }
QString PathUtils::getAppLocalDataPath(const QString& overridePath /* = "" */) { QString PathUtils::getAppLocalDataPath() {
static QString overriddenPath = ""; QString overriddenPath = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString();
// set the overridden path if one was passed in
if (!overridePath.isEmpty()) {
overriddenPath = overridePath;
}
// return overridden path if set // return overridden path if set
if (!overriddenPath.isEmpty()) { if (!overriddenPath.isEmpty()) {
return overriddenPath; return overriddenPath;

View file

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

View file

@ -17,6 +17,7 @@ namespace hifi { namespace properties {
const char* TEST = "com.highfidelity.test"; const char* TEST = "com.highfidelity.test";
const char* TRACING = "com.highfidelity.tracing"; const char* TRACING = "com.highfidelity.tracing";
const char* HMD = "com.highfidelity.hmd"; const char* HMD = "com.highfidelity.hmd";
const char* APP_LOCAL_DATA_PATH = "com.highfidelity.appLocalDataPath";
namespace gl { namespace gl {
const char* BACKEND = "com.highfidelity.gl.backend"; const char* BACKEND = "com.highfidelity.gl.backend";

View file

@ -19,6 +19,7 @@ namespace hifi { namespace properties {
extern const char* TEST; extern const char* TEST;
extern const char* TRACING; extern const char* TRACING;
extern const char* HMD; extern const char* HMD;
extern const char* APP_LOCAL_DATA_PATH;
namespace gl { namespace gl {
extern const char* BACKEND; extern const char* BACKEND;