Example #1
0
        /// <summary>
        /// Write a nest entry to file writer
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="sw"></param>
        /// <returns></returns>
        private static async Task WriteEntry(MenuEntry entry, FileWriter sw)
        {
            if (!entry.IsEnable)
            {
                return;
            }
            switch (entry.EntryType)
            {
            case MenuEntryType.MainMenu:
                await sw.WriteLineAsync(
                    $"#\n# Automatically generated file; DO NOT EDIT.\n# {entry.Prompt}\n#");

                break;

            case MenuEntryType.Menu:
                await sw.WriteLineAsync($"\n#\n# {entry.Prompt}\n#");

                break;

            case MenuEntryType.Choice:
                break;

            case MenuEntryType.Config:
            case MenuEntryType.MenuConfig:
                //skip global variable
                if (entry.Name.StartsWith("$"))
                {
                    break;
                }
                if ((entry.ValueType == MenuAttributeType.Bool) ||
                    (entry.ValueType == MenuAttributeType.Tristate))
                {
                    if (entry.Value == "n")
                    {
                        await sw.WriteLineAsync($"# CONFIG_{entry.Name} is not set");

                        break;
                    }
                }

                if (entry.ValueType == MenuAttributeType.String)
                {
                    await sw.WriteLineAsync($"CONFIG_{entry.Name}=\"{entry.Value}\"");
                }
                else
                {
                    await sw.WriteLineAsync($"CONFIG_{entry.Name}={entry.Value}");
                }
                break;

            case MenuEntryType.Comment:
                await sw.WriteLineAsync($"# {entry.Prompt}");

                return;
            }

            if (entry.ChildEntries != null)
            {
                foreach (var childEntry in entry.ChildEntries)
                {
                    await WriteEntry(childEntry, sw);
                }
            }
        }