AssetCache::AssetCache(AssetAPI *owner, QString assetCacheDirectory) : QNetworkDiskCache(owner), assetAPI(owner), cacheDirectory(GuaranteeTrailingSlash(assetCacheDirectory)) { LogInfo("Using AssetCache in directory '" + assetCacheDirectory.toStdString() + "'"); // Check that the main directory exists QDir assetDir(cacheDirectory); if (!assetDir.exists()) { QString dirName = cacheDirectory.split("/", QString::SkipEmptyParts).last(); QString parentPath = cacheDirectory; parentPath.chop(dirName.length()+1); QDir parentDir(parentPath); parentDir.mkdir(dirName); } // Check that the needed subfolders exist if (!assetDir.exists("data")) assetDir.mkdir("data"); assetDataDir = QDir(cacheDirectory + "data"); if (!assetDir.exists("metadata")) assetDir.mkdir("metadata"); assetMetaDataDir = QDir(cacheDirectory + "metadata"); // Set for QNetworkDiskCache setCacheDirectory(cacheDirectory); }
AssetCache::AssetCache(AssetAPI *owner, QString assetCacheDirectory) : assetAPI(owner), cacheDirectory(GuaranteeTrailingSlash(QDir::fromNativeSeparators(assetCacheDirectory))) { LogInfo("* Asset cache directory : " + QDir::toNativeSeparators(cacheDirectory)); // Check that the main directory exists QDir assetDir(cacheDirectory); if (!assetDir.exists()) { QString dirName = cacheDirectory.split("/", QString::SkipEmptyParts).last(); QString parentPath = cacheDirectory; parentPath.chop(dirName.length()+1); QDir parentDir(parentPath); parentDir.mkdir(dirName); } // Check that the needed subfolders exist if (!assetDir.exists("data")) assetDir.mkdir("data"); assetDataDir = QDir(cacheDirectory + "data"); // Check --clearAssetCache start param if (owner->GetFramework()->HasCommandLineParameter("--clearAssetCache") || owner->GetFramework()->HasCommandLineParameter("--clear-asset-cache")) /**< @todo Remove support for the deprecated parameter version at some point. */ { LogInfo("AssetCache: Removing all data and metadata files from cache, found 'clearAssetCache' from the startup params!"); ClearAssetCache(); } }
HttpAssetStorage::HttpAssetStorage(Urho3D::Context* context, const String &name, const String &baseUrl, const String &localDir) : IAssetStorage(context), // HttpAssetStorage name_(name), baseUrl_(baseUrl), localDir_(localDir.Empty() ? localDir : GuaranteeTrailingSlash(localDir)) { // IAssetStorage writable = false; liveUpdate = false; autoDiscoverable = false; isReplicated = true; }
void ConfigAPI::PrepareDataFolder(QString configFolder) { QDir config = QDir(Application::ParseWildCardFilename(configFolder.trimmed())); if (!config.exists()) { bool success = config.mkpath("."); if (!success) { LogError("Failed to create configuration folder \"" + config.absolutePath() + "\"! Check that this path is valid, and it is write-accessible!"); return; } } configFolder_ = GuaranteeTrailingSlash(config.absolutePath()); LogInfo("* Config directory : " + QDir::toNativeSeparators(configFolder_)); }
AssetStoragePtr HttpAssetProvider::AddStorage(const QString &location, const QString &name) { QString locationCleaned = GuaranteeTrailingSlash(location.trimmed()); // Check if same location and name combination already exists for(size_t i=0; i<storages.size(); ++i) { HttpAssetStoragePtr checkStorage = storages[i]; if (!checkStorage.get()) continue; if (checkStorage->baseAddress == locationCleaned && checkStorage->storageName == name) return checkStorage; } // Add new if not found HttpAssetStoragePtr storage = HttpAssetStoragePtr(new HttpAssetStorage()); storage->baseAddress = locationCleaned; storage->storageName = name; storage->provider = this->shared_from_this(); storages.push_back(storage); return storage; }
QString AssetCache::CacheDirectory() const { return GuaranteeTrailingSlash(assetDataDir.absolutePath()); }