Loading downloaded content

This commit is contained in:
Oleg Petruny 2024-11-19 23:15:45 +01:00
parent e751315be1
commit 3230164736
3 changed files with 15 additions and 7 deletions

Binary file not shown.

View File

@ -21,7 +21,7 @@ namespace
constexpr auto httpContentTypeJson = TEXT("application/json"); constexpr auto httpContentTypeJson = TEXT("application/json");
constexpr auto pakIndexUrl = TEXT("https://pixelyfier.com/lost_edge/content/"); constexpr auto pakIndexUrl = TEXT("https://pixelyfier.com/lost_edge/content/");
const auto pakFileSavePath = FPaths::ProjectDir(); const auto pakFileSavePath = FString::Printf(TEXT("%sDownloaded/"), *FPaths::ProjectDir());
} }
void UContentLoader::BeginDestroy() void UContentLoader::BeginDestroy()
@ -119,7 +119,15 @@ void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback,
FString pakToDownload = SelectContentByMethod(availablePaks, method); FString pakToDownload = SelectContentByMethod(availablePaks, method);
downloadedContent.Add(pakToDownload); downloadedContent.Add(pakToDownload);
UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to download pak %s from index."), *pakToDownload); UE_LOG(LogTemp, Log, TEXT("ContentLoader: Pak selected for loading: %s."), *pakToDownload);
auto savePath = FString::Printf(TEXT("%s%s"), *pakFileSavePath, *pakToDownload);
if(FPlatformFileManager::Get().GetPlatformFile().FileExists(*savePath))
{
UE_LOG(LogTemp, Log, TEXT("ContentLoader: Selected pak already exists... skipping download."));
downloadedCallback.ExecuteIfBound(savePath);
return;
}
FHttpRequestCompleteDelegate pakDownloadCallback; FHttpRequestCompleteDelegate pakDownloadCallback;
pakDownloadCallback.BindLambda([=, this](FHttpRequestPtr request, FHttpResponsePtr response, bool successful) pakDownloadCallback.BindLambda([=, this](FHttpRequestPtr request, FHttpResponsePtr response, bool successful)
@ -132,7 +140,6 @@ void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback,
return; return;
} }
auto savePath = FString::Printf(TEXT("%s%s"), *pakFileSavePath, *pakToDownload);
if(!FFileHelper::SaveArrayToFile(response->GetContent(), *savePath)) if(!FFileHelper::SaveArrayToFile(response->GetContent(), *savePath))
{ {
UE_LOG(LogTemp, Log, TEXT("ContentLoader: Saving pak file %s failed."), *savePath); UE_LOG(LogTemp, Log, TEXT("ContentLoader: Saving pak file %s failed."), *savePath);
@ -143,6 +150,7 @@ void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback,
downloadedCallback.ExecuteIfBound(savePath); downloadedCallback.ExecuteIfBound(savePath);
}); });
UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to download pak %s from index."), *pakToDownload);
HttpGet(FString::Printf(TEXT("%s%s"), pakIndexUrl, *pakToDownload), pakDownloadCallback); HttpGet(FString::Printf(TEXT("%s%s"), pakIndexUrl, *pakToDownload), pakDownloadCallback);
}); });