Пример #1
0
        /// <summary>
        /// Applies metadata to an in-memory ESD, adding additional info.
        /// </summary>
        public static void Apply(ESDL esd, ESDMetadata meta)
        {
            if (meta.ESDHash.Trim().ToUpper() != esd.LastSavedHash.Trim().ToUpper())
            {
                throw new Exception("MD5 Hash of ESD file does not match that of the saved metadata. Metadata was not made for this ESD file.");
            }

            esd.StateGroupNames = meta.StateGroupNames;

            foreach (var g in esd.StateGroups.Keys)
            {
                foreach (var s in esd.StateGroups[g].Keys)
                {
                    esd.StateGroups[g][s].Name        = meta.StateMetadatas[g][s].Name;
                    esd.StateGroups[g][s].EntryScript = meta.StateMetadatas[g][s].EntryScript;
                    esd.StateGroups[g][s].ExitScript  = meta.StateMetadatas[g][s].ExitScript;
                    esd.StateGroups[g][s].WhileScript = meta.StateMetadatas[g][s].WhileScript;
                }
            }

            foreach (var g in esd.GetAllConditions())
            {
                foreach (var c in g.Value)
                {
                    c.Name       = meta.ConditionMetadatas[c.MetaRefID].Name;
                    c.Evaluator  = meta.ConditionMetadatas[c.MetaRefID].Evaluator;
                    c.PassScript = meta.ConditionMetadatas[c.MetaRefID].PassScript;
                }
            }
        }
Пример #2
0
        private static ESDMetadata InnerReadFromBinary(string binFileName)
        {
            var meta = new ESDMetadata();

            using (var fileStream = System.IO.File.Open(binFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                var br = new BinaryReaderEx(bigEndian: false, stream: fileStream);
                br.AssertASCII("ESD_META");
                br.AssertInt64(CURRENT_BINARY_VERSION);
                meta.ESDHash = br.ReadASCII();
                int stateGroupCount = br.ReadInt32();
                for (int i = 0; i < stateGroupCount; i++)
                {
                    long   stateGroupID   = br.ReadInt64();
                    string stateGroupName = br.ReadShiftJIS();
                    meta.StateGroupNames.Add(stateGroupID, stateGroupName);
                    meta.StateMetadatas.Add(stateGroupID, new Dictionary <long, StateMetadata>());
                    int stateCount = br.ReadInt32();
                    for (int j = 0; j < stateCount; j++)
                    {
                        long   stateID          = br.ReadInt64();
                        string stateName        = br.ReadShiftJIS();
                        string stateEntryScript = br.ReadShiftJIS();
                        string stateExitScript  = br.ReadShiftJIS();
                        string stateWhileScript = br.ReadShiftJIS();
                        meta.StateMetadatas[stateGroupID].Add(stateID, new StateMetadata()
                        {
                            Name        = stateName,
                            EntryScript = stateEntryScript,
                            ExitScript  = stateExitScript,
                            WhileScript = stateWhileScript,
                        });
                    }
                }
                int conditionCount = br.ReadInt32();
                for (int i = 0; i < conditionCount; i++)
                {
                    long   conditionID         = br.ReadInt64();
                    string conditionName       = br.ReadShiftJIS();
                    string conditionEvaluator  = br.ReadShiftJIS();
                    string conditionPassScript = br.ReadShiftJIS();
                    meta.ConditionMetadatas.Add(conditionID, new ConditionMetadata()
                    {
                        Name       = conditionName,
                        Evaluator  = conditionEvaluator,
                        PassScript = conditionPassScript,
                    });
                }
            }
            return(meta);
        }
Пример #3
0
        private static ESDMetadata InnerReadFromXml(string xmlFileName)
        {
            var meta = new ESDMetadata();

            XmlDocument xml = new XmlDocument();

            xml.Load(xmlFileName);

            meta.ESDHash = xml.SelectSingleNode("EzStateMetadata").Attributes["Hash"].InnerText;

            foreach (XmlNode groupNode in xml.SelectNodes("EzStateMetadata/StateGroups/StateGroup"))
            {
                long   stateGroupID   = long.Parse(groupNode.Attributes["ID"].InnerText);
                string stateGroupName = groupNode.Attributes["Name"].InnerText;
                meta.StateGroupNames.Add(stateGroupID, stateGroupName);
                meta.StateMetadatas.Add(stateGroupID, new Dictionary <long, StateMetadata>());
                foreach (XmlNode stateNode in groupNode.SelectNodes("States/State"))
                {
                    long   stateID          = long.Parse(stateNode.Attributes["ID"].InnerText);
                    string stateName        = stateNode.Attributes["Name"].InnerText;
                    string stateEntryScript = stateNode.SelectSingleNode("EntryScript").InnerText;
                    string stateExitScript  = stateNode.SelectSingleNode("ExitScript").InnerText;
                    string stateWhileScript = stateNode.SelectSingleNode("WhileScript").InnerText;
                    meta.StateMetadatas[stateGroupID].Add(stateID, new StateMetadata()
                    {
                        Name        = stateName,
                        EntryScript = stateEntryScript,
                        ExitScript  = stateExitScript,
                        WhileScript = stateWhileScript,
                    });
                }
            }

            foreach (XmlNode conditionNode in xml.SelectNodes("EzStateMetadata/Conditions/Condition"))
            {
                long   conditionID         = long.Parse(conditionNode.Attributes["ID"].InnerText);
                string conditionName       = conditionNode.Attributes["Name"].InnerText;
                string conditionEvaluator  = conditionNode.SelectSingleNode("Evaluator").InnerText;
                string conditionPassScript = conditionNode.SelectSingleNode("PassScript").InnerText;
                meta.ConditionMetadatas.Add(conditionID, new ConditionMetadata()
                {
                    Name       = conditionName,
                    Evaluator  = conditionEvaluator,
                    PassScript = conditionPassScript,
                });
            }

            return(meta);
        }
Пример #4
0
        /// <summary>
        /// Generates metadata based on the in-memory ESD file.
        /// </summary>
        public static ESDMetadata Generate(ESDL esd)
        {
            var meta = new ESDMetadata();

            meta.ESDHash = esd.LastSavedHash;

            meta.StateGroupNames = esd.StateGroupNames;

            foreach (var g in esd.StateGroups.Keys)
            {
                meta.StateMetadatas.Add(g, new Dictionary <long, StateMetadata>());
                foreach (var s in esd.StateGroups[g].Keys)
                {
                    meta.StateMetadatas[g].Add(s, new StateMetadata()
                    {
                        Name        = esd.StateGroups[g][s].Name,
                        EntryScript = esd.StateGroups[g][s].EntryScript,
                        ExitScript  = esd.StateGroups[g][s].ExitScript,
                        WhileScript = esd.StateGroups[g][s].WhileScript,
                    });
                }
            }

            foreach (var g in esd.GetAllConditions())
            {
                foreach (var c in g.Value)
                {
                    meta.ConditionMetadatas.Add(c.MetaRefID, new ConditionMetadata()
                    {
                        Name       = c.Name,
                        Evaluator  = c.Evaluator,
                        PassScript = c.PassScript,
                    });
                }
            }

            return(meta);
        }
Пример #5
0
        public void ImportNamesFromOther(ESDMetadata other)
        {
            foreach (var kvp in other.StateGroupNames)
            {
                StateGroupNames[kvp.Key] = kvp.Value;
            }

            foreach (var g in other.StateMetadatas.Keys)
            {
                foreach (var s in other.StateMetadatas[g].Keys)
                {
                    StateMetadatas[g][s].Name = other.StateMetadatas[g][s].Name;
                }
            }

            var thisCondKeys = ConditionMetadatas.Keys.ToList();
            var otherValues  = other.ConditionMetadatas.Values.ToList();

            for (int i = 0; i < otherValues.Count; i++)
            {
                var matchingKey = thisCondKeys[i];
                ConditionMetadatas[matchingKey].Name = otherValues[i].Name;
            }
        }