示例#1
0
        private static StringItem createStringItem(XmlNode current)
        {
            StringItem item = new StringItem();
            item.value = current.InnerText;
            XmlAttributeCollection attribs = current.Attributes;
            for (int j = 0; j < attribs.Count; j++)
            {
                XmlAttribute atr = attribs[j];
                switch (atr.Name)
                {
                    case "_locID":
                        item.ID = int.Parse(attribs.GetNamedItem("_locID").InnerText);
                        break;

                    case "comment":
                        item.comment = attribs.GetNamedItem("comment").InnerText;
                        break;

                    case "symbol":
                        item.symbol = attribs.GetNamedItem("symbol").InnerText;
                        break;

                    case "gamecharacter":
                        item.gameCharacter = attribs.GetNamedItem("gamecharacter").InnerText;
                        break;

                    case "soundfilename":
                        item.soundFilename = attribs.GetNamedItem("soundfilename").InnerText;
                        break;

                    case "portraitfilename":
                        item.portraitFilename = attribs.GetNamedItem("portraitfilename").InnerText;
                        break;
                }
            }
            return item;
        }
示例#2
0
        /// <summary>
        /// Add a new StringItem to the stringtable
        /// </summary>
        /// <param name="value">StringItem to be added</param>
        /// <returns>True if successful, otherwise false</returns>
        public bool addString(StringItem value)
        {
            try
            {
                XmlElement newItem = stringtable.CreateElement("String");
                newItem.InnerText = value.value;
                newItem.SetAttribute("_locID", nextID.ToString());
                if (value.comment != "")
                    newItem.SetAttribute("comment", value.comment);
                if (value.symbol != "")
                    newItem.SetAttribute("symbol", value.symbol);
                if (value.gameCharacter != "")
                    newItem.SetAttribute("gamecharacter", value.gameCharacter);
                if (value.portraitFilename != "")
                    newItem.SetAttribute("portraitfilename", value.portraitFilename);
                if (value.soundFilename != "")
                    newItem.SetAttribute("soundfilename", value.soundFilename);

                stringtable.SelectSingleNode("/StringTable/Language").AppendChild(newItem);
                nextID++;
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
示例#3
0
 /// <summary>
 /// Replace a string in the stringtable file with
 /// one that has been supplied via parameter.
 /// </summary>
 /// <param name="value">The StringItem to be used
 /// in the set operation.</param>
 /// <returns>True if successful, otherwise false.</returns>
 public bool setStringById(StringItem value)
 {
     try
     {
         XmlNodeList allStrings = stringtable.GetElementsByTagName("String");
         foreach (XmlElement current in allStrings)
         {
             if (int.Parse(current.Attributes.GetNamedItem("_locID").InnerText) == value.ID)
             {
                 // This is the string we're looking for! Update the values.
                 current.InnerText = value.value;
                 // Comment?
                 if (value.comment != "")
                 {
                     current.SetAttribute("comment", value.comment);
                 }
                 else
                 {
                     current.RemoveAttribute("comment");
                 }
                 // Symbol?
                 if (value.symbol != "")
                 {
                     current.SetAttribute("symbol", value.symbol);
                 }
                 else
                 {
                     current.RemoveAttribute("symbol");
                 }
                 // Gamecharacter?
                 if (value.gameCharacter != "")
                 {
                     current.SetAttribute("gamecharacter", value.gameCharacter);
                 }
                 else
                 {
                     current.RemoveAttribute("gamecharacter");
                 }
                 // Soundfilename?
                 if (value.soundFilename != "")
                 {
                     current.SetAttribute("soundfilename", value.soundFilename);
                 }
                 else
                 {
                     current.RemoveAttribute("soundfilename");
                 }
                 // Portraitfilename?
                 if (value.portraitFilename != "")
                 {
                     current.SetAttribute("portraitfilename", value.portraitFilename);
                 }
                 else
                 {
                     current.RemoveAttribute("portraitfilename");
                 }
                 // That should be it, if we've got here without
                 // throwing some sort of exception I think we can
                 // declare success.
                 return true;
             }
         }
     }
     catch (Exception e)
     {
         return false;
     }
     return false;
 }