/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes the keys.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void DeleteKeys()
        {
            List <string> keys = new List <string>(m_KeysToDelete.Count);

            keys.AddRange(m_KeysToDelete.Keys);
            keys.Sort();
            for (int i = keys.Count - 1; i >= 0; i--)
            {
                DeleteKeyInfo delKeyInfo = m_KeysToDelete[keys[i]];
                string        keyName    = delKeyInfo.KeyName;
                RegistryKey   hiveKey    = delKeyInfo.Hive;
                RegistryKey   parentKey;
                int           iLastBackslash = keyName.LastIndexOf('\\');
                if (iLastBackslash >= 0)
                {
                    parentKey = hiveKey.OpenSubKey(keyName.Substring(0, iLastBackslash), true);
                    keyName   = keyName.Substring(iLastBackslash + 1);
                }
                else
                {
                    parentKey = hiveKey;
                }

                if (delKeyInfo.IsCreated)
                {
                    parentKey.DeleteSubKeyTree(keyName);
                }
                else
                {
                    parentKey.DeleteSubKey(keyName, FailOnError);
                }
            }
        }
Ejemplo n.º 2
0
        public DeleteKeyInfo DeleteKey(StringData stringData, bool translationsOnly, ProgressBar bar)
        {
            DeleteKeyInfo info = new DeleteKeyInfo();

            try
            {
                foreach (LanguageData languageData in stringData.Data)
                {
                    string code = languageData.Code;
                    if (translationsOnly && String.IsNullOrEmpty(code))
                    {
                        continue;
                    }

                    string fileName = languageData.FileName;

                    XmlDocument doc = new XmlDocument();
                    doc.PreserveWhitespace = true;
                    doc.Load(fileName);

                    XmlNode     parent = doc.SelectSingleNode("/resources");
                    XmlNodeList nodes  = doc.SelectNodes("/resources/string[@name='" + stringData.StringId + "']");
                    foreach (XmlNode node in nodes)
                    {
                        XmlNode previous = node.PreviousSibling;
                        while (previous != null && previous is XmlWhitespace)
                        {
                            XmlNode whitespace = previous;
                            previous = whitespace.PreviousSibling;
                            parent.RemoveChild(whitespace);
                        }
                        parent.RemoveChild(node);
                        info.Count++;
                    }

                    doc.Save(fileName);
                }
            }
            catch (Exception e)
            {
                info.Error = e;
            }

            return(info);
        }