예제 #1
0
파일: InstallManager.cs 프로젝트: akutz/nvn
 /// <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
파일: InstallManager.cs 프로젝트: akutz/nvn
        /// <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
파일: InstallManager.cs 프로젝트: akutz/nvn
        /// <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;
        }