-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaf6249
commit 1fccd20
Showing
6 changed files
with
61 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
AssettoServer/Server/Configuration/ReferenceConfigurationHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.ObjectGraphVisitors; | ||
|
||
namespace AssettoServer.Server.Configuration; | ||
|
||
public static class ReferenceConfigurationHelper | ||
{ | ||
private const string BaseFolder = "cfg/reference"; | ||
|
||
public static void WriteReferenceConfiguration(string filename, string schemaPath, object config, string name) | ||
{ | ||
Directory.CreateDirectory(BaseFolder); | ||
|
||
var path = Path.Join(BaseFolder, filename); | ||
|
||
FileInfo? info = null; | ||
if (File.Exists(path)) | ||
{ | ||
info = new FileInfo(path); | ||
info.IsReadOnly = false; | ||
} | ||
|
||
using (var writer = File.CreateText(path)) | ||
{ | ||
ConfigurationSchemaGenerator.WriteModeLine(writer, BaseFolder, schemaPath); | ||
writer.WriteLine($"# {name} Reference Configuration"); | ||
writer.WriteLine("# This file serves as an overview of all possible options with their default values."); | ||
writer.WriteLine(); | ||
|
||
var builder = new SerializerBuilder() | ||
.WithoutEmissionPhaseObjectGraphVisitor<DefaultValuesObjectGraphVisitor>() | ||
.Build(); | ||
|
||
builder.Serialize(writer, config); | ||
} | ||
|
||
info ??= new FileInfo(path); | ||
info.IsReadOnly = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters