コード例 #1
0
        public bool Process(Record p)
        {
            FalloutSnip.Data.RecordsRecord rr = ProcessBase(p);

            // int srIdx = 0;
            var groups = from psr in p.SubRecords
                         group psr by psr.Name into g
                         select new { Name = g.Key, Records = g.ToArray() };

            int lastIndex = 0;
            Dictionary<string, FalloutSnip.Data.Subrecord> dict = new Dictionary<string, FalloutSnip.Data.Subrecord>();
            foreach (var kvp in groups)
            {
                if (IsCanceled) return false;

                FalloutSnip.Data.Subrecord sr = rr.Subrecords.FirstOrDefault(x => x.name == kvp.Name);
                if (sr == null)
                {
                    sr = new FalloutSnip.Data.Subrecord();
                    sr.name = sr.desc = kvp.Name;
                    sr.optional = 1;
                    if (lastIndex + 1 <= rr.Items.Count)
                    {
                        rr.Items.Insert(++lastIndex, sr);
                    }
                    else
                    {
                        rr.Items.Add(sr);
                    }
                }
                else
                {
                    lastIndex = rr.Items.IndexOf(sr, lastIndex);
                    if (lastIndex < 0)  // out of order
                        lastIndex = rr.Items.IndexOf(sr);
                }
                int n = kvp.Records.Length;
                if (n > 0)
                {
                    if (sr.repeat == 0 && n > 1)
                        sr.optional = sr.repeat = 1;
                    int idx1 = p.SubRecords.IndexOf(kvp.Records[0]);
                    int idx2 = idx1;
                    for (int i = 1; i < n; ++i, idx1 = idx2)
                    {
                        idx2 = p.SubRecords.IndexOf(kvp.Records[i]);
                        int diff = (idx2 - idx1);
                        if (diff > sr.repeat)
                        {
                            if (diff < 10)
                            {
                                sr.optional = sr.repeat = diff;
                            }
                            else
                            {
                                sr.optional = sr.repeat;
                            }
                        }
                    }
                }
                foreach (var subrec in kvp.Records)
                {
                    if (IsCanceled) break;
                    Process(sr, subrec);
                }
            }
            return true;
        }
コード例 #2
0
        public void ConfigureRecords(IEnumerable<Record> records)
        {
            var recs = records.Select(rec => rec.GetStructure()).Distinct();
            this.rec = (recs.Count() == 1) ? recs.FirstOrDefault() : null;
            if (this.rec == null)
            {
                this.filterTree.Roots = null;
            }
            else
            {
                //this.records = records;

                var srs = (from sr in this.rec.subrecords
                           let children = sr.elements.Select(se => new BatchElement() { Name = se.name, Parent = null, Record = se, Type = BatchCondElementType.Set, Checked = false }).ToList()
                           select new BatchSubrecord() { Name = string.Format("{0}: {1}", sr.name, sr.desc), Record = sr, Children = children, Checked = false, }).ToList();

                // Construct specialized editors for FormID and related headers
            #if false
                {
                    var elems = new List<FalloutSnip.Data.SubrecordElement>
                    {
                        new FalloutSnip.Data.SubrecordElement{name = "FormID", desc = "Form ID", hexview = true, type = "uint"},
                        new FalloutSnip.Data.SubrecordElement{name = "Flags1", desc = "Flags 1", hexview = true, type = "uint"},
                        new FalloutSnip.Data.SubrecordElement{name = "Flags2", desc = "Flags 2", hexview = true, type = "uint"},
                        new FalloutSnip.Data.SubrecordElement{name = "Flags3", desc = "Flags 3", hexview = true, type = "uint"},
                    };
                    var frmHdr = new FalloutSnip.Data.Subrecord { name = "Header", desc = "Record Header", Elements = elems };
                    var hdr = new SubrecordStructure(frmHdr);
                    var hdrElems = hdr.elements.Select(se =>
                        new BatchElement { Name = se.name, Parent = null, Record = se, Type = BatchCondElementType.Set, Checked = false }
                        ).ToList();
                    srs.Insert(0, new BatchSubrecord
                    {
                        Name = string.Format("{0}: {1}", hdr.name, hdr.desc),
                        Record = hdr,
                        Children = hdrElems,
                        Checked = false,
                    });
                }
            #endif

                // fix parents after assignments
                foreach (var sr in srs)
                {
                    foreach (var se in sr.Children)
                    {
                        se.Parent = sr;
                    }
                }

                this.filterTree.Roots = srs;
            }
        }