コード例 #1
0
 private static bool HasItem(List <SameLangItem> sameLangItems, SameLangItem sameLangItem, out SameLangItem lItem)
 {
     lItem = null;
     foreach (SameLangItem langItem in sameLangItems)
     {
         if (langItem.Tag == sameLangItem.Tag &&
             langItem.WorkLangName == sameLangItem.WorkLangName &&
             langItem.NodeName == sameLangItem.NodeName)
         {
             lItem = langItem;
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        public void SaveToFile()
        {
            List <SameLangItem> sameLangItems = new List <SameLangItem>();

            using (FileStream fileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                XElement xDoc = new XElement("ModPlus");
                xDoc.SetAttributeValue("Version", Version);
                xDoc.SetAttributeValue("Name", Name);
                // add nodes
                foreach (NodeModel nodeModel in Nodes)
                {
                    XElement nodeXel = new XElement(nodeModel.NodeName);
                    foreach (NodeAttributeModel attributeModel in nodeModel.Attributes)
                    {
                        nodeXel.SetAttributeValue(attributeModel.Name, attributeModel.Value);
                        if (attributeModel.SameLanguageNames.Any())
                        {
                            sameLangItems.Add(new SameLangItem(attributeModel.Name, Name, attributeModel.OwnerNodeModel.NodeName,
                                                               attributeModel.SameLanguageNames));
                        }
                    }
                    foreach (ItemModel itemModel in nodeModel.Items)
                    {
                        nodeXel.SetElementValue(itemModel.Tag, itemModel.Value);
                        if (itemModel.SameLanguageNames.Any())
                        {
                            sameLangItems.Add(new SameLangItem(itemModel.Tag, Name, itemModel.OwnerNodeModel.NodeName,
                                                               itemModel.SameLanguageNames));
                        }
                    }
                    xDoc.Add(nodeXel);
                }
                // save
                xDoc.Save(fileStream);
            }
            if (sameLangItems.Any())
            {
                SameLangItem.SaveToFile(sameLangItems);
            }
        }