Class DataBasePackedFile
- Namespace
- LlamaLogic.Packages
- Assembly
- LlamaLogic.Packages.dll
Represents a Maxis DBPF format package file (🔒)
public sealed class DataBasePackedFile : IAsyncDisposable, IDisposable
- Inheritance
-
DataBasePackedFile
- Implements
- Inherited Members
Remarks
Streams and Disposal
When a package is opened by this class from a Stream, the class assumes ownership of the Stream. Manipulating the Stream afterward may result in undefined behavior. The class will dispose of the Stream when it is, itself, disposed.
To use the Save(bool, ResourceKeyOrder) or SaveAsync(bool, ResourceKeyOrder, CancellationToken) methods, the package must have been opened from a Stream which is writeable. This can also be determined by the caller in advance of attempting to use them by checking the value of the CanSaveInPlace property. However, for ease of use in web frameworks like ASP.NET Core, the CopyTo(Stream, ResourceKeyOrder) and CopyToAsync(Stream, ResourceKeyOrder, CancellationToken) methods do not require that the Stream which they are passed is seekable.
Lazy Loading
When a package is first opened using this class, the package index is read but the content of the package resources is not. All of the retrieval methods of this class have async counterparts for callers who prefer not to be blocked by I/O operations which may be required when retrieving resource content.
Because resource names (when applicable) are determined by their content, this class will not index resource names until they are first referenced, either explicitly by calling GetNames() or GetNamesAsync(CancellationToken), or implicitly by calling any of the other methods which deal with resource names. Afterward, the names are cached for the lifetime of the package instance and updated as the caller sets the content of resources or deletes them.
Thread Safety
All properties and methods of this class, including async methods, are kept thread-safe with internally managed locks. Async methods which accept cancellation tokens will honor signals so long as they have not progressed to mutating the state of the package.
Compression
Decompression of resource content is handled automatically by this class.
When retrieving resource content, this class will automatically decompress it using either proprietary Maxis internal or streaming compression, or ZLib compression. When saving resources, this class will always use ZLib compression. For more details, see the remarks for the CompressionMode enumeration.
Resource content is compressed in memory when it is set to minimize the amount of memory used while operating on a package.
Deleted Entries
This class honors the deleted entry flag in the package index under normal circumstances.
If a caller attempts to retrieve the content of a resource flagged as deleted, the class will throw a FileNotFoundException by default.
All retrieval methods have an optional force bool parameter which, when true, will cause the class to attempt to retrieve the content of a resource flagged as deleted (this is not guaranteed to work).
Constructors
DataBasePackedFile()
Initializes a new, blank DataBasePackedFile
public DataBasePackedFile()
DataBasePackedFile(Stream)
Initializes a DataBasePackedFile from the specified stream (🗑️💤)
public DataBasePackedFile(Stream stream)
Parameters
streamStream
DataBasePackedFile(string, bool)
Initializes a DataBasePackedFile from the specified path (🗑️💤)
public DataBasePackedFile(string path, bool forReadOnly = true)
Parameters
Properties
CanSaveInPlace
Gets whether the package can be saved in place
public bool CanSaveInPlace { get; }
Property Value
Count
Gets the number of resources
public int Count { get; }
Property Value
CreationTime
Gets/sets when the package was created
public DateTimeOffset CreationTime { get; set; }
Property Value
FileVersion
Gets/sets the version of the format of the file
public Version FileVersion { get; set; }
Property Value
Remarks
This class is intended to work with versions of the Maxis DBPF format up to version 2.1 and going back as far as possible.
While it will permit the caller to specify any version they like, it does not guard against potential negative consequences which may result from such packages actually being used.
The default version for newly created packages is currently 2.1.
this[ResourceKey]
Gets/sets the content of a resource with the specified key
public object? this[ResourceKey key] { get; set; }
Parameters
keyResourceKey
Property Value
Keys
Gets a list of keys for all the resources in the package
public IReadOnlyList<ResourceKey> Keys { get; }
Property Value
UpdatedTime
Gets/sets when the package was last updated
public DateTimeOffset UpdatedTime { get; set; }
Property Value
UserVersion
Gets/sets the version of the user (presumably the user agent, actually? -- is Maxis versioning human beings?)
public Version UserVersion { get; set; }
Property Value
Methods
ContainsKey(ResourceKey)
Gets whether the package contains a resource with the specified key
public bool ContainsKey(ResourceKey key)
Parameters
keyResourceKey
Returns
ContainsKeyAsync(ResourceKey, CancellationToken)
Gets whether the package contains a resource with the specified key asynchronously
public Task<bool> ContainsKeyAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
keyResourceKeycancellationTokenCancellationToken
Returns
ConvertPngToTranslucentJpeg(ReadOnlyMemory<byte>)
Converts the data for a PNG the data for a Maxis Translucent JPEG
public static ReadOnlyMemory<byte> ConvertPngToTranslucentJpeg(ReadOnlyMemory<byte> pngData)
Parameters
pngDataReadOnlyMemory<byte>The data for a PNG
Returns
ConvertPngToTranslucentJpegAsync(ReadOnlyMemory<byte>, CancellationToken)
Converts the data for a PNG the data for a Maxis Translucent JPEG asynhronously
public static ValueTask<ReadOnlyMemory<byte>> ConvertPngToTranslucentJpegAsync(ReadOnlyMemory<byte> pngData, CancellationToken cancellationToken)
Parameters
pngDataReadOnlyMemory<byte>The data for a PNG
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
ConvertTranslucentJpegToPng(ReadOnlyMemory<byte>)
Converts the data for a Maxis Translucent JPEG the data for a PNG
public static ReadOnlyMemory<byte> ConvertTranslucentJpegToPng(ReadOnlyMemory<byte> translucentJpegData)
Parameters
translucentJpegDataReadOnlyMemory<byte>The data for a Maxis Translucent JPEG
Returns
ConvertTranslucentJpegToPngAsync(ReadOnlyMemory<byte>, CancellationToken)
Converts the data for a Maxis Translucent JPEG the data for a PNG asynhronously
public static ValueTask<ReadOnlyMemory<byte>> ConvertTranslucentJpegToPngAsync(ReadOnlyMemory<byte> translucentJpegData, CancellationToken cancellationToken = default)
Parameters
translucentJpegDataReadOnlyMemory<byte>The data for a Maxis Translucent JPEG
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
CopyTo(Stream, ResourceKeyOrder)
Copies the package in binary format to the specified destination (🔄️🏃)
public void CopyTo(Stream destination, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
destinationStreamresourceKeyOrderResourceKeyOrder
Exceptions
- ArgumentNullException
destinationis null- ArgumentException
destinationis not writeable
CopyToAsync(Stream, ResourceKeyOrder, CancellationToken)
Copies the package in binary format to the specified destination asynchronously (🔄️🏃)
public Task CopyToAsync(Stream destination, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
destinationStreamresourceKeyOrderResourceKeyOrdercancellationTokenCancellationToken
Returns
Exceptions
- ArgumentNullException
destinationis null- ArgumentException
destinationis not writeable
Delete(ResourceKey)
public bool Delete(ResourceKey key)
Parameters
keyResourceKey
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
~DataBasePackedFile()
Called by the finalizer
protected ~DataBasePackedFile()
ForEach(ResourceKeyOrder, Predicate<ResourceKey>, Action<ResourceKey, ReadOnlyMemory<byte>>, CancellationToken)
Processes undeleted resources in the specified keyOrder if they satisfy the specified keyPredicate using the specified processResourceAction
public void ForEach(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Action<ResourceKey, ReadOnlyMemory<byte>> processResourceAction, CancellationToken cancellationToken = default)
Parameters
keyOrderResourceKeyOrderkeyPredicatePredicate<ResourceKey>processResourceActionAction<ResourceKey, ReadOnlyMemory<byte>>cancellationTokenCancellationToken
ForEachAsync(ResourceKeyOrder, Predicate<ResourceKey>, Func<ResourceKey, ReadOnlyMemory<byte>, Task>, CancellationToken)
Processes undeleted resources in the specified keyOrder if they satisfy the specified keyPredicate using the specified processResourceAsyncAction
public Task ForEachAsync(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Func<ResourceKey, ReadOnlyMemory<byte>, Task> processResourceAsyncAction, CancellationToken cancellationToken = default)
Parameters
keyOrderResourceKeyOrderkeyPredicatePredicate<ResourceKey>processResourceAsyncActionFunc<ResourceKey, ReadOnlyMemory<byte>, Task>cancellationTokenCancellationToken
Returns
ForEachRaw(ResourceKeyOrder, Predicate<ResourceKey>, Action<ResourceKey, ReadOnlyMemory<byte>>, CancellationToken)
Processes undeleted raw resources (meaning that the library will not decompress a resource for you if it is compressed) in the specified keyOrder if they satisfy the specified keyPredicate using the specified processResourceAction
public void ForEachRaw(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Action<ResourceKey, ReadOnlyMemory<byte>> processResourceAction, CancellationToken cancellationToken = default)
Parameters
keyOrderResourceKeyOrderkeyPredicatePredicate<ResourceKey>processResourceActionAction<ResourceKey, ReadOnlyMemory<byte>>cancellationTokenCancellationToken
ForEachRawAsync(ResourceKeyOrder, Predicate<ResourceKey>, Func<ResourceKey, ReadOnlyMemory<byte>, Task>, CancellationToken)
Processes undeleted raw resources (meaning that the library will not decompress a resource for you if it is compressed) in the specified keyOrder if they satisfy the specified keyPredicate using the specified processResourceAsyncAction
public Task ForEachRawAsync(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Func<ResourceKey, ReadOnlyMemory<byte>, Task> processResourceAsyncAction, CancellationToken cancellationToken = default)
Parameters
keyOrderResourceKeyOrderkeyPredicatePredicate<ResourceKey>processResourceAsyncActionFunc<ResourceKey, ReadOnlyMemory<byte>, Task>cancellationTokenCancellationToken
Returns
FromPathAsync(string, bool)
Initializes a DataBasePackedFile asynchronously from the specified path (🗑️💤)
public static Task<DataBasePackedFile> FromPathAsync(string path, bool forReadOnly = true)
Parameters
Returns
FromStreamAsync(Stream, CancellationToken)
Initializes a DataBasePackedFile asynchronously from the specified stream (🗑️💤)
public static Task<DataBasePackedFile> FromStreamAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamcancellationTokenCancellationToken
Returns
Get(ResourceKey, bool)
Gets the content of a resource with the specified key
public ReadOnlyMemory<byte> Get(ResourceKey key, bool force = false)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetAllSizes(Predicate<ResourceKey>?)
Gets the size of the content of each resource in the package indexed by key
public IReadOnlyDictionary<ResourceKey, int> GetAllSizes(Predicate<ResourceKey>? predicate = null)
Parameters
predicatePredicate<ResourceKey>An optional predicate to filter the keys
Returns
GetAllSizesAsync(Predicate<ResourceKey>?, CancellationToken)
Gets the size of the content of each resource in the package indexed by key, asynchronously
public Task<IReadOnlyDictionary<ResourceKey, int>> GetAllSizesAsync(Predicate<ResourceKey>? predicate = null, CancellationToken cancellationToken = default)
Parameters
predicatePredicate<ResourceKey>An optional predicate to filter the keys
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
GetAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key asynchronously
public Task<ReadOnlyMemory<byte>> GetAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
GetCount()
Gets the number of resources
public int GetCount()
Returns
GetCountAsync(CancellationToken)
Gets the number of resources asychronously
public Task<int> GetCountAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetData(ResourceKey, bool)
Gets the content of a resource with the specified key as a DataModel
public DataModel GetData(ResourceKey key, bool force = false)
Parameters
keyResourceKeyforcebool
Returns
GetDataAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as a DataModel asynchronously
public Task<DataModel> GetDataAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
GetDirectDrawSurfaceAsPng(ResourceKey, bool)
Gets the content of a resource that is a DST/DXT DirectDraw Surface with the specified key, encoded as a PNG
public ReadOnlyMemory<byte> GetDirectDrawSurfaceAsPng(ResourceKey key, bool force = false)
Parameters
keyResourceKeyforcebool
Returns
GetDirectDrawSurfaceAsPngAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource that is a DST/DXT DirectDraw Surface with the specified key, encoded as a PNG, asynchronously
public Task<ReadOnlyMemory<byte>> GetDirectDrawSurfaceAsPngAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
GetExplicitCompressionMode(ResourceKey)
Gets the CompressionMode value to pass to Set methods to ensure they will compress the content of the resource specified by key in the same way it is currently compressed in the package
public CompressionMode GetExplicitCompressionMode(ResourceKey key)
Parameters
keyResourceKey
Returns
GetKeys(ResourceKeyOrder)
Gets a list of keys for all the resources in the package
public IReadOnlyList<ResourceKey> GetKeys(ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
resourceKeyOrderResourceKeyOrder
Returns
GetKeysAsync(ResourceKeyOrder, CancellationToken)
Gets a list of keys for all the resources in the package asynchronously
public Task<IReadOnlyList<ResourceKey>> GetKeysAsync(ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
resourceKeyOrderResourceKeyOrdercancellationTokenCancellationToken
Returns
GetKeysByName(string)
Gets a list of keys for resources with the specified name
public IReadOnlyList<ResourceKey> GetKeysByName(string name)
Parameters
namestring
Returns
GetKeysByNameAsync(string, CancellationToken)
Gets a list of keys for resources with the specified name asynchronously
public Task<IReadOnlyList<ResourceKey>> GetKeysByNameAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringcancellationTokenCancellationToken
Returns
GetModFileManifest(ResourceKey, bool)
Gets the content of a resource with the specified key as a ModFileManifestModel
public ModFileManifestModel GetModFileManifest(ResourceKey key, bool force = false)
Parameters
keyResourceKeyforcebool
Returns
GetModFileManifestAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as a ModFileManifestModel asynchronously
public Task<ModFileManifestModel> GetModFileManifestAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
GetModelAsync<TModel>(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as a TModel asynchronously
public Task<TModel> GetModelAsync<TModel>(ResourceKey key, bool force = false, CancellationToken cancellationToken = default) where TModel : IModel<TModel>
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
- Task<TModel>
Type Parameters
TModelA model used to browse and modify certain types of resources
Exceptions
- ArgumentException
TModelcannot deal with resources of the type specified bykey
GetModel<TModel>(ResourceKey, bool)
Gets the content of a resource with the specified key as a TModel
public TModel GetModel<TModel>(ResourceKey key, bool force = false) where TModel : IModel<TModel>
Parameters
keyResourceKeyforcebool
Returns
- TModel
Type Parameters
TModelA model used to browse and modify certain types of resources
Exceptions
- ArgumentException
TModelcannot deal with resources of the type specified bykey
GetNameByKey(ResourceKey)
Gets the name for the resource with the specified key
public string? GetNameByKey(ResourceKey key)
Parameters
keyResourceKey
Returns
GetNameByKeyAsync(ResourceKey, CancellationToken)
Gets the name for the resource with the specified key asynchronously
public Task<string?> GetNameByKeyAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
keyResourceKeycancellationTokenCancellationToken
Returns
GetNames()
Gets the names for all the resources in the package
public IReadOnlyList<string> GetNames()
Returns
GetNamesAsync(CancellationToken)
Gets the names for all the resources in the package asynchronously
public Task<IReadOnlyList<string>> GetNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetRaw(ResourceKey, bool)
Gets the raw content of a resource with the specified key, meaning that the library will not decompress it for you if it is compressed
public ReadOnlyMemory<byte> GetRaw(ResourceKey key, bool force = false)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetRawAsync(ResourceKey, bool, CancellationToken)
Gets the raw content of a resource with the specified key asynchronously, meaning that the library will not decompress it for you if it is compressed
public Task<ReadOnlyMemory<byte>> GetRawAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
GetSize(ResourceKey)
Gets the size of the content of the resource with the specified key
public int GetSize(ResourceKey key)
Parameters
keyResourceKey
Returns
GetSizeAsync(ResourceKey, CancellationToken)
Gets the size of the content of the resource with the specified key asynchronously
public Task<int> GetSizeAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
keyResourceKeycancellationTokenCancellationToken
Returns
GetStringTable(ResourceKey, bool)
Gets the content of a resource with the specified key as a StringTableModel
public StringTableModel GetStringTable(ResourceKey key, bool force = false)
Parameters
keyResourceKeyforcebool
Returns
GetStringTableAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as a StringTableModel asynchronously
public Task<StringTableModel> GetStringTableAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
GetText(ResourceKey, bool)
Gets the content of a resource with the specified key as a string
public string GetText(ResourceKey key, bool force = false)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetTextAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as a string asynchronously
public Task<string> GetTextAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
GetTranslucentJpegAsPng(ResourceKey, bool)
Gets the content of a resource that is a TS4 proprietary translucent JPEG based with the specified key, reintegrated into RGBA and encoded as a PNG
public ReadOnlyMemory<byte> GetTranslucentJpegAsPng(ResourceKey key, bool force = false)
Parameters
keyResourceKeyforcebool
Returns
GetTranslucentJpegAsPngAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource that is a TS4 proprietary translucent JPEG based with the specified key, reintegrated into RGBA and encoded as a PNG, asynchronously
public Task<ReadOnlyMemory<byte>> GetTranslucentJpegAsPngAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyforceboolcancellationTokenCancellationToken
Returns
GetXml(ResourceKey, bool)
Gets the content of a resource with the specified key as an XDocument
public XDocument GetXml(ResourceKey key, bool force = false)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetXmlAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key as an XDocument asynchronously
public Task<XDocument> GetXmlAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
forcebooltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
InternalCompress(ReadOnlyMemory<byte>, out bool)
Compresses the specified memory in the manner of Maxis' internal algorithm, returning the result
public static ReadOnlyMemory<byte> InternalCompress(ReadOnlyMemory<byte> memory, out bool wasCompressed)
Parameters
memoryReadOnlyMemory<byte>wasCompressedbool
Returns
InternalDecompress(ReadOnlyMemory<byte>)
Decompresses the specified memory in the manner of Maxis' internal algorithm, returning the result
public static ReadOnlyMemory<byte> InternalDecompress(ReadOnlyMemory<byte> memory)
Parameters
memoryReadOnlyMemory<byte>
Returns
LoadAll(bool, CompressionMode)
Loads all resources in the package into memory
public void LoadAll(bool force = false, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
forcebooltrue to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)
compressionModeCompressionModeThis parameter is now ignored
LoadAllAsync(bool, CompressionMode, CancellationToken)
Loads all resources in the package into memory
public Task LoadAllAsync(bool force = false, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
forcebooltrue to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)
compressionModeCompressionModeThis parameter is now ignored
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
LoadNames()
Loads the names of all the resources in the package (a no-op if the names are already loaded)
public void LoadNames()
LoadNamesAsync(CancellationToken)
Loads the names of all the resources in the package asynchronously (a no-op if the names are already loaded)
public Task LoadNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Save(bool, ResourceKeyOrder)
Saves the package to the stream from which it was loaded
public void Save(bool unloadFromMemory = false, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
unloadFromMemoryboolresourceKeyOrderResourceKeyOrder
Exceptions
- InvalidOperationException
The package was not loaded from stream or the stream is not writeable
SaveAs(string, ResourceKeyOrder)
Saves the package to the specified path (🔄️🏃)
public void SaveAs(string path, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
pathstringresourceKeyOrderResourceKeyOrder
SaveAsAsync(string, ResourceKeyOrder, CancellationToken)
Saves the package to the specified path asynchronously (🔄️🏃)
public Task SaveAsAsync(string path, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
pathstringresourceKeyOrderResourceKeyOrdercancellationTokenCancellationToken
Returns
SaveAsync(bool, ResourceKeyOrder, CancellationToken)
Saves the package to the stream from which it was loaded asynchronously
public Task SaveAsync(bool unloadFromMemory = false, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
unloadFromMemoryboolresourceKeyOrderResourceKeyOrdercancellationTokenCancellationToken
Returns
Exceptions
- InvalidOperationException
The package was not loaded from stream or the stream is not writeable
Set(ResourceKey, IModel, CompressionMode)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, IModel content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
keyResourceKeyThe key of the resource
contentIModelThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, ReadOnlyMemory<byte>, CompressionMode)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, ReadOnlyMemory<byte> content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
keyResourceKeyThe key of the resource
contentReadOnlyMemory<byte>The content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, string, CompressionMode)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, string content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
keyResourceKeyThe key of the resource
contentstringThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, XDocument, CompressionMode)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, XDocument content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
keyResourceKeyThe key of the resource
contentXDocumentThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
Returns
SetAsync(ResourceKey, IModel, CompressionMode, CancellationToken)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, IModel content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
contentIModelThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, ReadOnlyMemory<byte>, CompressionMode, CancellationToken)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, ReadOnlyMemory<byte> content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
contentReadOnlyMemory<byte>The content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, string, CompressionMode, CancellationToken)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, string content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
contentstringThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, XDocument, CompressionMode, CancellationToken)
Sets the content of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, XDocument content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
contentXDocumentThe content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
SetPngAsTranslucentJpeg(ResourceKey, ReadOnlyMemory<byte>)
Sets the content of a resource as a TS4 proprietary translucent JPEG based on an RGBA image encoded as pngData (the resource content will not be DBPF-compressed as it will already be JPEG lossy compressed and PNG DEFLATE compressed)
public void SetPngAsTranslucentJpeg(ResourceKey key, ReadOnlyMemory<byte> pngData)
Parameters
keyResourceKeyThe key of the resource
pngDataReadOnlyMemory<byte>The encoded PNG data
SetPngAsTranslucentJpegAsync(ResourceKey, ReadOnlyMemory<byte>, CancellationToken)
Sets the content of a resource as a TS4 proprietary translucent JPEG based on an RGBA image encoded as pngData (the resource content will not be DBPF-compressed as it will already be JPEG lossy compressed and PNG DEFLATE compressed) asycnhronously
public Task SetPngAsTranslucentJpegAsync(ResourceKey key, ReadOnlyMemory<byte> pngData, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
pngDataReadOnlyMemory<byte>The encoded PNG data
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
SetXml(ResourceKey, string, CompressionMode)
Sets the xmlContent of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public bool SetXml(ResourceKey key, string xmlContent, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
keyResourceKeyThe key of the resource
xmlContentstringThe XML content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
Returns
SetXmlAsync(ResourceKey, string, CompressionMode, CancellationToken)
Sets the xmlContent of a resource with the specified key, returning true if the resource was compressed; otherwise, false
public Task<bool> SetXmlAsync(ResourceKey key, string xmlContent, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
keyResourceKeyThe key of the resource
xmlContentstringThe XML content of the resource
compressionModeCompressionModeThe compression mode to use for the resource
cancellationTokenCancellationTokenThe token to monitor for cancellation requests
Returns
ZLibCompress(ReadOnlyMemory<byte>)
Compresses the specified memory using ZLib, returning the result
public static ReadOnlyMemory<byte> ZLibCompress(ReadOnlyMemory<byte> memory)
Parameters
memoryReadOnlyMemory<byte>
Returns
ZLibCompressAsync(ReadOnlyMemory<byte>, CancellationToken)
Compresses the specified memory using ZLib asynchronously, returning the result
public static Task<ReadOnlyMemory<byte>> ZLibCompressAsync(ReadOnlyMemory<byte> memory, CancellationToken cancellationToken = default)
Parameters
memoryReadOnlyMemory<byte>cancellationTokenCancellationToken
Returns
ZLibDecompress(ReadOnlyMemory<byte>, int)
Decompresses the specified memory using ZLib, returning the result at the specified sizeDecompressed
public static ReadOnlyMemory<byte> ZLibDecompress(ReadOnlyMemory<byte> memory, int sizeDecompressed)
Parameters
memoryReadOnlyMemory<byte>sizeDecompressedint
Returns
ZLibDecompressAsync(ReadOnlyMemory<byte>, int, CancellationToken)
Decompresses the specified memory using ZLib asynchronously, returning the result at the specified sizeDecompressed
public static Task<ReadOnlyMemory<byte>> ZLibDecompressAsync(ReadOnlyMemory<byte> memory, int sizeDecompressed, CancellationToken cancellationToken = default)
Parameters
memoryReadOnlyMemory<byte>sizeDecompressedintcancellationTokenCancellationToken