Table of Contents

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

stream Stream

DataBasePackedFile(string, bool)

Initializes a DataBasePackedFile from the specified path (🗑️💤)

public DataBasePackedFile(string path, bool forReadOnly = true)

Parameters

path string
forReadOnly bool

Properties

CanSaveInPlace

Gets whether the package can be saved in place

public bool CanSaveInPlace { get; }

Property Value

bool

Count

Gets the number of resources

public int Count { get; }

Property Value

int

CreationTime

Gets/sets when the package was created

public DateTimeOffset CreationTime { get; set; }

Property Value

DateTimeOffset

FileVersion

Gets/sets the version of the format of the file

public Version FileVersion { get; set; }

Property Value

Version

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

key ResourceKey

Property Value

object

Keys

Gets a list of keys for all the resources in the package

public IReadOnlyList<ResourceKey> Keys { get; }

Property Value

IReadOnlyList<ResourceKey>

UpdatedTime

Gets/sets when the package was last updated

public DateTimeOffset UpdatedTime { get; set; }

Property Value

DateTimeOffset

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

Version

Methods

ContainsKey(ResourceKey)

Gets whether the package contains a resource with the specified key

public bool ContainsKey(ResourceKey key)

Parameters

key ResourceKey

Returns

bool

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

key ResourceKey
cancellationToken CancellationToken

Returns

Task<bool>

CopyTo(Stream, ResourceKeyOrder)

Copies the package in binary format to the specified destination (🔄️🏃)

public void CopyTo(Stream destination, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)

Parameters

destination Stream
resourceKeyOrder ResourceKeyOrder

Exceptions

ArgumentNullException

destination is null

ArgumentException

destination is 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

destination Stream
resourceKeyOrder ResourceKeyOrder
cancellationToken CancellationToken

Returns

Task

Exceptions

ArgumentNullException

destination is null

ArgumentException

destination is not writeable

Delete(ResourceKey)

Deletes the resource with the specified key and returns true if it was found; otherwise, false

public bool Delete(ResourceKey key)

Parameters

key ResourceKey

Returns

bool

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

keyOrder ResourceKeyOrder
keyPredicate Predicate<ResourceKey>
processResourceAction Action<ResourceKey, ReadOnlyMemory<byte>>
cancellationToken CancellationToken

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

keyOrder ResourceKeyOrder
keyPredicate Predicate<ResourceKey>
processResourceAsyncAction Func<ResourceKey, ReadOnlyMemory<byte>, Task>
cancellationToken CancellationToken

Returns

Task

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

keyOrder ResourceKeyOrder
keyPredicate Predicate<ResourceKey>
processResourceAction Action<ResourceKey, ReadOnlyMemory<byte>>
cancellationToken CancellationToken

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

keyOrder ResourceKeyOrder
keyPredicate Predicate<ResourceKey>
processResourceAsyncAction Func<ResourceKey, ReadOnlyMemory<byte>, Task>
cancellationToken CancellationToken

Returns

Task

FromPathAsync(string, bool)

Initializes a DataBasePackedFile asynchronously from the specified path (🗑️💤)

public static Task<DataBasePackedFile> FromPathAsync(string path, bool forReadOnly = true)

Parameters

path string
forReadOnly bool

Returns

Task<DataBasePackedFile>

FromStreamAsync(Stream, CancellationToken)

Initializes a DataBasePackedFile asynchronously from the specified stream (🗑️💤)

public static Task<DataBasePackedFile> FromStreamAsync(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream
cancellationToken CancellationToken

Returns

Task<DataBasePackedFile>

Get(ResourceKey, bool)

Gets the content of a resource with the specified key

public ReadOnlyMemory<byte> Get(ResourceKey key, bool force = false)

Parameters

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

Returns

ReadOnlyMemory<byte>

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

predicate Predicate<ResourceKey>

An optional predicate to filter the keys

Returns

IReadOnlyDictionary<ResourceKey, int>

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

predicate Predicate<ResourceKey>

An optional predicate to filter the keys

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<IReadOnlyDictionary<ResourceKey, int>>

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<ReadOnlyMemory<byte>>

GetCount()

Gets the number of resources

public int GetCount()

Returns

int

GetCountAsync(CancellationToken)

Gets the number of resources asychronously

public Task<int> GetCountAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<int>

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

key ResourceKey
force bool

Returns

DataModel

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

key ResourceKey
force bool
cancellationToken CancellationToken

Returns

Task<DataModel>

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

key ResourceKey

Returns

CompressionMode

GetKeys(ResourceKeyOrder)

Gets a list of keys for all the resources in the package

public IReadOnlyList<ResourceKey> GetKeys(ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)

Parameters

resourceKeyOrder ResourceKeyOrder

Returns

IReadOnlyList<ResourceKey>

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

resourceKeyOrder ResourceKeyOrder
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<ResourceKey>>

GetKeysByName(string)

Gets a list of keys for resources with the specified name

public IReadOnlyList<ResourceKey> GetKeysByName(string name)

Parameters

name string

Returns

IReadOnlyList<ResourceKey>

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

name string
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<ResourceKey>>

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

key ResourceKey
force bool

Returns

ModFileManifestModel

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

key ResourceKey
force bool
cancellationToken CancellationToken

Returns

Task<ModFileManifestModel>

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

key ResourceKey
force bool
cancellationToken CancellationToken

Returns

Task<TModel>

Type Parameters

TModel

A model used to browse and modify certain types of resources

Exceptions

ArgumentException

TModel cannot deal with resources of the type specified by key

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

key ResourceKey
force bool

Returns

TModel

Type Parameters

TModel

A model used to browse and modify certain types of resources

Exceptions

ArgumentException

TModel cannot deal with resources of the type specified by key

GetNameByKey(ResourceKey)

Gets the name for the resource with the specified key

public string? GetNameByKey(ResourceKey key)

Parameters

key ResourceKey

Returns

string

GetNameByKeyAsync(ResourceKey, CancellationToken)

Gets the name for the resource with the specified key asynchronously

public Task<string?> GetNameByKeyAsync(ResourceKey key, CancellationToken cancellationToken = default)

Parameters

key ResourceKey
cancellationToken CancellationToken

Returns

Task<string>

GetNames()

Gets the names for all the resources in the package

public IReadOnlyList<string> GetNames()

Returns

IReadOnlyList<string>

GetNamesAsync(CancellationToken)

Gets the names for all the resources in the package asynchronously

public Task<IReadOnlyList<string>> GetNamesAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IReadOnlyList<string>>

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

Returns

ReadOnlyMemory<byte>

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<ReadOnlyMemory<byte>>

GetSize(ResourceKey)

Gets the size of the content of the resource with the specified key

public int GetSize(ResourceKey key)

Parameters

key ResourceKey

Returns

int

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

key ResourceKey
cancellationToken CancellationToken

Returns

Task<int>

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

key ResourceKey
force bool

Returns

StringTableModel

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

key ResourceKey
force bool
cancellationToken CancellationToken

Returns

Task<StringTableModel>

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

Returns

string

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<string>

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

key ResourceKey
force bool

Returns

ReadOnlyMemory<byte>

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

key ResourceKey
force bool
cancellationToken CancellationToken

Returns

Task<ReadOnlyMemory<byte>>

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

Returns

XDocument

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

key ResourceKey

The key of the resource

force bool

true to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<XDocument>

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

memory ReadOnlyMemory<byte>
wasCompressed bool

Returns

ReadOnlyMemory<byte>

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

memory ReadOnlyMemory<byte>

Returns

ReadOnlyMemory<byte>

LoadAll(bool, CompressionMode)

Loads all resources in the package into memory

public void LoadAll(bool force = false, CompressionMode compressionMode = CompressionMode.Auto)

Parameters

force bool

true to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)

compressionMode CompressionMode

This 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

force bool

true to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)

compressionMode CompressionMode

This parameter is now ignored

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task

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

cancellationToken CancellationToken

Returns

Task

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

unloadFromMemory bool
resourceKeyOrder ResourceKeyOrder

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

path string
resourceKeyOrder ResourceKeyOrder

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

path string
resourceKeyOrder ResourceKeyOrder
cancellationToken CancellationToken

Returns

Task

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

unloadFromMemory bool
resourceKeyOrder ResourceKeyOrder
cancellationToken CancellationToken

Returns

Task

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

key ResourceKey

The key of the resource

content IModel

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

Returns

bool

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

key ResourceKey

The key of the resource

content ReadOnlyMemory<byte>

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

Returns

bool

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

key ResourceKey

The key of the resource

content string

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

Returns

bool

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

key ResourceKey

The key of the resource

content XDocument

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

Returns

bool

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

key ResourceKey

The key of the resource

content IModel

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<bool>

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

key ResourceKey

The key of the resource

content ReadOnlyMemory<byte>

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<bool>

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

key ResourceKey

The key of the resource

content string

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<bool>

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

key ResourceKey

The key of the resource

content XDocument

The content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<bool>

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)

public Task SetPngAsTranslucentJpegAsync(ResourceKey key, ReadOnlyMemory<byte> pngData, CancellationToken cancellationToken = default)

Parameters

key ResourceKey

The key of the resource

pngData ReadOnlyMemory<byte>

The encoded PNG data

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task

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

key ResourceKey

The key of the resource

xmlContent string

The XML content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

Returns

bool

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

key ResourceKey

The key of the resource

xmlContent string

The XML content of the resource

compressionMode CompressionMode

The compression mode to use for the resource

cancellationToken CancellationToken

The token to monitor for cancellation requests

Returns

Task<bool>

ZLibCompress(ReadOnlyMemory<byte>)

Compresses the specified memory using ZLib, returning the result

public static ReadOnlyMemory<byte> ZLibCompress(ReadOnlyMemory<byte> memory)

Parameters

memory ReadOnlyMemory<byte>

Returns

ReadOnlyMemory<byte>

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

memory ReadOnlyMemory<byte>
cancellationToken CancellationToken

Returns

Task<ReadOnlyMemory<byte>>

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

memory ReadOnlyMemory<byte>
sizeDecompressed int

Returns

ReadOnlyMemory<byte>

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

memory ReadOnlyMemory<byte>
sizeDecompressed int
cancellationToken CancellationToken

Returns

Task<ReadOnlyMemory<byte>>