Files
UnrealEngineUWP/Engine/Source/Runtime/RuntimeAssetCache/Private/RuntimeAssetCacheFilesystemBackend.cpp
Geremy Mustard 7e2fa737e4 #ue4 RuntimeAssetCache - fixed bug preventing the cached meta data from being read (was passing in a file path for the CacheKey instead of just the file name)
--------
Integrated using branch UE4-to-UE4-Fortnite-Simple (reversed) of change#2639444 by Geremy.Mustard on 2015/07/30 17:22:19.

[CL 2639455 by Geremy Mustard in Main branch]
2015-07-30 17:25:18 -04:00

80 lines
2.7 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "RuntimeAssetCachePrivatePCH.h"
#include "RuntimeAssetCacheFilesystemBackend.h"
#include "RuntimeAssetCacheEntryMetadata.h"
#include "RuntimeAssetCacheBucket.h"
FArchive* FRuntimeAssetCacheFilesystemBackend::CreateReadArchive(FName Bucket, const TCHAR* CacheKey)
{
FString Path = FPaths::Combine(*PathToRAC, *Bucket.ToString(), CacheKey);
return IFileManager::Get().CreateFileReader(*Path);
}
FArchive* FRuntimeAssetCacheFilesystemBackend::CreateWriteArchive(FName Bucket, const TCHAR* CacheKey)
{
FString Path = FPaths::Combine(*PathToRAC, *Bucket.ToString(), CacheKey);
return IFileManager::Get().CreateFileWriter(*Path);
}
FRuntimeAssetCacheFilesystemBackend::FRuntimeAssetCacheFilesystemBackend()
{
GConfig->GetString(TEXT("RuntimeAssetCache"), TEXT("PathToRAC"), PathToRAC, GEngineIni);
PathToRAC = FPaths::GameSavedDir() / PathToRAC;
}
bool FRuntimeAssetCacheFilesystemBackend::RemoveCacheEntry(const FName Bucket, const TCHAR* CacheKey)
{
FString Path = FPaths::Combine(*PathToRAC, *Bucket.ToString(), CacheKey);
return IFileManager::Get().Delete(*Path);
}
bool FRuntimeAssetCacheFilesystemBackend::ClearCache()
{
return IFileManager::Get().DeleteDirectory(*PathToRAC, false, true);
}
bool FRuntimeAssetCacheFilesystemBackend::ClearCache(FName Bucket)
{
return IFileManager::Get().DeleteDirectory(*FPaths::Combine(*PathToRAC, *Bucket.ToString()), false, true);
}
FRuntimeAssetCacheBucket* FRuntimeAssetCacheFilesystemBackend::PreLoadBucket(FName BucketName, int32 BucketSize)
{
FString Path = FPaths::Combine(*PathToRAC, *BucketName.ToString());
FRuntimeAssetCacheBucket* Result = new FRuntimeAssetCacheBucket(BucketSize);
class FRuntimeAssetCacheFilesystemBackendDirectoryVisitor : public IPlatformFile::FDirectoryVisitor
{
public:
FRuntimeAssetCacheFilesystemBackendDirectoryVisitor(FRuntimeAssetCacheBucket* InBucket, FName InBucketName, FRuntimeAssetCacheFilesystemBackend* InBackend)
: Bucket(InBucket)
, BucketName(InBucketName)
, Backend(InBackend)
{ }
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
{
if (bIsDirectory)
{
return true;
}
FString CacheKey = FPaths::GetBaseFilename(FilenameOrDirectory);
FArchive* Ar = Backend->CreateReadArchive(BucketName, *CacheKey);
FCacheEntryMetadata* Metadata = Backend->PreloadMetadata(Ar);
Bucket->AddMetadataEntry(*FPaths::GetBaseFilename(FilenameOrDirectory), Metadata, true);
delete Ar;
return true;
}
private:
FRuntimeAssetCacheBucket* Bucket;
FName BucketName;
FRuntimeAssetCacheFilesystemBackend* Backend;
} Visitor(Result, BucketName, this);
IFileManager::Get().IterateDirectory(*Path, Visitor);
return Result;
}