예제 #1
0
        // -------- Ini Serialization --------

        /// <summary>
        /// Save the content of this value store as a Ini file formatted string.
        /// </summary>
        public static string Save(ValueStore store)
        {
            var output = new StringBuilder();

            foreach (var node in store.Roots)
            {
                SaveIniRecursive(output, "", node, false);
            }
            return(output.ToString());
        }
예제 #2
0
 /// <summary>
 /// Create the main runtime profile with the given value store.
 /// </summary>
 /// <remarks>
 /// This method is automatically called by <see cref="T:sttz.Trimmer.Editor.BuildManager"/>
 /// and <see cref="ProfileContainer"/> and should not be called manually.
 /// </remarks>
 public static void CreateMain(ValueStore store)
 {
     if (Main == null)
     {
         Main = new RuntimeProfile(store);
     }
     else
     {
         Main.Store = store;
     }
 }
예제 #3
0
        /// <summary>
        /// Create a clone of the current store.
        /// </summary>
        public ValueStore Clone()
        {
            var clone = new ValueStore();

            clone.nodes = new List <RootNode>(nodes.Count);
            foreach (var node in nodes)
            {
                clone.nodes.Add((RootNode)node.Clone());
            }

            return(clone);
        }
예제 #4
0
        /// <summary>
        /// Create a new profile with given defaults.
        /// </summary>
        public RuntimeProfile(ValueStore store)
        {
            // Create Option instances
            foreach (var optionType in AllOptionTypes)
            {
                if (ShouldCreateOption(optionType))
                {
                    var option = (Option)Activator.CreateInstance(optionType);
                    options.Add(option);
                    optionsByName[option.Name] = option;
                }
            }
            options.Sort((a, b) => a.ApplyOrder.CompareTo(b.ApplyOrder));

            // Set store, which sets its values on the Options
            Store = store;
        }
예제 #5
0
        // ------ Ini Deserialization ------

        /// <summary>
        /// Load the values in an Ini file into this value store instance,
        /// replacing the value store's contents.
        /// </summary>
        public static void Load(ValueStore store, string content)
        {
            // TODO: More input validation
            var lines = content.Split('\n');

            foreach (var line in lines)
            {
                if (commentedLineRegex.IsMatch(line) || line.Trim().Length == 0)
                {
                    continue;
                }

                var match = LineRegex.Match(line);
                if (!match.Success)
                {
                    Debug.LogWarning("Failed to read line in Ini file: " + line);
                    continue;
                }

                // Groups:
                // 1 = Regular Name
                // 2 = Child name
                // 3 = Quoted Parameter
                // 4 = Unquoted Parameter
                // 5 = Quoted Value
                // 6 = Unquoted Value

                var rootCapture = match.Groups[1];
                var rootNode    = store.GetOrCreateRoot(rootCapture.Value);

                var node = GetNodeRecursive(rootNode, match, rootCapture.Index + rootCapture.Length - 1);

                var isQuoted     = true;
                var valueCapture = match.Groups[5];
                if (!valueCapture.Success)
                {
                    isQuoted     = false;
                    valueCapture = match.Groups[6];
                }

                node.value = ProcessQuotedString(valueCapture.Value, isQuoted);
            }
        }