Creates an entry in the configuration system. The name of the config directory. The name of the config entry. The value of the entry.
(string directoryName, string entryName, object value)
| 126 | /// <param name="entryName">The name of the config entry.</param> |
| 127 | /// <param name="value">The value of the entry.</param> |
| 128 | public static void CreateEntry(string directoryName, string entryName, object value) |
| 129 | { |
| 130 | if (!EnsureConfigSystem()) |
| 131 | { |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | using RegistryKey? configKey = GetConfigSystemKey(); |
| 136 | using RegistryKey? key = configKey?.CreateSubKey(directoryName); |
| 137 | |
| 138 | if (key != null) |
| 139 | { |
| 140 | switch (Directories[directoryName]) |
| 141 | { |
| 142 | case RegistryValueKind.String: |
| 143 | if (value?.ToString() is string stringValue && !stringValue.IsNullOrWhiteSpace()) |
| 144 | { |
| 145 | key.SetStringValue(entryName, stringValue); |
| 146 | |
| 147 | Log.Information( |
| 148 | new LogTextItem("Created config system entry"), |
| 149 | new LogFileItem($"{directoryName}/{entryName}"), |
| 150 | new LogTextItem("="), |
| 151 | new LogFileItem($"{stringValue}") |
| 152 | ); |
| 153 | } |
| 154 | return; |
| 155 | case RegistryValueKind.DWord: |
| 156 | if (value?.ToString().ToInt32OrNull() is int intValue) |
| 157 | { |
| 158 | key.SetInt32Value(entryName, intValue); |
| 159 | |
| 160 | Log.Information( |
| 161 | new LogTextItem("Created config system entry"), |
| 162 | new LogFileItem($"{directoryName}/{entryName}"), |
| 163 | new LogTextItem("="), |
| 164 | new LogFileItem($"{intValue}") |
| 165 | ); |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | Log.Error( |
| 170 | new LogTextItem("Failed to create config system entry."), |
| 171 | new LogDetailsItem("Value must be an integer.") |
| 172 | ); |
| 173 | } |
| 174 | return; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | Log.Error( |
| 179 | new LogTextItem("Failed to create config system entry"), |
| 180 | new LogFileItem($"{directoryName}/{entryName}") |
| 181 | ); |
| 182 | } |
| 183 | /// <summary> |
| 184 | /// Deletes an entry from the configuration system. |
| 185 | /// </summary> |
no test coverage detected