Exemple #1
0
        public static ElderScrollsPlugin ReadXML(string sourceFolder)
        {
            var headerLocation         = Path.Combine(sourceFolder, "Header.xml");
            var xml                    = XDocument.Load(headerLocation);
            ElderScrollsPlugin outPlug = new ElderScrollsPlugin(Path.GetDirectoryName(sourceFolder), new RecordView(headerLocation));

            outPlug.FileName = xml.Element("Record").Element("FileName").Value;

            outPlug.ReadMasters();

            outPlug.Masters.Add(outPlug.FileName);

            foreach (var folder in Directory.EnumerateDirectories(sourceFolder, "*.*", SearchOption.TopDirectoryOnly))
            {
                Group newGroup = Group.CreateGroup(folder);

                newGroup.GroupAdded      += (g) => outPlug.AllGroups.Add(g);
                newGroup.RecordViewAdded += (r) => outPlug.RecordViews.Add(r);
                outPlug.TopGroups.Add(newGroup);
                outPlug.AllGroups.Add(newGroup);

                newGroup.ReadXML(folder, outPlug);
            }

            ElderScrollsPlugin.LoadedPlugins.Add(outPlug);

            return(outPlug);
        }
Exemple #2
0
        public static ElderScrollsPlugin ReadBinary(string file)
        {
            ElderScrollsPlugin outPlug = new ElderScrollsPlugin(Path.GetFileNameWithoutExtension(file), new Header());

            outPlug.FileName = Path.GetFileName(file);
            FileInfo fi = new FileInfo(file);

            outPlug.mmf = MemoryMappedFile.CreateFromFile(file, FileMode.Open, Path.GetFileNameWithoutExtension(file), fi.Length, MemoryMappedFileAccess.Read);

            using (MemoryMappedViewStream stream = outPlug.mmf.CreateViewStream(0, fi.Length, MemoryMappedFileAccess.Read))
                using (ESPReader reader = new ESPReader(stream, outPlug))
                {
                    outPlug.Header = new RecordView(reader, outPlug.mmf);

                    outPlug.Masters = new List <string>();

                    outPlug.ReadMasters();

                    outPlug.Masters.Add(outPlug.FileName);

                    Log("Beginning loading plugin " + outPlug.FileName, LogLevel.Plugin);

                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        var group = Group.CreateGroup(reader);

                        group.GroupAdded      += (g) => outPlug.AllGroups.Add(g);
                        group.RecordViewAdded += (r) => outPlug.RecordViews.Add(r);

                        group.ReadBinary(reader, outPlug.mmf);

                        var index = outPlug.TopGroups.FindIndex(g => ((TopGroup)g).RecordType.Equals(((TopGroup)group).RecordType));
                        if (index > 0)
                        {
                            group.MergeGroup(outPlug.TopGroups[index]);
                        }
                        else
                        {
                            outPlug.TopGroups.Add(group);
                            outPlug.AllGroups.Add(group);
                        }
                    }
                    Log("Finished loading plugin " + outPlug.FileName, LogLevel.Plugin);
                }

            ElderScrollsPlugin.LoadedPlugins.Add(outPlug);

            foreach (RecordView view in outPlug.RecordViews)
            {
                LoadOrderFormID loID = new LoadOrderFormID(view.FormID, outPlug);

                Dictionary <uint, List <RecordView> > typeDict;
                List <RecordView> viewList;

                //add view to collection of all views
                if (!ElderScrollsPlugin.LoadedRecordViews.TryGetValue(loID.RawValue, out viewList))
                {
                    viewList = new List <RecordView>();
                    ElderScrollsPlugin.LoadedRecordViews.Add(loID.RawValue, viewList);
                }
                viewList.Add(view);

                //add view to categorized collection of all views
                string tag = view.Tag;
                if (!ElderScrollsPlugin.RecordViewsByType.TryGetValue(tag, out typeDict))
                {
                    typeDict = new Dictionary <uint, List <RecordView> >();
                    ElderScrollsPlugin.RecordViewsByType.Add(tag, typeDict);
                }
                if (!ElderScrollsPlugin.RecordViewsByType[tag].TryGetValue(loID.RawValue, out viewList))
                {
                    viewList = new List <RecordView>();
                    ElderScrollsPlugin.RecordViewsByType[tag].Add(loID.RawValue, viewList);
                }
                viewList.Add(view);
            }
            return(outPlug);
        }