private string GetDefaultToml() { var doc = new DocumentSyntax() { Tables = { new TableSyntax(new KeySyntax("config")) { Items = { { "schemaVersion", "0.0.1" } } }, new TableSyntax(new KeySyntax("auth")) { Items = { { "defaultToken", "" } } }, new TableSyntax(new KeySyntax("auth", "authorTokens")) { Items = { { "ExampleAuthor", "" } } }, } }; return(doc.ToString()); }
/// <summary> /// Save the document syntax to the root file /// </summary> public static async Task SerializeAsync(DocumentSyntax documentSyntax, System.IO.Stream stream) { // Write out the entire root table var content = documentSyntax.ToString(); using (var writer = new System.IO.StreamWriter(stream)) { await writer.WriteAsync(content); } }
public void TestDocument() { var doc = new DocumentSyntax() { Tables = { new TableSyntax("test") { Items = { { "a", 1 }, { "b", true }, { "c", "Check" }, { "d", "ToEscape\nWithAnotherChar\t" }, { "e", 12.5 }, { "f", new int[] { 1, 2, 3, 4 } }, { "g", new string[] { "0", "1", "2" } }, { "key with space", 2 } } } } }; var docStr = doc.ToString(); var expected = @"[test] a = 1 b = true c = ""Check"" d = ""ToEscape\nWithAnotherChar\t"" e = 12.5 f = [1, 2, 3, 4] g = [""0"", ""1"", ""2""] ""key with space"" = 2 "; AssertHelper.AreEqualNormalizeNewLine(expected, docStr); // Reparse the result and compare it again var newDoc = Toml.Parse(docStr); AssertHelper.AreEqualNormalizeNewLine(expected, newDoc.ToString()); }
public void Save(string path) { var doc = new DocumentSyntax() { Tables = { new TableSyntax("AssemblyGenerator") { Items = { { "UnityVersion", (UnityVersion == null) ? "" : UnityVersion }, { "GameAssemblyHash", (GameAssemblyHash == null) ? "" : GameAssemblyHash }, { "DumperVersion", (DumperVersion == null) ? "" : DumperVersion }, { "UnhollowerVersion", (UnhollowerVersion == null) ? "" : UnhollowerVersion }, { "OldFiles", OldFiles.ToArray() } } } } }; File.WriteAllText(path, doc.ToString()); }
internal static void Save() { DocumentSyntax doc = new DocumentSyntax() { Tables = { new TableSyntax("AssemblyGenerator") { Items = { { "UnityVersion", (UnityVersion == null) ? "" : UnityVersion }, { "Cpp2IL", (Cpp2ILVersion == null) ? "" : Cpp2ILVersion }, { "Il2CppAssemblyUnhollower", (Il2CppAssemblyUnhollowerVersion == null) ? "" : Il2CppAssemblyUnhollowerVersion }, { "GameAssemblyHash", (GameAssemblyHash == null) ? "" : GameAssemblyHash }, { "OldFiles", OldFiles.ToArray() } } } } }; File.WriteAllText(FilePath, doc.ToString()); }
internal void Write() { var doc = new DocumentSyntax(); foreach (var credential in credentials.Values) { if (string.IsNullOrEmpty(credential.token)) { credential.token = ""; } doc.Tables.Add(new TableSyntax(new KeySyntax("npmAuth", credential.url)) { Items = { { "token", credential.token }, { "alwaysAuth", credential.alwaysAuth } } }); } File.WriteAllText(upmconfigFile, doc.ToString()); }
public static void WriteDefault() { var path = GetFilepath(); if (File.Exists(path)) { Console.WriteLine($"Project configuration already exists at {path}, skipping creation"); } else { var doc = new DocumentSyntax() { Tables = { new TableSyntax("config") { Items = { { "schemaVersion", "0.0.1" } } }, new TableSyntax("package") { Items = { { "author", "AuthorName" }, { "name", "PackageName" }, { "versionNumber", "1.0.0" }, { "description", "" }, { "websiteUrl", "" }, } }, new TableSyntax(new KeySyntax("package", "dependencies")) { Items = { { "Example-Dependency", "1.0.0" }, }, }, new TableSyntax("build") { Items = { { "icon", "./icon.png" }, { "readme", "./README.md" }, { "outdir", "./build" }, } }, new TableSyntax(new KeySyntax("build", "copy")) { Items = { { "./dist", "./" } } }, new TableSyntax(new KeySyntax("publish")) { Items = { { "repository", "thunderstore.io" } } } } }; File.WriteAllText(path, doc.ToString()); Console.WriteLine($"Wrote project configuration to {path}"); } }
public void TestDocument() { var table = new TableSyntax("test") { Items = { { "a", 1 }, { "b", true }, { "c", "Check" }, { "d", "ToEscape\nWithAnotherChar\t" }, { "e", 12.5 }, { "f", new int[] { 1, 2, 3, 4 } }, { "g", new string[] { "0", "1", "2" } }, { "key with space", 2 } } }; var doc = new DocumentSyntax() { Tables = { table } }; table.AddLeadingComment("This is a comment"); table.AddLeadingTriviaNewLine(); var firstElement = table.Items.GetChildren(0); firstElement.AddTrailingComment("This is an item comment"); var secondElement = table.Items.GetChildren(2); secondElement.AddLeadingTriviaNewLine(); secondElement.AddLeadingComment("This is a comment in a middle of a table"); secondElement.AddLeadingTriviaNewLine(); secondElement.AddLeadingTriviaNewLine(); var docStr = doc.ToString(); var expected = @"# This is a comment [test] a = 1 # This is an item comment b = true # This is a comment in a middle of a table c = ""Check"" d = ""ToEscape\nWithAnotherChar\t"" e = 12.5 f = [1, 2, 3, 4] g = [""0"", ""1"", ""2""] ""key with space"" = 2 "; AssertHelper.AreEqualNormalizeNewLine(expected, docStr); // Reparse the result and compare it again var newDoc = Toml.Parse(docStr); AssertHelper.AreEqualNormalizeNewLine(expected, newDoc.ToString()); }
public void CreateConfig(DocumentSyntax initialConfig = null) { File.WriteAllText(ConfigPath, (initialConfig?.ToString() ?? "") + "\n"); }
public void CreateConfig(DocumentSyntax initialConfig = null) { File.WriteAllText(ConfigPath, (initialConfig?.ToString() ?? "") + "\n"); Logger.Warn($"Created new config at {ConfigPath}."); }