ConfigFile
In-memory sections, keys and typed Variants with explicit file loading and saving.
SetValue changes memory; Save writes a file. Load and Parse merge into an existing instance. For independent loading, use a new ConfigFile, check Error and only then change game state.
Ordinary Save produces text using Variant syntax. Encrypted variants are separate methods; ConfigFile itself does not establish that progress is trustworthy. Comments and original file formatting are not preserved.
GetValue returns a Variant. Values needing cleanup have a finalizer as a fallback; using releases them predictably when leaving scope. The example checks position type and finiteness before returning it to the caller. The ConfigFile must already contain the loaded data.
using Reckfell;
public static class ConfigPositionExample
{
public static bool TryReadPosition(ConfigFile data, out Vector3 position)
{
position = default;
if (!data.HasSectionKey("player", "position"))
return false;
using Variant value = data.GetValue("player", "position");
if (value.VariantType != Variant.Type.Vector3)
return false;
Vector3 candidate = value.AsVector3();
if (!candidate.IsFinite())
return false;
position = candidate;
return true;
}
}For writing with a backup, see saving progress.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ConfigFileConstructor
public ConfigFile();Creates an empty in-memory store of sections, keys and Variants. Does not itself open a file or load earlier data.
Methods19
Clearvoid
public void Clear();Removes every section and value from this instance's memory only. Neither deletes a file nor saves the change to disk.
EncodeToTextstring
public string EncodeToText();Creates a text representation of current values without writing a file. Does not preserve comments or original formatting. It is not guaranteed to match Save byte for byte: the current engine writes section a]b here as [a]b], whereas Save escapes the closing bracket. Use Save for files with such section names.
stringSection/value text; an empty string for an empty ConfigFile.
EraseSectionvoid
public void EraseSection(string section);Removes the section and all its keys in memory. A missing section reports a native error rather than a guaranteed CLR exception. Check HasSection first when absence is expected. Does not change the disk file.
| Name | Type | Default |
|---|---|---|
section | string | — |
sectionExisting section name.
EraseSectionKeyvoid
public void EraseSectionKey(string section, string key);Removes a key from an in-memory section. Removing its last key also removes the section. A missing section or key reports a native error; use HasSectionKey before conditional removal. Persist the change with a separate Save.
| Name | Type | Default |
|---|---|---|
section | string | — |
key | string | — |
sectionExisting section name.
keyExisting key name.
GetSectionKeysstring[]
public string[] GetSectionKeys(string section);Returns key names from an existing section. A missing section reports a native error and returns an empty array. Use HasSection when absence is expected to avoid that error.
| Name | Type | Default |
|---|---|---|
section | string | — |
sectionIn-memory section name, not a file path.
string[]A string[] array of key names.
GetSectionsstring[]
public string[] GetSections();Returns an array of this instance's section names. It is neither a file listing nor the section values. Do not tie save-format logic to a name's position in the array.
string[]A string[] array; empty when no sections exist.
GetValueVariant
public Variant GetValue(string section, string key, Variant @default = default);Returns the specified key value. If the section or key is absent, returns the supplied default. A missing value with a Nil default also produces an engine error; this does not replace explicitly checking whether the key exists.
| Name | Type | Default |
|---|---|---|
section | string | — |
key | string | — |
default | Variant | default |
sectionSection name. An empty string identifies values outside a section.
keyKey name within the specified section.
defaultFallback when the section or key is missing. Supply an explicit non-Nil Variant, such as 7 or false, to handle a missing value normally.
VariantThe stored Variant or the supplied default. Its type depends on the stored data; the caller converts it to the required C# type.
HasSectionbool
public bool HasSection(string section);Checks in-memory section existence without loading a file or reporting a missing-section error. Does not establish that its values have the required types.
| Name | Type | Default |
|---|---|---|
section | string | — |
sectionSection name to check.
booltrue if the section exists; otherwise false.
HasSectionKeybool
public bool HasSectionKey(string section, string key);Checks whether an in-memory section/key pair exists. A missing section returns false without an error. Check the value type and range separately after GetValue.
| Name | Type | Default |
|---|---|---|
section | string | — |
key | string | — |
sectionSection name.
keyKey name within the section.
booltrue only when both the section and key exist.
LoadError
public Error Load(string path);Reads and parses a file into this ConfigFile. Matching values are replaced, but existing values absent from the file remain: Load does not clear the object. Use a new ConfigFile or call Clear() first for replacement. Check the returned Error.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathPath to the configuration file to read, for example user://settings.ini. Load does not create a missing file.
ErrorError.Ok after successful reading and parsing; otherwise a file-opening or parsing error. Do not assume a failed load cleared the object.
LoadEncrypted2 overloads
public Error LoadEncrypted(string path, byte[] key);Opens an encrypted file using the supplied 32-byte key, then parses values into this instance. Like Load, merges data without clearing earlier values. A wrong key, damaged file or parse error is not a successful load: check Error and apply data from a fresh object only after validation.
| Name | Type | Default |
|---|---|---|
path | string | — |
key | byte[] | — |
pathFile path; normally user:// for user data.
keyExactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.
ErrorError.Ok after successful decryption and parsing; otherwise an open, format, key or parse error.
public Error LoadEncrypted(string path, ReadOnlySpan<byte> key);Opens an encrypted file using the supplied 32-byte key, then parses values into this instance. Like Load, merges data without clearing earlier values. A wrong key, damaged file or parse error is not a successful load: check Error and apply data from a fresh object only after validation.
| Name | Type | Default |
|---|---|---|
path | string | — |
key | ReadOnlySpan<byte> | — |
pathFile path; normally user:// for user data.
keyExactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.
ErrorError.Ok after successful decryption and parsing; otherwise an open, format, key or parse error.
LoadEncryptedPassError
public Error LoadEncryptedPass(string path, string password);Loads a SaveEncryptedPass file using the same password, then merges values into the current object. Neither clears earlier state nor establishes that gameplay data is valid: check Error, types and ranges.
| Name | Type | Default |
|---|---|---|
path | string | — |
password | string | — |
pathFile path; its parent directory must exist.
passwordPassword used by the built-in key derivation. Use the same password for reading; do not substitute its string for a byte[] key in another overload.
ErrorError.Ok on successful loading; otherwise a decryption, open or parse error.
ParseError
public Error Parse(string data);Parses text into this instance, adding values and replacing matching keys. Does not clear earlier data. Mutates the object while parsing: an error does not guarantee rollback of values already read. For independent loading, parse into a new ConfigFile and check Error before applying data to the game.
| Name | Type | Default |
|---|---|---|
data | string | — |
dataConfigFile-format text, not a filename. Values use Variant syntax; do not assume full compatibility with arbitrary INI parsers.
ErrorError.Ok on successful parsing; otherwise a parse error. The object may be partially changed.
SaveError
public Error Save(string path);Writes the current ConfigFile values to a file with an INI-style structure. SetValue changes memory only; writing requires a separate Save. Missing parent directories are not created.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathDestination file path. Use a writable location such as user://settings.ini for user settings.
ErrorError.Ok on successful writing; otherwise an error code. Check it before reporting a successful save.
SaveEncrypted2 overloads
public Error SaveEncrypted(string path, byte[] key);Writes current values using AES-256 and the supplied 32-byte key. Does not create parent directories or perform an atomic replacement with a backup. An error does not guarantee preservation of the old file: the destination is opened for writing before the operation finishes.
| Name | Type | Default |
|---|---|---|
path | string | — |
key | byte[] | — |
pathFile path; normally user:// for user data.
keyExactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.
ErrorError.Ok on successful execution; otherwise an error code. Does not guarantee durability across power loss.
public Error SaveEncrypted(string path, ReadOnlySpan<byte> key);Writes current values using AES-256 and the supplied 32-byte key. Does not create parent directories or perform an atomic replacement with a backup. An error does not guarantee preservation of the old file: the destination is opened for writing before the operation finishes.
| Name | Type | Default |
|---|---|---|
path | string | — |
key | ReadOnlySpan<byte> | — |
pathFile path; normally user:// for user data.
keyExactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.
ErrorError.Ok on successful execution; otherwise an error code. Does not guarantee durability across power loss.
SaveEncryptedPassError
public Error SaveEncryptedPass(string path, string password);Saves values with encryption using the built-in password-derived key. This is a different key-input method from passing 32 bytes to SaveEncrypted. Does not back up or atomically replace an existing file.
| Name | Type | Default |
|---|---|---|
path | string | — |
password | string | — |
pathFile path; its parent directory must exist.
passwordPassword used by the built-in key derivation. Use the same password for reading; do not substitute its string for a byte[] key in another overload.
ErrorError.Ok on successful execution; otherwise an error code.
SetValuevoid
public void SetValue(string section, string key, Variant value);Assigns a value in memory, creating the section and key when needed. A Nil value, including default(Variant), removes the key and removes its section if empty. The file is not changed until Save.
| Name | Type | Default |
|---|---|---|
section | string | — |
key | string | — |
value | Variant | — |
sectionSection name. An empty string identifies values outside a section.
keyKey name within the specified section.
valueVariant value to store in memory. Nil means deleting the key, rather than storing an empty value.