From 32301647369c7d8983fd300a293af041c84c14f2 Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Tue, 19 Nov 2024 23:15:45 +0100 Subject: [PATCH] Loading downloaded content --- .../RuntimeLoadTest/BP_Test_RuntimeLoad.uasset | 4 ++-- .../Lost_Edge/Content/Levels/Test/L_Test.umap | 4 ++-- .../Source/Lost_Edge/Private/ContentLoader.cpp | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset b/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset index 19b84b6..8ac1e67 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2c1d5e18df10568f346e078aee33a2bef68d4a7f8426a11598f17032076a54ce -size 68506 +oid sha256:aa2e821da734968bc3381ea5cd9595bf91638fa86634b0ab296f2fe79f315580 +size 72341 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index 90f2678..b2b7c82 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:517227541cd118fc0c58a1ccaebb377531a4b888a9ee45394fe2531cbc3e434d -size 2257413 +oid sha256:429d510512b55b0c1bb5aedc97715de4ceaba362be6c8f1d9d1c5a0a38c40050 +size 2257698 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp index c03765f..8d01c52 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp @@ -21,7 +21,7 @@ namespace constexpr auto httpContentTypeJson = TEXT("application/json"); 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() @@ -119,7 +119,15 @@ void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback, FString pakToDownload = SelectContentByMethod(availablePaks, method); 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; pakDownloadCallback.BindLambda([=, this](FHttpRequestPtr request, FHttpResponsePtr response, bool successful) @@ -132,7 +140,6 @@ void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback, return; } - auto savePath = FString::Printf(TEXT("%s%s"), *pakFileSavePath, *pakToDownload); if(!FFileHelper::SaveArrayToFile(response->GetContent(), *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); }); + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to download pak %s from index."), *pakToDownload); HttpGet(FString::Printf(TEXT("%s%s"), pakIndexUrl, *pakToDownload), pakDownloadCallback); });