Example #1
0
 /// <summary>
 /// write to .config file to save config values
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public async Task <int> WriteDotConfig(string fileName = ".config")
 {
     _opMutex.WaitOne();
     try
     {
         return(await DotConfigIo.WriteFile(Entries, fileName));
     }
     finally
     {
         _opMutex.ReleaseMutex();
     }
 }
Example #2
0
        /// <summary>
        /// read from .config file to get previous config values
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private async Task <int> ReadDotConfig(string fileName = ".config")
        {
            var list = await DotConfigIo.ReadFile(fileName);

            if (list == null)
            {
                return(0);
            }

            foreach (var entries in HierarchicalList)
            {
                var removeSet = new HashSet <DotConfigItem>();
                foreach (var item in list)
                {
                    var entry = entries.FirstOrDefault(menuEntry => menuEntry.Name == item.Name);
                    if (entry == null)
                    {
                        continue;
                    }
                    removeSet.Add(item);

                    if ((entry.ValueType == MenuAttributeType.Bool) &&
                        (item.Type == MenuAttributeType.Tristate))
                    {
                        entry.Value = item.Value;
                        continue;
                    }

                    if (entry.ValueType == item.Type)
                    {
                        entry.Value = item.Value;
                    }
                }

                foreach (var item in removeSet)
                {
                    list.Remove(item);
                }

                if (list.Count == 0)
                {
                    return(0);
                }
            }

            return(0);
        }