Exemplo n.º 1
0
        IDictionary <string, int> GetNumberValues(string regKey, string subKey)
        {
            if (string.IsNullOrEmpty(regKey))
            {
                throw new ArgumentNullException("regKey");
            }
            if (string.IsNullOrEmpty(subKey))
            {
                throw new ArgumentNullException("subKey");
            }
            IDictionary <string, int> values;

            lock (_lock)
            {
                subKey = regKey + "\\" + subKey;
                using (RegistryKey reg = OpenHKCUKey(subKey))
                {
                    if (reg == null)
                    {
                        return(null);
                    }
                    HybridCollection <string> hs = new HybridCollection <string>();
                    hs.AddRange(reg.GetValueNames());

                    values = new Dictionary <string, int>(hs.Count);

                    foreach (string item in hs)
                    {
                        int width;
                        if (RegistryUtils.TryGetIntValue(reg, item, out width) && width > 0)
                        {
                            values.Add(item, width);
                        }
                    }
                }
            }
            return(values);
        }
Exemplo n.º 2
0
        public void Add(string item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            else if (!_allowWhiteSpace && string.IsNullOrEmpty(item))
            {
                return; // Don't add whitepace
            }
            using (RegistryKey key = OpenFifoKey(false))
            {
                int nSize;
                int nPos;
                if (!RegistryUtils.TryGetIntValue(key, "_size", out nSize) || nSize < 1)
                {
                    nSize = _defaultSize;
                    key.SetValue("_size", _defaultSize);
                }

                // This gives a very tiny race condition if used at the same time in
                // two VS instances.
                // We ignore this as it is just UI helper code and a user can't edit
                //  two windows at the same time
                if (!RegistryUtils.TryGetIntValue(key, "_pos", out nPos) || (nPos < 0) || (nPos >= nSize))
                {
                    nPos = 0;
                }

                if (nPos < 0 || nPos >= nSize)
                {
                    List <string> names = new List <string>(key.GetValueNames());

                    int nX = nSize;
                    for (int i = nSize - 1; i >= 0; i--)
                    {
                        if (names.Contains("#" + i.ToString(CultureInfo.InvariantCulture)))
                        {
                            break;
                        }

                        nX = i;
                    }

                    if (nX < nSize)
                    {
                        nPos = nX;
                    }
                    else
                    {
                        nPos = 0;
                    }
                }


                nPos++;

                if (nPos > nSize)
                {
                    nPos = 0;
                }

                key.SetValue("_pos", nPos);
                key.SetValue("#" + nPos.ToString(CultureInfo.InvariantCulture), item);
            }
        }