66using System . Text . Json ;
77using System . Text . Json . Serialization ;
88using System . Text . Json . Serialization . Metadata ;
9+ using WinGetStudio . Services . Core . Helpers ;
910using WinGetStudio . Services . DesiredStateConfiguration . Helpers ;
1011using WinGetStudio . Services . DesiredStateConfiguration . Models ;
1112using WinGetStudio . Services . DesiredStateConfiguration . Models . Schemas . ConfigurationV3 ;
@@ -97,7 +98,8 @@ public static string ToJson(this ConfigurationV3 config)
9798 public static string ToYaml ( this ConfigurationV3 config )
9899 {
99100 var json = config . ToJson ( ) ;
100- return DSCYamlHelper . JsonToYaml ( json ) ;
101+ var yaml = DSCYamlHelper . JsonToYaml ( json ) ;
102+ return AddYamlHeaderComment ( yaml ) ;
101103 }
102104
103105 /// <summary>
@@ -148,7 +150,7 @@ private static void ConfigurationV3PropertiesOrder(JsonTypeInfo typeInfo)
148150 /// <param name="dict">The parent dictionary.</param>
149151 /// <param name="key">The key to check.</param>
150152 /// <returns>The dictionary object.</returns>
151- public static IDictionary < string , object > EnsureObjectDict ( IDictionary < string , object > dict , string key )
153+ private static IDictionary < string , object > EnsureObjectDict ( IDictionary < string , object > dict , string key )
152154 {
153155 if ( ! dict . TryGetValue ( key , out var obj ) || obj is not IDictionary < string , object > value )
154156 {
@@ -158,4 +160,16 @@ public static IDictionary<string, object> EnsureObjectDict(IDictionary<string, o
158160
159161 return value ;
160162 }
163+
164+ /// <summary>
165+ /// Adds a YAML header comment indicating the tool and version used to
166+ /// create the configuration.
167+ /// </summary>
168+ /// <param name="yaml">The YAML string.</param>
169+ /// <returns>The YAML string with the header comment.</returns>
170+ private static string AddYamlHeaderComment ( string yaml )
171+ {
172+ var headerComment = $ "# Created with WinGet Studio - v{ RuntimeHelper . GetAppVersion ( ) } ";
173+ return headerComment + Environment . NewLine + Environment . NewLine + yaml ;
174+ }
161175}
0 commit comments