Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
PackageWriter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_UNSUPPORTED - Contains code with dll export not allowed COREUOBJECT_API
6
7#include "Async/Future.h"
8#include "Containers/StringView.h"
9#include "IO/IoDispatcher.h"
10#include "Misc/AssertionMacros.h"
11#include "Misc/DateTime.h"
12#include "Misc/EnumClassFlags.h"
13#include "Misc/SecureHash.h"
14#include "Serialization/CompactBinary.h"
15#include "Templates/UniquePtr.h"
16
17class FAssetRegistryState;
18class FCbObject;
19class FCbObjectView;
22class IPackageStoreWriter;
23struct UObject;
24struct FPackageStoreEntryResource;
25struct FSavePackageArgs;
26struct FSavePackageResultStruct;
27
28/** Interface for SavePackage to write packages to storage. */
30{
31public:
32 virtual ~IPackageWriter() = default;
33
35 {
36 /**
37 * Whether an entry should be created for each BulkData stored in the BulkData section
38 * This is necessary for some Writers that need to be able to load the BulkDatas individually.
39 * For other writers the extra regions are an unnecessary performance cost.
40 */
42
43 /** Applicable only to -diffonly saves; suppresses output and breakpoints for diffs in the header. */
44 bool bIgnoreHeaderDiffs = false;
45 };
46
47 /** Return capabilities/settings this PackageWriter has/requires
48 */
50 {
51 return FCapabilities();
52 }
53
54 // Events the PackageWriter receives
56 {
59 };
60
61 /** Mark the beginning of a package store transaction for the specified package
62
63 This must be called before any data is produced for a given package
64 */
65 virtual void BeginPackage(const FBeginPackageInfo& Info) = 0;
66
68 {
69 FUtf8StringView Key;
71 };
72 enum class EWriteOptions
73 {
74 None = 0,
75 WritePackage = 0x01,
76 WriteSidecars = 0x02,
78 ComputeHash = 0x04,
79 SaveForDiff = 0x08,
80 };
81 enum class ECommitStatus
82 {
83 Success,
85 Error
86 };
88 {
94 };
95
96 /** Finalize a package started with BeginPackage()
97 */
98 virtual void CommitPackage(FCommitPackageInfo&& Info) = 0;
99
101 {
102 /** Associated Package Name Entry from BeginPackage */
105 uint64 HeaderSize = 0;
108 };
109
110 /** Write package data (exports and serialized header)
111
112 This may only be called after a BeginPackage() call has been made
113 to signal the start of a package store transaction
114 */
115 virtual void WritePackageData(const FPackageInfo& Info, FLargeMemoryWriter& ExportsArchive, const TArray<FFileRegion>& FileRegions) = 0;
116
118 {
119 enum EType
120 {
126 };
127
128 /** Associated Package Name Entry */
134 };
135
136 /** Write bulk data for the current package
137 */
138 virtual void WriteBulkData(const FBulkDataInfo& Info, const FIoBuffer& BulkData, const TArray<FFileRegion>& FileRegions) = 0;
139
141 {
142 /** Associated Package Name Entry */
147 };
148
149 /** Write separate files written by UObjects during cooking via UObject::CookAdditionalFiles. */
150 virtual void WriteAdditionalFile(const FAdditionalFileInfo& Info, const FIoBuffer& FileData) = 0;
151
153 {
154 /** Associated Package Name Entry */
157 };
158 /** Write separate data written by UObjects via FLinkerSave::AdditionalDataToAppend. */
159 virtual void WriteLinkerAdditionalData(const FLinkerAdditionalDataInfo& Info, const FIoBuffer& Data, const TArray<FFileRegion>& FileRegions) = 0;
160
161 /** Report the size of the Footer that is added after Exports and BulkData but before the PackageTrailer */
162 virtual int64 GetExportsFooterSize()
163 {
164 return 0;
165 }
166
168 {
171 };
172 /** Write the PackageTrailer, a separate segment for some bulkdata that is written the end of the file. */
173 virtual void WritePackageTrailer(const FPackageTrailerInfo& Info, const FIoBuffer& Data) = 0;
174
175 /** Create the FLargeMemoryWriter to which the Header and Exports are written during the save. */
177
178 /** Returns an archive to be used when serializing exports. */
180
181 /** Report whether PreSave was already called by the PackageWriter before the current UPackage::Save call. */
182 virtual bool IsPreSaveCompleted() const
183 {
184 return false;
185 }
186
187 /** Downcast function for IPackageWriters that implement the ICookedPackageWriters inherited interface. */
189 {
190 return nullptr;
191 }
192};
193
195
196/** Struct containing hashes computed during cooked package writing. */
198{
199 /** Hashes for each chunk saved by the package. */
201
202 /** This is a hash representing the entire package. Not consistently computed across PackageWriters! */
204
205 /**
206 * A Future that is triggered after all packages have been stored on *this.
207 * Left as an invalid TFuture when hashes are not async; caller should check for IsValid before
208 * chaining with .Then or .Next.
209 */
211};
212
213/** Interface for cooking that writes cooked packages to storage usable by the runtime game. */
215{
216public:
217 virtual ~ICookedPackageWriter() = default;
218
220 {
221 /** Whether this writer implements -diffonly and -linkerdiff. */
222 bool bDiffModeSupported = false;
223 };
224
225 /** Return cook capabilities/settings this PackageWriter has/requires
226 */
228 {
229 return FCookCapabilities();
230 }
231
232 /** Return the timestamp of the previous cook, or FDateTime::MaxValue to indicate previous cook should be assumed newer than any other cook data. */
234 {
236 }
237
239 {
240 return this;
241 }
242
244 {
246 {
249 };
250
252 bool bFullBuild = true;
255 };
256
257 /** Delete outdated cooked data, etc.
258 */
259 virtual void Initialize(const FCookInfo& Info) = 0;
260
261 /** Signal the start of a cooking pass
262
263 Package data may only be produced after BeginCook() has been called and
264 before EndCook() is called
265 */
266 virtual void BeginCook(const FCookInfo& Info) = 0;
267
268 /** Signal the end of a cooking pass.
269 */
270 virtual void EndCook(const FCookInfo& Info) = 0;
271
273 {
277 int64 DiskSize = -1;
278 };
279
280 /**
281 * Returns an AssetRegistry describing the previous cook results. This doesn't mean a cook saved off
282 * to another directory - it means the AssetRegistry that's living in the directory we are about
283 * to cook in to.
284 */
286
287 /**
288 * Returns an Attachment that was previously commited for the given PackageName.
289 * Returns an empty object if not found.
290 */
291 virtual FCbObject GetOplogAttachment(FName PackageName, FUtf8StringView AttachmentKey) = 0;
292
293 /**
294 * Remove the given cooked package(s) from storage; they have been modified since the last cook.
295 */
296 virtual void RemoveCookedPackages(TArrayView<const FName> PackageNamesToRemove) = 0;
297
298 /**
299 * Remove all cooked packages from storage.
300 */
301 virtual void RemoveCookedPackages() = 0;
302
303 /**
304 * Signal the given cooked package(s) have been checked for changes and have not been modified since the last cook.
305 */
306 virtual void MarkPackagesUpToDate(TArrayView<const FName> UpToDatePackages) = 0;
307
309 {
311 int64 Size;
314 };
315 /** Load the bytes of the previously-cooked package, used for diffing */
317 {
318 // The subclass must override this method if it returns bDiffModeSupported=true in GetCookCapabilities
320 return false;
321 }
322 /** Append all data to the Exports archive that would normally be done in CommitPackage, used for diffing. */
323 virtual void CompleteExportsArchiveForDiff(const FPackageInfo& Info, FLargeMemoryWriter& ExportsArchive)
324 {
325 // The subclass must override this method if it returns bDiffModeSupported=true in GetCookCapabilities
327 }
328 /** Modify the SaveArgs if required before the first Save. Used for diffing. */
329 virtual void UpdateSaveArguments(FSavePackageArgs& SaveArgs)
330 {
331 }
332 /** Report whether an additional save is needed and set up for it if so. Used for diffing. */
333 virtual bool IsAnotherSaveNeeded(FSavePackageResultStruct& PreviousResult, FSavePackageArgs& SaveArgs)
334 {
335 return false;
336 }
337 /**
338 * Asynchronously create a CompactBinary Object message that replicates all of the package data from package save
339 * that is collected in memory and written at end of cook rather than being written to disk during package save.
340 * Used during MPCook to transfer this information from CookWorker to CookDirector. Called after CommitPackage,
341 * and only on CookWorkers.
342 */
344
345 /** Read PackageData written by WriteMPCookMessageForPackage on a CookWorker. Called only on CookDirector. */
346 virtual bool TryReadMPCookMessageForPackage(FName PackageName, FCbObjectView Message) = 0;
347
348 /** Downcast function for ICookedPackageWriters that implement the IPackageStoreWriter inherited interface. */
349 virtual IPackageStoreWriter* AsPackageStoreWriter()
350 {
351 return nullptr;
352 }
353
354 /**
355 * Cooked package writers asynchronously hash the chunks for each package after CommitPackage. Once cooking has completed,
356 * use this to acquire the results. This is synced using void UPackage::WaitForAsyncFileWrites() - do not access
357 * the results before that completes. Non-const so that the cooking process can Move the map of hashes.
358 */
360};
361
362static inline const ANSICHAR* LexToString(IPackageWriter::FBulkDataInfo::EType Value)
363{
364 switch (Value)
365 {
367 return "AppendToExports";
369 return "Standard";
371 return "Mmap";
373 return "Optional";
374 default:
375 checkNoEntry();
376 return "Unknown";
377 }
378
379}
#define checkNoEntry()
#define unimplemented()
#define ENUM_CLASS_FLAGS(Enum)
static const ANSICHAR * LexToString(IPackageWriter::FBulkDataInfo::EType Value)
virtual void RemoveCookedPackages()=0
virtual void UpdateSaveArguments(FSavePackageArgs &SaveArgs)
virtual ICookedPackageWriter * AsCookedPackageWriter() override
virtual ~ICookedPackageWriter()=default
virtual void MarkPackagesUpToDate(TArrayView< const FName > UpToDatePackages)=0
virtual FCookCapabilities GetCookCapabilities() const
virtual void BeginCook(const FCookInfo &Info)=0
virtual void RemoveCookedPackages(TArrayView< const FName > PackageNamesToRemove)=0
virtual FDateTime GetPreviousCookTime() const
virtual TFuture< FCbObject > WriteMPCookMessageForPackage(FName PackageName)=0
virtual TMap< FName, TRefCountPtr< FPackageHashes > > & GetPackageHashes()=0
virtual IPackageStoreWriter * AsPackageStoreWriter()
virtual bool IsAnotherSaveNeeded(FSavePackageResultStruct &PreviousResult, FSavePackageArgs &SaveArgs)
virtual FCbObject GetOplogAttachment(FName PackageName, FUtf8StringView AttachmentKey)=0
virtual void EndCook(const FCookInfo &Info)=0
virtual bool GetPreviousCookedBytes(const FPackageInfo &Info, FPreviousCookedBytesData &OutData)
virtual TUniquePtr< FAssetRegistryState > LoadPreviousAssetRegistry()=0
virtual void Initialize(const FCookInfo &Info)=0
virtual bool TryReadMPCookMessageForPackage(FName PackageName, FCbObjectView Message)=0
virtual void CompleteExportsArchiveForDiff(const FPackageInfo &Info, FLargeMemoryWriter &ExportsArchive)
virtual void WriteAdditionalFile(const FAdditionalFileInfo &Info, const FIoBuffer &FileData)=0
virtual int64 GetExportsFooterSize()
virtual ~IPackageWriter()=default
virtual bool IsPreSaveCompleted() const
virtual void WriteBulkData(const FBulkDataInfo &Info, const FIoBuffer &BulkData, const TArray< FFileRegion > &FileRegions)=0
virtual void BeginPackage(const FBeginPackageInfo &Info)=0
virtual void WritePackageData(const FPackageInfo &Info, FLargeMemoryWriter &ExportsArchive, const TArray< FFileRegion > &FileRegions)=0
virtual void WriteLinkerAdditionalData(const FLinkerAdditionalDataInfo &Info, const FIoBuffer &Data, const TArray< FFileRegion > &FileRegions)=0
virtual void WritePackageTrailer(const FPackageTrailerInfo &Info, const FIoBuffer &Data)=0
virtual FCapabilities GetCapabilities() const
virtual ICookedPackageWriter * AsCookedPackageWriter()
virtual void CommitPackage(FCommitPackageInfo &&Info)=0
static FDateTime MaxValue()
Definition DateTime.h:633
Definition Guid.h:108
FMD5Hash PackageHash
TFuture< int > CompletionFuture
TMap< FIoChunkId, FIoHash > ChunkHashes
TArray< FCommitAttachmentInfo > Attachments
Definition UE.h:432