1using Microsoft.Extensions.Configuration;
11[JsonObject(IsReference =
true)]
14 private const string _defaultConfigFileName =
"gondwana.json";
15 private string _fileName = _defaultConfigFileName;
17 private EngineConfigurationFile()
26 public static EngineConfigurationFile
CreateNew(
string? configFileName =
null,
bool? autoSave =
null)
28 var config =
new EngineConfigurationFile
30 FileName = configFileName ?? _defaultConfigFileName,
46 public static EngineConfigurationFile
Load(
string? configFileName =
null,
bool? autoSave =
null)
48 var configFile = configFileName ?? _defaultConfigFileName;
50 var configRoot =
new ConfigurationBuilder()
51 .AddJsonFile(configFile, optional:
true, reloadOnChange:
true)
55 return new EngineConfigurationFile
69 get => Path.GetFileName(_fileName);
70 private set => _fileName = Path.GetFullPath(value);
77 public string FilePath => Path.GetFullPath(_fileName);
112 public void Save(
string jsonPath)
114 var json = JsonConvert.SerializeObject(
this, Formatting.Indented);
115 File.WriteAllText(jsonPath, json);
128 GC.SuppressFinalize(
this);
string FilePath
Gets the full path to the configuration file.
bool AutoSave
Gets or sets a value indicating whether the configuration should be automatically saved when the inst...
EngineConfiguration Configuration
Gets the engine configuration represented by this file-backed store.
static EngineConfigurationFile Load(string? configFileName=null, bool? autoSave=null)
Loads an engine configuration file from disk.
void Dispose()
Releases all resources used by the EngineConfigurationFile.
EngineConfiguration EngineConfig
Gets the engine configuration settings.
void Save(string jsonPath)
Saves the configuration to the specified file path.
void Save()
Saves the configuration to the file specified by FilePath.
static EngineConfigurationFile CreateNew(string? configFileName=null, bool? autoSave=null)
Creates a new engine configuration file with default settings.
string FileName
Gets the name of the configuration file without the directory path.
Settings used by the engine when cycling.
Provides a persistence boundary for EngineConfiguration.