1using System.Collections.Generic;
3using System.Text.RegularExpressions;
25 private const string AllCommands =
"+-!;";
73 public ConfigCommand(
string line,
int order)
77 string command =
"", name =
"", value =
"";
79 line.MatchGroup(
@"^(?<COMMAND>[\+\-!;]?)(?<NAME>.*?)(=(?<VALUE>.*))?$", RegexOptions.CultureInvariant)
80 ?.Fetch(
"COMMAND", out command)
81 ?.Fetch(
"NAME", out name)
82 ?.Fetch(
"VALUE", out value);
85 Type =
string.IsNullOrWhiteSpace(command) || AllCommands.All(c => c != command[0])
90 Name =
Type != CommandType.Comment ? name.Trim() : name;
97 public string Serialize() =>
Type switch
99 CommandType.Set => $
"{Name}={GetSerializedValue()}",
100 CommandType.Add => $
"+{Name}={GetSerializedValue()}",
101 CommandType.Remove => $
"-{Name}={GetSerializedValue()}",
102 CommandType.Clear =>
"!" +
Name,
103 CommandType.Comment =>
";" +
Name + (
string.IsNullOrWhiteSpace(GetSerializedValue()) ?
"" :
"=" +
Value),
107 public override bool Equals(
object? obj)
109 if (obj is ConfigCommand b)
116 public override int GetHashCode() => (int)
Type ^ (
Name?.GetHashCode() ^
Value?.GetHashCode() ?? 0);
CommandType
Unreal INI config items are read top to bottom, reading like individual commands, especially when man...
Structural representation of a config line in Unreal.
string Name
Config item name.
int Order
Maintain the original position for this section as they were in the source file so serialization does...
string Value
Everything on the right side of the = symbol on a config,.
CommandType Type
How this config item should apply its value.
string CommentText
Get the full text of a comment including = character and its right side.
bool IsQuotedString
Was the value quoted originally in the source config file.