Example #1
0
 public void NestedReferenceTest()
 {
     SectionEntry root = GenerateTestTree();
     Entry n2 = root.Entries[1];
     // test the VNAME of n2, which points to the VNAME of n1 which also contains a reference
     Assert.AreEqual("First Node: A Value That Is A Name", FormattedReader.ParseValueRefs(n2, n2.FriendlyName));
 }
        public void ItemSectionRoundTrip()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            var writeID =
                wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <OHLCV> >();
            ISectionFormatter f = new ItemSectionFormatter();

            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            f.Read(rc);
            rc.Description.Should().Not.Be.Null();
            var id = rc.Description.ItemDescription;

            id.ItemTypeName.Should().Be(typeof(Event <OHLCV>).GetLanguageName());
            id.ItemSize.Should().Be(wc.Description.ItemDescription.ItemSize);
            id.Fields.Select(ff => ff.Name).Should().Have.SameValuesAs("Time", "Open", "High", "Low", "Close", "Volume");
            id.Fields.Select(ff => ff.Index).Should().Have.SameValuesAs(0, 1, 2, 3, 4, 5);
            id.Fields.Select(ff => ff.FieldType).Should().Have.SameValuesAs(FieldType.Int64, FieldType.Double, FieldType.Double, FieldType.Double, FieldType.Double);
            id.Fields.Select(ff => ff.Offset).Should().Have.SameValuesAs(writeID.Fields.Select(ff => ff.Offset));

            ms.Position.Should().Be(ms.Length); // very important, all bytes must have been read
        }
Example #3
0
        public void TimeSectionRoundTrip()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >();
            wc.Description.Timescale       = Time.Scale;
            ISectionFormatter f = new TimeSectionFormatter();

            f.Write(wc);

            ms.Position = 0;
            ms.Length.Should().Be(24); // epoch(8) ticksperday(8) fieldcount(4) + timefieldoffset(4) = 24

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            rc.Description.ItemDescription = wc.Description.ItemDescription; // this makes the test a bit weaker, but we need some item description here
            f.Read(rc);
            rc.Description.Should().Not.Be.Null();
            rc.Description.Timescale.HasValue.Should().Be.True();
        }
Example #4
0
        public void ReadHeader()
        {
            FileIO          fio = new FileIO(this.stream);
            FormattedReader r   = new FormattedReader(fio);
            var             rc  = HeaderManager.Instance.ReadHeader(r);

            this.description   = rc.Description;
            this.itemAreaStart = rc.ItemAreaStart;
            this.itemAreaEnd   = rc.ItemAreaEnd;
            if (this.stream.Position != this.itemAreaStart)
            {
                throw new InternalErrorException("file position is not set to begin of item area after reading header.");
            }
            if (this.Description != null && this.Description.Timescale.HasValue)
            {
                var fileTimeScale = this.Description.Timescale.Value;
                if (!fileTimeScale.Equals(Time.Scale))
                {
                    switch (Time.ScaleCollisionBehavior)
                    {
                    case ScaleCollisionBehavior.ThrowException:
                        throw new TimescaleException();

                    case ScaleCollisionBehavior.Ignore:
                        break;

                    case ScaleCollisionBehavior.UseNewScale:
                        Time.Scale = fileTimeScale;
                        break;
                    }
                }
            }
        }
Example #5
0
        public void NameValueSectionRoundTrip3EntriesTest()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            ISectionFormatter f = new NameValueSectionFormatter();

            wc.Description            = new TeaFileDescription();
            wc.Description.NameValues = new NameValueCollection();
            wc.Description.NameValues.Add(new NameValue("someName", 1.23));
            wc.Description.NameValues.Add(new NameValue("someName2", "second value"));
            wc.Description.NameValues.Add(new NameValue("someName3", 333));
            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            f.Read(rc);

            rc.Description.Should().Not.Be.Null();
            rc.Description.NameValues.Should().Not.Be.Null();
            rc.Description.NameValues.Should().Have.Count.EqualTo(3);
            rc.Description.NameValues.Select(nv => nv.Name).Should().Have.SameSequenceAs("someName", "someName2", "someName3");
            rc.Description.NameValues.Select(nv => nv.GetValue <object>()).Should().Have.SameSequenceAs(1.23, "second value", 333);
        }
Example #6
0
        public void NameValueSectionRoundTrip1EntryTest()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            ISectionFormatter f = new NameValueSectionFormatter();

            wc.Description            = new TeaFileDescription();
            wc.Description.NameValues = new NameValueCollection();
            wc.Description.NameValues.Add(new NameValue("someName", 1.23));
            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            f.Read(rc);

            rc.Description.Should().Not.Be.Null();
            rc.Description.NameValues.Should().Not.Be.Null();
            rc.Description.NameValues.Should().Have.Count.EqualTo(1);
            rc.Description.NameValues.First().Name.Should().Be("someName");
            rc.Description.NameValues.First().GetValue <double>().Should().Be(1.23);
        }
Example #7
0
        public void FirstTimeFieldIsAutomaticallyEventTime()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>();
            wc.Description.Timescale       = Time.Scale;
            ISectionFormatter f = new TimeSectionFormatter();

            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            rc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>();

            f.Read(rc);

            var fields = rc.Description.ItemDescription.Fields;

            fields[0].IsEventTime.Should().Be.True();
            fields[1].IsEventTime.Should().Be.False();
        }
Example #8
0
        public void EventTimeAttributeRoundTrip()
        {
            Time.Scale = Timescale.Net;

            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >();
            wc.Description.Timescale       = Time.Scale;
            ISectionFormatter f = new TimeSectionFormatter();

            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            rc.Description.ItemDescription = wc.Description.ItemDescription;
            rc.Description.ItemDescription.Fields.ForEach(ff => ff.IsEventTime = ff.IsTime = false); // reset flags

            f.Read(rc);

            rc.Description.ItemDescription.Fields.Count(ff => ff.IsTime).Should().Be(1);
            rc.Description.ItemDescription.Fields.Count(ff => ff.IsEventTime).Should().Be(1);
            rc.Description.Timescale.Value.Epoch.Should().Be(0);
            rc.Description.Timescale.Value.TicksPerDay.Should().Be(TimeSpan.TicksPerDay);
        }
Example #9
0
        public void TimeSectionValuesRoundTrip()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >();
            Time.Scale = Timescale.FromEpoch(33, 77);
            wc.Description.Timescale = Time.Scale;
            ISectionFormatter f = new TimeSectionFormatter();

            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            rc.Description.ItemDescription = wc.Description.ItemDescription;

            f.Read(rc);
            rc.Description.Timescale.Value.Epoch.Should().Be(33);
            rc.Description.Timescale.Value.TicksPerDay.Should().Be(77);

            Executing.This(() => f.Read(rc)).Should().Throw <EndOfStreamException>();
        }
Example #10
0
        public void RecursiveSectionTest()
        {
            var          reader = new FormattedReader(new MemoryStream(Encoding.UTF8.GetBytes(RECURSIVE_FORMAT)));
            SectionEntry file   = reader.ReadFileFromString(RECURSIVE_FILE);
            var          second = (SectionEntry)((SectionEntry)((SectionEntry)((SectionEntry)((SectionEntry)file.Entries[0]).Entries[0]).Entries[2]).Entries[3]).Entries[3];

            Assert.AreEqual("Province", second.Entries[0].FriendlyName); //test that the second "from" was properly detected (by checking a value inside it)
            Assert.AreEqual("From", second.Entries[3].FriendlyName);     //test that the third "from" was properly detected
        }
Example #11
0
        private void ReadFile(string formatPath, string filePath)
        {
            FileReadingDialog dialog = new FileReadingDialog();
            FormattedReader   reader = new FormattedReader(formatPath);

            dialog.ReadingDone += Dialog_ReadingDone;
            dialog.ReadFile(reader, filePath);
            dialog.Show(this);
            dialog.Focus();
        }
Example #12
0
        public override object GetValue(Aga.Controls.Tree.TreeNodeAdv node)
        {
            ValueEntry ent = node.Tag as ValueEntry;

            if (ent == null)
            {
                return("");//if this is not a value entry, value is not relevant
            }
            Entry linked = FormattedReader.ParseRef(ent, ent.Link);

            return(ent.Value + (ent.Link != null && linked != null ? " (" + FormattedReader.ParseValueRefs(linked, linked.FriendlyName) + ")" : ""));
        }
Example #13
0
        public void BasicReferenceTest()
        {
            SectionEntry root = GenerateTestTree();

            SectionEntry n1 = (SectionEntry)root.Entries[0];
            Entry n2 = root.Entries[1];
            Assert.AreEqual("First Node: A Value That Is A Name", FormattedReader.ParseValueRefs(n1, n1.FriendlyName)); //test the VNAME of n1 (relative value ref)
            Entry n1_1 = n1.Entries[0];
            Assert.AreEqual(n2, FormattedReader.ParseRef(n1_1, n1_1.Link)); //test the link of n1_1 (absolute ref)
            Entry n1_2 = n1.Entries[1];
            Assert.AreEqual(n1, FormattedReader.ParseRef(n1_2, n1_2.Link)); //test the link of n1_2 (relative ref that goes up the tree)
        }
Example #14
0
        private void btn_load_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.ShowDialog();
            ofd.Filter = "Neuron State Files (*.neuron)|*.neuron";
            if (ofd.FileName != null)
            {
                using (FormattedReader fr = new FormattedReader(ofd.FileName))
                {
                    var psf = fr.Read <ProgramStateFile>();

                    if (psf.version > 0)
                    {
                        MessageBox.Show("Version too high");
                        return;
                    }

                    // Create nodes
                    foreach (var node in psf.nodes)
                    {
                        var box = CreateLayer(node.name.Contents, node.size, node.type);
                        box.MainControl.Location = new Point(node.x, node.y);
                    }

                    // Link up
                    foreach (var node in psf.nodes)
                    {
                        foreach (var link in node.links)
                        {
                            var wm = LinkNodes(vectors[node.name.Contents], vectors[link.nodename.Contents]);
                            wm.weights = new Matrix(link.matrix.Matrix);
                        }
                    }

                    // Pull in configurations
                    foreach (var config in psf.configurations)
                    {
                        AddToConfiguration(config.Contents);
                    }

                    foreach (var config in psf.trainings)
                    {
                        AddToTraining(config.Contents);
                    }

                    foreach (var config in psf.crossValidations)
                    {
                        AddToCrossValidation(config.Contents);
                    }
                }
            }
        }
Example #15
0
        public void GotoLink(string path, TreeNodeAdv start = null)
        {
            TreeNodeAdv node = start != null ? start : Tree.Root;
            Entry       startEnt;

            if (node.Tag == null) //the root node doesn't have a tag
            {                     //create a temporary wrapper SectionEntry
                startEnt = RootSection;
            }
            else
            {
                startEnt = (Entry)node.Tag;
            }
            node = Tree.Root;
            Goto(FormattedReader.ParseRefPath(startEnt, path));
        }
Example #16
0
        public override object GetValue(TreeNodeAdv node)
        {
            if (node.Tag == null)
            {//this is the button for adding new entries
                return("+++Add New+++");
            }
            Entry ent = node.Tag as Entry;

            if (ent == null)
            {
                throw new ArgumentException("EntryNameNodeText can only be used with entries");
            }
            string res = FormattedReader.ParseValueRefs(ent, ent.FriendlyName);

            return(res != null ? res : ent.InternalName);
        }
Example #17
0
 private static UserdataFileFormat ReadUserData()
 {
     UserdataFileFormat udf;
     if (File.Exists("sites.info"))
     {
         using (FormattedReader fr = new FormattedReader("sites.info"))
         {
             udf = fr.Read<UserdataFileFormat>();
         }
     }
     else
     {
         udf = UserdataFileFormat.Init();
     }
     return udf;
 }
Example #18
0
        private static UserdataFileFormat ReadUserData()
        {
            UserdataFileFormat udf;

            if (File.Exists("sites.info"))
            {
                using (FormattedReader fr = new FormattedReader("sites.info"))
                {
                    udf = fr.Read <UserdataFileFormat>();
                }
            }
            else
            {
                udf = UserdataFileFormat.Init();
            }
            return(udf);
        }
Example #19
0
        public void FormattedReaderTest()
        {
            FormattedReader reader = new FormattedReader(TestsReference.FORMAT_PATH);
            SectionEntry    root   = reader.ReadFile(TestsReference.MIN_TEST_PATH);
            SectionEntry    player = new SectionEntry("player", "Player", null);

            player.Root   = root;
            player.Parent = root;
            player.Entries.Add(new ValueEntry("id", "Id", "number", "665369", null, player, root));
            player.Entries.Add(new ValueEntry("type", "Type", "number", "66", null, player, root));
            Assert.IsTrue(player.Equals(root.Entries[2]));
            Assert.AreEqual(12, root.Entries.Count);

            Entry  start   = root.Entries[0];
            string refpath = "..";

            Assert.AreEqual(start.Parent, FormattedReader.ParseRef(start, refpath));
        }
Example #20
0
        public PAKFile(string filename)
        {
            FormattedReader pak = new FormattedReader(filename);

            while (true)
            {
                var sig = pak.Read <Signature>();

                if (ArrayUtils.AreEqual(sig.signature, stringFileHeader2))
                {
                    var header = pak.Read <File>();

                    if (version == 0)
                    {
                        version = detectVersion(header.data, header.uncompressedSize, header.crc, header.compressionMethod);
                        if (version == 0)
                        {
                            throw new Exception("Unknown AION version!");
                        }
                    }
                    files[header.Filename.ToLower()] = header;

                    Console.WriteLine("File: {0} Compression: {1}", header.Filename, header.compressionMethod);
                }
                else if (ArrayUtils.AreEqual(sig.signature, stringCentralDir2))
                {
                    var header = pak.Read <Dir>();

                    Console.WriteLine("Dir: {0}", header.Filename);
                }
                else if (ArrayUtils.AreEqual(sig.signature, stringEndArchive2))
                {
                    var header = pak.Read <End>();

                    Console.WriteLine("End disknumber {0}", header.diskNumber);

                    break;
                }
                else
                {
                    throw new Exception("bad sig");
                }
            }
        }
Example #21
0
        public void Load(string filename)
        {
            using (FormattedReader fr = new FormattedReader(filename)) {
                var   gff   = fr.Read <GraphFileFormat>();
                Box[] boxes = ArrayUtils.ConvertAll(gff.vertices, x =>
                {
                    var box = AddBox(Color.FromArgb(x.color), x.data);
                    box.MainControl.Location = new Point(x.x, x.y);
                    return(box);
                });

                for (int i = 0; i < boxes.Length; i++)
                {
                    foreach (int edge in gff.vertices[i].edges)
                    {
                        boxes[i].LinkTo(boxes[edge], gff.vertices[i].linkdatas[edge]);
                    }
                }
            }
        }
        public void ContentSectionFormatterRoundTrip()
        {
            const string testValue = "Météo pour Paris, France. @€";

            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ContentDescription = testValue;
            ISectionFormatter f = new ContentSectionFormatter();

            f.Write(wc);
            ms.Position = 0;
            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            f.Read(rc);
            rc.Description.Should().Not.Be.Null();
            rc.Description.ContentDescription.Should().Be(testValue);
        }
Example #23
0
        public void TimeSectionRoundTripFieldIsNotInItemDescriptionError()
        {
            var ms  = new MemoryStream();
            var fio = new FileIO(ms);
            var fw  = new FormattedWriter(fio);
            var wc  = new WriteContext(fw);

            wc.Description = new TeaFileDescription();
            wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >();
            wc.Description.Timescale       = Time.Scale;
            ISectionFormatter f = new TimeSectionFormatter();

            f.Write(wc);

            ms.Position = 0;

            var fr = new FormattedReader(fio);
            var rc = new ReadContext(fr);

            rc.Description.Should().Not.Be.Null();
            rc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>();

            Executing.This(() => f.Read(rc)).Should().Throw <FileFormatException>();
        }
Example #24
0
        private void btn_load_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            ofd.Filter = "Neuron State Files (*.neuron)|*.neuron";
            if (ofd.FileName != null)
            {
                using (FormattedReader fr = new FormattedReader(ofd.FileName))
                {
                    var psf = fr.Read<ProgramStateFile>();

                    if (psf.version > 0)
                    {
                        MessageBox.Show("Version too high");
                        return;
                    }

                    // Create nodes
                    foreach (var node in psf.nodes)
                    {
                        var box = CreateLayer(node.name.Contents, node.size, node.type);
                        box.MainControl.Location = new Point(node.x, node.y);
                    }

                    // Link up
                    foreach (var node in psf.nodes)
                    {
                        foreach (var link in node.links)
                        {
                            var wm = LinkNodes(vectors[node.name.Contents], vectors[link.nodename.Contents]);
                            wm.weights = new Matrix(link.matrix.Matrix);
                        }
                    }

                    // Pull in configurations
                    foreach (var config in psf.configurations)
                    {
                        AddToConfiguration(config.Contents);
                    }

                    foreach (var config in psf.trainings)
                    {
                        AddToTraining(config.Contents);
                    }

                    foreach (var config in psf.crossValidations)
                    {
                        AddToCrossValidation(config.Contents);
                    }
                }
            }
        }
Example #25
0
        public static void GenerateSectionNode(XmlDocument doc, XmlNode parent, string scope)
        {
            bool           foundNumber = false;
            bool           foundBlank  = false;
            bool           foundDate   = false;
            List <XmlNode> foundNames  = new List <XmlNode>();

            foreach (var childPair in FormatUtil.ListEntriesWithIndexes(scope))
            {
                XmlAttribute multiple = null;
                double       n;
                if (double.TryParse(childPair.Value, out n))
                {
                    if (foundNumber)
                    {
                        continue;
                    }
                    else
                    {
                        multiple       = doc.CreateAttribute("multiple");
                        multiple.Value = "number";
                        foundNumber    = true;
                    }
                }
                else
                {
                    if (childPair.Value == "")
                    {
                        if (foundBlank)
                        {
                            continue;
                        }
                        else
                        {
                            multiple       = doc.CreateAttribute("multiple");
                            multiple.Value = "blank";
                            foundBlank     = true;
                        }
                    }
                    else if (childPair.Value.Count(c => c == '.') == 2)
                    {
                        if (foundDate)
                        {
                            continue;
                        }
                        else
                        {
                            multiple       = doc.CreateAttribute("multiple");
                            multiple.Value = "date";
                            foundDate      = true;
                        }
                    }
                    else
                    {
                        XmlNode found = foundNames.Find(elem => elem.LocalName == childPair.Value);
                        if (found != null)
                        {
                            multiple       = doc.CreateAttribute("multiple");
                            multiple.Value = "same";
                            found.Attributes.Append(multiple);
                            continue;
                        }
                    }
                }

                string       type = FormattedReader.DetectType(scope, childPair);
                string       name;
                XmlAttribute grouperName = null;
                if (multiple != null)
                {
                    grouperName       = doc.CreateAttribute("grouper-name");
                    grouperName.Value = "";
                    switch (multiple.Value)
                    {
                    case "number":
                        name = "NUMBER";
                        break;

                    case "blank":
                        name = "BLANK";
                        break;

                    case "date":
                        name = "DATE";
                        break;

                    default:
                        name = childPair.Value;
                        grouperName.Value = Util.UppercaseWords("(" + childPair.Value + "s)");
                        break;
                    }
                }
                else
                {
                    name = childPair.Value;
                }

                XmlNode      node = doc.CreateElement(name);
                XmlAttribute natt = doc.CreateAttribute("name");
                natt.Value = Util.UppercaseWords(name.Replace('_', ' '));
                node.Attributes.Append(natt);
                if (multiple != null)
                {
                    node.Attributes.Append(multiple);
                    node.Attributes.Append(grouperName);
                }
                parent.AppendChild(node);
                if (type == "section")
                {
                    GenerateSectionNode(doc, node, FormatUtil.ExtractDelimited(scope, childPair.Value, childPair.Key));
                }
                else
                {
                    XmlAttribute tatt = doc.CreateAttribute("type");
                    tatt.Value = type;
                    node.Attributes.Append(tatt);
                }
                foundNames.Add(node);
            }
        }
Example #26
0
        public PAKFile(string filename)
        {
            FormattedReader pak = new FormattedReader(filename);

            while (true) {
                var sig = pak.Read<Signature>();

                if (ArrayUtils.AreEqual(sig.signature, stringFileHeader2)) {
                    var header = pak.Read<File>();

                    if (version == 0) {
                        version = detectVersion(header.data, header.uncompressedSize, header.crc, header.compressionMethod);
                        if (version == 0) {
                            throw new Exception("Unknown AION version!");
                        }
                    }
                    files[header.Filename.ToLower()] = header;

                    Console.WriteLine("File: {0} Compression: {1}", header.Filename, header.compressionMethod);

                } else if (ArrayUtils.AreEqual(sig.signature, stringCentralDir2)) {
                    var header = pak.Read<Dir>();

                    Console.WriteLine("Dir: {0}", header.Filename);

                } else if (ArrayUtils.AreEqual(sig.signature, stringEndArchive2)) {
                    var header = pak.Read<End>();

                    Console.WriteLine("End disknumber {0}", header.diskNumber);

                    break;
                } else {
                    throw new Exception("bad sig");
                }
            }
        }
Example #27
0
        public bool Matches(Entry entry)
        {
            if (Type == SearchType.Section && entry is ValueEntry)
            {
                return(false);
            }
            if (Type == SearchType.Value && entry is SectionEntry)
            {
                return(false);
            }
            if (!string.IsNullOrEmpty(Identifier) && (entry.InternalName == null || !entry.InternalName.Contains(Identifier)))
            {
                return(false);
            }
            if (entry is ValueEntry)
            {
                if (!string.IsNullOrEmpty(Value) && !((ValueEntry)entry).Value.Contains(Value))
                {
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(FriendlyName) && (entry.FriendlyName == null || !(FormattedReader.ParseValueRefs(entry, entry.FriendlyName)).Contains(FriendlyName)))
            {
                return(false);
            }

            return(true);
        }
Example #28
0
        private void btn_loadtiles_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            if (string.IsNullOrEmpty(ofd.FileName))
            {
                return;
            }
            string basename = Path.Combine(Path.GetDirectoryName(ofd.FileName), Path.GetFileNameWithoutExtension(ofd.FileName));
            string basictilesname = basename + ".basictiles";
            string tilesname = basename + ".tiles";
            string pngname = basename + ".png";
            if (!File.Exists(basictilesname) || !File.Exists(tilesname))
            {
                return;
            }

            using (Bitmap bmp = new Bitmap(pngname))
            {
                using (FormattedReader tiles = new FormattedReader(tilesname))
                using (FormattedReader basictiles = new FormattedReader(basictilesname))
                {
                    var btff = basictiles.Read<BasicTilesFileFormat>();
                    var simpletiles = btff.tiles.Select(x => new SimpleTile(x, bmp)).ToArray();
                    //foreach (var st in simpletiles)
                    //{
                    //    AddBasicTile(st);
                    //}

                    var tff = tiles.Read<TilesFileFormat>();
                    foreach (var tile in tff.tiles)
                    {
                        if (tile.type == TileType.SIMPLE)
                        {
                            AddSimpleTile(simpletiles[tile.simp[0].basictile]);
                        }
                        else if (tile.type == TileType.AUTOTILE12)
                        {
                            AutoTile12 at = new AutoTile12(simpletiles, tile.auto[0].basictiles);
                            AddAutotile12(at, at);
                        }
                        else if (tile.type == TileType.AUTOTILE94)
                        {
                            AutoTile94 at = new AutoTile94(simpletiles, tile.auto[0].basictiles);
                            AddAutotile94(at, at);
                        }
                    }
                }
            }
        }
Example #29
0
 internal void ReadFile(FormattedReader reader, string path)
 {
     this.reader = reader;
     this.path   = path;
     bworker.RunWorkerAsync();
 }