Пример #1
0
 /// <summary>
 /// Processes a registry value.
 /// </summary>
 /// <param name="rv">A registry value.</param>
 /// <returns>
 /// True if the value is found and meets the specified 
 /// condition. The Inverse property may be used to invert
 /// the returned value.
 /// </returns>
 private static bool ProcessRegValue(RegValue rv)
 {
     var er = EvalRegValue(rv);
     return rv.Inverse ? !er : er;
 }
Пример #2
0
        /// <summary>
        /// Evaluates a registry value.
        /// </summary>
        /// <param name="rv">A registry value.</param>
        /// <returns>
        /// True if the value is found and meets the specified 
        /// condition.
        /// </returns>
        private static bool EvalRegValue(RegValue rv)
        {
            if (rv == null)
            {
                return false;
            }

            var frk = rv.X64
                ? RegUtils.OpenKey(
                    rv.Path, false, RegUtils.ProcessArchitecture.X64)
                : RegUtils.OpenKey(rv.Path);

            if (frk == null)
            {
                return false;
            }

            var ov = frk.GetValue(rv.ValueName);

            frk.Close();

            if (ov == null)
            {
                return false;
            }

            var tn = rv.TypeName;
            var rvv = rv.Value;

            if (tn == "string")
            {
                if (rv.Comparison == "==")
                {
                    return rvv == (string) ov;
                }

                if (rv.Comparison == "!=")
                {
                    return rvv != (string) ov;
                }

                return false;
            }

            if (tn == "match")
            {
                var rx = new Regex(rvv);
                return rx.IsMatch((string) ov);
            }

            if (tn == "version")
            {
                var rx = new Regex(@"\d+(?:\.\d+){0,2}");
                var rvVer = new Version(rx.Match(rvv).Groups[0].Value);
                var vVer = new Version(rx.Match((string) ov).Groups[0].Value);

                switch (rv.Comparison)
                {
                    case @"==":
                    {
                        return rvVer == vVer;
                    }
                    case @"!=":
                    {
                        return rvVer != vVer;
                    }
                    case @">":
                    {
                        return rvVer > vVer;
                    }
                    case @"<":
                    {
                        return rvVer < vVer;
                    }
                    case @">=":
                    {
                        return rvVer >= vVer;
                    }
                    case @"<=":
                    {
                        return rvVer <= vVer;
                    }
                    default:
                    {
                        return false;
                    }
                }
            }

            if (tn == "long")
            {
                var vLong = long.Parse(string.Format("{0}", ov));
                var rvLong = long.Parse(rvv);

                switch (rv.Comparison)
                {
                    case @"==":
                    {
                        return rvLong == vLong;
                    }
                    case @"!=":
                    {
                        return rvLong != vLong;
                    }
                    case @">":
                    {
                        return rvLong > vLong;
                    }
                    case @"<":
                    {
                        return rvLong < vLong;
                    }
                    case @">=":
                    {
                        return rvLong >= vLong;
                    }
                    case @"<=":
                    {
                        return rvLong <= vLong;
                    }
                    default:
                    {
                        return false;
                    }
                }
            }

            return false;
        }
Пример #3
0
        /// <summary>
        /// Evaluates a registry value.
        /// </summary>
        /// <param name="rv">A registry value.</param>
        /// <returns>
        /// True if the value is found and meets the specified 
        /// condition.
        /// </returns>
        private static bool EvalRegValue(RegValue rv)
        {
            if (rv == null)
            {
                return false;
            }

            var kp = ExpandRegRootName(rv.KeyPath);

            var ov = Registry.GetValue(kp, rv.ValueName, null);

            if (ov == null)
            {
                return false;
            }

            var tn = rv.TypeName;
            var rvv = rv.Value;

            if (tn == "string")
            {
                if (rv.Comparison == "==")
                {
                    return rvv == (string) ov;
                }

                if (rv.Comparison == "!=")
                {
                    return rvv != (string) ov;
                }

                return false;
            }

            if (tn == "match")
            {
                var rx = new Regex(rvv);
                return rx.IsMatch((string) ov);
            }

            if (tn == "version")
            {
                var rx = new Regex(@"\d+(?:\.\d+){0,2}");
                var rvVer = new Version(rx.Match(rvv).Groups[0].Value);
                var vVer = new Version(rx.Match((string) ov).Groups[0].Value);

                switch (rv.Comparison)
                {
                    case @"==":
                    {
                        return rvVer == vVer;
                    }
                    case @"!=":
                    {
                        return rvVer != vVer;
                    }
                    case @">":
                    {
                        return rvVer > vVer;
                    }
                    case @"<":
                    {
                        return rvVer < vVer;
                    }
                    case @">=":
                    {
                        return rvVer >= vVer;
                    }
                    case @"<=":
                    {
                        return rvVer <= vVer;
                    }
                    default:
                    {
                        return false;
                    }
                }
            }

            if (tn == "long")
            {
                var vLong = long.Parse(string.Format("{0}", ov));
                var rvLong = long.Parse(rvv);

                switch (rv.Comparison)
                {
                    case @"==":
                    {
                        return rvLong == vLong;
                    }
                    case @"!=":
                    {
                        return rvLong != vLong;
                    }
                    case @">":
                    {
                        return rvLong > vLong;
                    }
                    case @"<":
                    {
                        return rvLong < vLong;
                    }
                    case @">=":
                    {
                        return rvLong >= vLong;
                    }
                    case @"<=":
                    {
                        return rvLong <= vLong;
                    }
                    default:
                    {
                        return false;
                    }
                }
            }

            return false;
        }