Esempio n. 1
0
    public void ClearTest()
    {
        var store = new ValueStore();

        IniAdapter.Load(store, ini);

        var node = store.AddRoot("Superfluous", "Value");

        node.AddChild("Child", "Value");

        var profile = new RuntimeProfile();

        profile.Store = store;
        profile.CleanStore();

        Assert.IsNull(profile.GetOption("Superfluous/Child"));
        Assert.IsNull(profile.GetOption("Superfluous"));

        var option = profile.GetOption("ParentDummy");

        Assert.IsNotNull(option);
        Assert.IsTrue(option.Save() == "no");

        option = profile.GetOption("ParentDummy/Child2:Child2Variant2/Child3/Child4/Child5:Default1");
        Assert.IsNotNull(option);
        Assert.IsNotNull(option.Save() == "Child5Default1Value");
    }
Esempio n. 2
0
        protected void CompleteOptionRecursive(string path, Option option, string baseInput)
        {
            if (!option.Path.StartsWith(path, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (option.Parent == null || option.IsDefaultVariant || option.Variance == OptionVariance.Single)
            {
                if (option.Parent != null)
                {
                    baseInput += ".";
                }
                baseInput += option.Name;
            }

            if (option.Variance != OptionVariance.Single && !option.IsDefaultVariant)
            {
                baseInput += "[" + IniAdapter.QuoteParameterIfNeeded(option.VariantParameter) + "]";
            }

            completions.Add(baseInput + " = " + option.Save());

            foreach (var variant in option.Variants)
            {
                CompleteOptionRecursive(path, variant, baseInput);
            }

            foreach (var child in option.Children)
            {
                CompleteOptionRecursive(path, child, baseInput);
            }
        }
Esempio n. 3
0
        string CommandSet(string name, string input)
        {
            var path = IniAdapter.NameToPath(input);

            if (path == null)
            {
                return("ERROR Invalid Option path");
            }

            var value = IniAdapter.GetValue(input);

            if (value == null)
            {
                return("ERROR Invalid Option value");
            }

            var option = RuntimeProfile.Main.GetOption(path);

            if (option == null)
            {
                return("ERROR Option not found");
            }

            option.Load(value);
            option.ApplyFromRoot();

            return(option.Save());
        }
Esempio n. 4
0
        /// <summary>
        /// Load an ini file from the given path.
        /// </summary>
        public void LoadIniFile(string path)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("Invalid path: Ini file '" + path + "' does not exist");
                return;
            }

            Debug.Log("Loading ini file: " + path);

            var data = File.ReadAllText(path);

            IniAdapter.Load(RuntimeProfile.Main.Store, data);
            RuntimeProfile.Main.Load();
        }
Esempio n. 5
0
        string CommandGet(string name, string input)
        {
            var path = IniAdapter.NameToPath(input);

            if (path == null)
            {
                return("ERROR Invalid Option path");
            }

            var option = RuntimeProfile.Main.GetOption(path);

            if (option == null)
            {
                return("ERROR Option not found");
            }

            return(option.Save());
        }
Esempio n. 6
0
    public void Test()
    {
        var store = new ValueStore();

        IniAdapter.Load(store, ini);

        var node = store.AddRoot("Superfluous", "Value");

        node.AddChild("Child", "Value");

        var profile = new RuntimeProfile();

        profile.Store = store;
        profile.SaveToStore();

        var newIni = IniAdapter.Save(profile.Store);

        System.IO.File.WriteAllText("/Users/adrian/Desktop/orig.ini", SortAndTrim(ini));
        System.IO.File.WriteAllText("/Users/adrian/Desktop/new.ini", SortAndTrim(newIni));
        Assert.True(SortAndTrim(ini) == SortAndTrim(newIni));
    }
Esempio n. 7
0
        protected void ExecutePrompt()
        {
            // Enter on empty prompt closes it
            if (input.Length == 0)
            {
                StopPrompt();

                // Set a option value
            }
            else if (input.Contains("="))
            {
                var path = IniAdapter.NameToPath(input);
                if (path != null)
                {
                    var option = RuntimeProfile.Main.GetOption(path);
                    var value  = IniAdapter.GetValue(input);
                    if (option != null && value != null)
                    {
                        option.Load(value);
                        option.ApplyFromRoot();
                        input = "";
                    }
                }

                // Enter on an option shows it's value
            }
            else
            {
                var path = IniAdapter.NameToPath(input);
                if (path != null)
                {
                    var option = RuntimeProfile.Main.GetOption(path);
                    if (option != null)
                    {
                        input += " = " + option.Save();
                    }
                }
            }
        }
Esempio n. 8
0
        protected void CompletePrompt(int moveIndex = 0)
        {
            // Generate completions list
            if (completions.Count == 0 || moveIndex == 0)
            {
                completions.Clear();

                var path = IniAdapter.NameToPath(input);
                if (path != null)
                {
                    foreach (var option in RuntimeProfile.Main)
                    {
                        if (option.Path.StartsWith(path, StringComparison.OrdinalIgnoreCase))
                        {
                            CompleteOptionRecursive(path, option, "");
                        }
                    }
                }
                if (completions.Count > 0)
                {
                    completions.Sort();
                    completions.Insert(0, input);
                    completions.Add("");
                    completionIndex = 1;
                }

                // Move completions index
            }
            else
            {
                completionIndex = Mathf.Max(Mathf.Min(completionIndex + moveIndex, completions.Count - 1), 0);
            }

            // Show new completion
            if (completionIndex < completions.Count)
            {
                input = completions[completionIndex];
            }
        }
Esempio n. 9
0
 public void PasteFromIniFile()
 {
     Undo.RecordObject(this, "Paste From Ini File");
     IniAdapter.Load(Store, EditorGUIUtility.systemCopyBuffer);
 }
Esempio n. 10
0
 public void CopyAsIniFile()
 {
     EditorGUIUtility.systemCopyBuffer = IniAdapter.Save(Store);
 }