Exemplo n.º 1
0
        private static MockRegistryKey Find(List <MockRegistryKey> topKeys, string fullKey)
        {
            Stack <string> s = CreateStack(fullKey);

            if (s.Count() == 0)
            {
                return(null);
            }
            string          k        = s.Pop(); // HKEY_LOCAL_MACHINE
            var             existing = topKeys.Where(m => m.ShortName == k);
            MockRegistryKey topKey   = null;

            if (existing.Count() > 0)
            {
                topKey = existing.First();
            }
            if (s.Count() == 0)
            {
                return(topKey);
            }
            else
            {
                return(topKey.Find(s));
            }
        }
Exemplo n.º 2
0
 public MockRegistry(string localMachineTestReg, string currentUserTestReg = null)
 {
     localMachine = MockRegistryKey.Parse(localMachineTestReg);
     if (string.IsNullOrEmpty(currentUserTestReg))
     {
         currentUser = null;
     }
     else
     {
         currentUser = MockRegistryKey.Parse(currentUserTestReg);
     }
 }
Exemplo n.º 3
0
        internal static MockRegistryKey Parse(string localMachineTestReg)
        {
            //[HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64]
            //'InstallPath'='C:\\Program Files\\R\\R-3.3.3'
            //'Current Version'='3.3.3'
            List <MockRegistryKey> topKeys = new List <MockRegistryKey>();
            var    lines      = localMachineTestReg.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
            string currentKey = null;

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                if (line.StartsWith("["))
                {
                    currentKey = line.Replace("[", "").Replace("]", ""); // so left with HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64
                    Populate(currentKey, topKeys);
                }
                else if (currentKey != null)
                {
                    var x = line.Trim();
                    if (x.Length == 0)
                    {
                        continue;
                    }
                    else
                    {
                        MockRegistryKey k = Find(topKeys, currentKey);
                        //'InstallPath'='C:\\Program Files\\R\\R-3.3.3'
                        var keyVal = x.Replace("'", "").Split('=');
                        k.AddKeyVal(keyVal[0], keyVal[1]);
                    }
                }
            }
            if (topKeys.Count() != 1)
            {
                throw new Exception("");
            }
            return(topKeys[0]);
        }
Exemplo n.º 4
0
        private MockRegistryKey Find(Stack <string> s)
        {
            if (s.Count() == 0)
            {
                return(null);
            }
            string          k        = s.Pop();
            var             existing = this.subKeys.Where(m => m.ShortName == k);
            MockRegistryKey topKey   = null;

            if (existing.Count() > 0)
            {
                topKey = existing.First();
            }
            if (s.Count() == 0)
            {
                return(topKey);
            }
            else
            {
                return(topKey.Find(s));
            }
        }
Exemplo n.º 5
0
        private static void Populate(string fullKey, List <MockRegistryKey> topKeys)
        {
            // fullKey is expected to be something like: HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64
            Stack <string> s = CreateStack(fullKey);

            if (s.Count() == 0)
            {
                return;
            }
            string          k        = s.Pop(); // HKEY_LOCAL_MACHINE
            var             existing = topKeys.Where(m => m.ShortName == k);
            MockRegistryKey topKey   = null;

            if (existing.Count() > 0)
            {
                topKey = existing.First();
                topKey.AddSubKeys(s);
            }
            else
            {
                topKey = new MockRegistryKey(fullKey);
                topKeys.Add(topKey);
            }
        }
Exemplo n.º 6
0
 public MockRegistry(MockRegistryKey localMachine, MockRegistryKey currentUser)
 {
     this.localMachine = localMachine;
     this.currentUser  = currentUser;
 }