// Copyright Epic Games, Inc. All Rights Reserved. #include "Replays/AsyncAction_QueryReplays.h" #include "Containers/Array.h" #include "Containers/UnrealString.h" #include "CoreTypes.h" #include "GameFramework/PlayerController.h" #include "LyraReplaySubsystem.h" #include "Misc/DateTime.h" #include "Misc/NetworkVersion.h" #include "NetworkReplayStreaming.h" #include "Templates/Sorting.h" #include "UObject/WeakObjectPtr.h" UAsyncAction_QueryReplays::UAsyncAction_QueryReplays(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { } UAsyncAction_QueryReplays* UAsyncAction_QueryReplays::QueryReplays(APlayerController* InPlayerController) { UAsyncAction_QueryReplays* Action = nullptr; if (InPlayerController != nullptr) { Action = NewObject(); Action->PlayerController = InPlayerController; } return Action; } void UAsyncAction_QueryReplays::Activate() { ReplayStreamer = FNetworkReplayStreaming::Get().GetFactory().CreateReplayStreamer(); ResultList = NewObject(); if (ReplayStreamer.IsValid()) { FNetworkReplayVersion EnumerateStreamsVersion = FNetworkVersion::GetReplayVersion(); ReplayStreamer->EnumerateStreams(EnumerateStreamsVersion, INDEX_NONE, FString(), TArray(), FEnumerateStreamsCallback::CreateUObject(this, &ThisClass::OnEnumerateStreamsComplete)); } else { QueryComplete.Broadcast(ResultList); } } void UAsyncAction_QueryReplays::OnEnumerateStreamsComplete(const FEnumerateStreamsResult& Result) { for (const FNetworkReplayStreamInfo& StreamInfo : Result.FoundStreams) { ULyraReplayListEntry* NewReplayEntry = NewObject(ResultList); NewReplayEntry->StreamInfo = StreamInfo; ResultList->Results.Add(NewReplayEntry); } // Sort demo names by date struct FCompareDateTime { FORCEINLINE bool operator()(const ULyraReplayListEntry& A, const ULyraReplayListEntry& B) const { return A.StreamInfo.Timestamp.GetTicks() > B.StreamInfo.Timestamp.GetTicks(); } }; Sort(ResultList->Results.GetData(), ResultList->Results.Num(), FCompareDateTime()); QueryComplete.Broadcast(ResultList); }