UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BackgroundHttpFileHashHelper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Map.h"
7#include "CoreTypes.h"
9
10//Simple data wrapper used to hold a mapping of a URL to the temp file holding the finished download of that URL in the BackgroundHTTP Temp folder
12{
13public:
14 FString URL;
15 FString TempFilename;
16
18 : URL()
19 , TempFilename()
20 {
21 }
22
23 FURLTempFileMapping(const FString& URLIn, const FString& TempFilenameIn)
24 : URL(URLIn)
26 {
27 }
28
29 //Creates an FString representation of this FURLTempFileMapping
30 FString ToString() const;
31
32 //Sets the values of this FURLTempFileMapping from the string representation
33 //Returns if the parse was successful or not
34 bool InitFromString(const FString& StringIn);
35};
36
45{
46public:
48 : bHasLoadedURLData(false)
49 , bIsDirty(false)
50 , URLFileMappings()
51 , URLFileMappingsLock()
52 {
53 }
54
55 // Handles loading URL Mapping data from disk. No operation if data has previously been loaded.
57
58 // Handles saving URL Mapping data to disk. No operation if data isn't dirty
60
61 // Creates an FString representation of this FBackgroundHttpFileHashHelper's URL mappings. Used for serializing to/from disk
63
64 // Sets the values of this FBackgroundHttpFileHashHelper from the string representation
65 // Returns if the parse was successful or not
67
68 // Looks for a temp filename mapping for the given URL. If one isn't found returns nullptr and does NOT generate one.
69 BACKGROUNDHTTPFILEHASH_API bool FindTempFilenameMappingForURL(const FString& URL, FString& OutTempFilename) const;
70
71 UE_DEPRECATED(5.7, "Please use FindTempFilenameMappingForURL with reference out argument instead")
72 BACKGROUNDHTTPFILEHASH_API const FString* FindTempFilenameMappingForURL(const FString& URL) const;
73
74 // Looks for a temp filename mapping for the given URL. If one isn't found a new one is generated and returned.
75 BACKGROUNDHTTPFILEHASH_API const FString& FindOrAddTempFilenameMappingForURL(const FString& URL);
76
77 // Removes URL mapping
78 BACKGROUNDHTTPFILEHASH_API void RemoveURLMapping(const FString& URL);
79
80 // Looks for a URL mapped to the supplied TempFilename. Nullptr returned if one isn't found
81 BACKGROUNDHTTPFILEHASH_API bool FindMappedURLForTempFilename(const FString& TempFilename, FString& OutMappedURL) const;
82
83 UE_DEPRECATED(5.7, "Please use FindMappedURLForTempFilename with reference out argument instead")
84 BACKGROUNDHTTPFILEHASH_API const FString* FindMappedURLForTempFilename(const FString& TempFilename) const;
85
86 // Deletes any URLMapping that doesn't have a corresponding Temp file actually on disk.
88
89 // Get our base directory used to store Temp files
91
92 // Helper function that returns the file extension used by our BackgroundHTTP temp files
94
95 // Helper function that returns a full path representation of hte given TempFilename
96 static BACKGROUNDHTTPFILEHASH_API FString GetFullPathOfTempFilename(const FString& TempFilename);
97
99 // Same as ToString but doesn't take a lock
100 BACKGROUNDHTTPFILEHASH_API FString ToStringNoLock() const;
101
102 // Same as InitFromString but doesn't take a lock
103 BACKGROUNDHTTPFILEHASH_API bool InitFromStringNoLock(const FString& StringIn);
104
105 // Helper function that just returns the filepath we use to save/load our URL mapping data
106 static BACKGROUNDHTTPFILEHASH_API const FString& GetURLMappingFilePathNoLock();
107
108 // Looks for a temp filename mapping for the given URL. If one isn't found returns nullptr an does NOT generate one.
109 BACKGROUNDHTTPFILEHASH_API const FURLTempFileMapping* FindMappingForURLNoLock(const FString& URL) const;
110
111 // Finds the hash that should be used to refer to this URL. Either finds the hash used in the map to reference the
112 // URLFileMappings entry for this URL or returns the hash we should use (the next valid hash entry) without inserting it into the map.
113 BACKGROUNDHTTPFILEHASH_API FString FindValidFilenameHashForURLNoLock(const FString& URL) const;
114
115 // Creates a hashed Filename with a modifier for the given collision count.
116 static BACKGROUNDHTTPFILEHASH_API FString GenerateHashedFilenameForURLNoLock(const FString& URL, uint32 CollisionCount);
117
118 // Used to make sure that we have called LoadData before any operations that depend on it
119 std::atomic<bool> bHasLoadedURLData;
120
121 // Tracks if we have changed data since our last call to SaveData()
122 std::atomic<bool> bIsDirty;
123
124 // Stores our FURLTempFileMapping mapped to a Hashed filename
125 TMap<FString, FURLTempFileMapping> URLFileMappings;
126
127 // Access lock for URLFileMappings
128 mutable FRWLock URLFileMappingsLock;
129};
130
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ESPMode
Definition SharedPointerFwd.h:12
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BackgroundHttpFileHashHelper.h:45
BACKGROUNDHTTPFILEHASH_API void SaveData()
Definition BackgroundHttpFileHashHelper.cpp:60
BACKGROUNDHTTPFILEHASH_API void DeleteURLMappingsWithoutTempFiles()
Definition BackgroundHttpFileHashHelper.cpp:333
FBackgroundHttpFileHashHelper()
Definition BackgroundHttpFileHashHelper.h:47
BACKGROUNDHTTPFILEHASH_API bool InitFromString(const FString &StringIn)
Definition BackgroundHttpFileHashHelper.cpp:123
BACKGROUNDHTTPFILEHASH_API const FString & FindOrAddTempFilenameMappingForURL(const FString &URL)
Definition BackgroundHttpFileHashHelper.cpp:198
BACKGROUNDHTTPFILEHASH_API FString ToString() const
Definition BackgroundHttpFileHashHelper.cpp:101
BACKGROUNDHTTPFILEHASH_API bool FindTempFilenameMappingForURL(const FString &URL, FString &OutTempFilename) const
Definition BackgroundHttpFileHashHelper.cpp:171
BACKGROUNDHTTPFILEHASH_API bool FindMappedURLForTempFilename(const FString &TempFilename, FString &OutMappedURL) const
Definition BackgroundHttpFileHashHelper.cpp:218
static BACKGROUNDHTTPFILEHASH_API FString GetFullPathOfTempFilename(const FString &TempFilename)
Definition BackgroundHttpFileHashHelper.cpp:94
BACKGROUNDHTTPFILEHASH_API void LoadData()
Definition BackgroundHttpFileHashHelper.cpp:42
BACKGROUNDHTTPFILEHASH_API void RemoveURLMapping(const FString &URL)
Definition BackgroundHttpFileHashHelper.cpp:356
static BACKGROUNDHTTPFILEHASH_API const FString & GetTempFileExtension()
Definition BackgroundHttpFileHashHelper.cpp:82
static BACKGROUNDHTTPFILEHASH_API const FString & GetTemporaryRootPath()
Definition BackgroundHttpFileHashHelper.cpp:76
Definition UnrealType.h:3087
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition CriticalSection.h:14
@ false
Definition radaudio_common.h:23
Definition BackgroundHttpFileHashHelper.h:12
FURLTempFileMapping()
Definition BackgroundHttpFileHashHelper.h:17
bool InitFromString(const FString &StringIn)
Definition BackgroundHttpFileHashHelper.cpp:22
FString TempFilename
Definition BackgroundHttpFileHashHelper.h:15
FString URL
Definition BackgroundHttpFileHashHelper.h:14
FURLTempFileMapping(const FString &URLIn, const FString &TempFilenameIn)
Definition BackgroundHttpFileHashHelper.h:23
FString ToString() const
Definition BackgroundHttpFileHashHelper.cpp:16