コード例 #1
0
ファイル: Byaml.cs プロジェクト: SeekingFunChild/Byaml_Editor
        private void SaveClick(object sender, EventArgs e)
        {
            byte[] temp = new byte[20 * 1024 * 1024];
            using (EndianBinaryWriter writer = new EndianBinaryWriter(new MemoryStream(temp)))
            {
                nodes.Clear();
                values.Clear();
                UpdateStrings(root);
                nodes.Sort(CustomStringSort);
                values.Sort(CustomStringSort);

                nodeChaches.Clear();
                int    len   = SaveTreeToFile(root, writer);
                byte[] bytes = new byte[len];
                for (int i = 0; i < len; i++)
                {
                    bytes[i] = temp[i];
                }

                if (isYaz0)
                {
                    bytes = Yaz0.encode(bytes);
                }

                File.WriteAllBytes(path, bytes);

                writer.Close();
            }
            MessageBox.Show("save successful");
        }
コード例 #2
0
ファイル: Byaml.cs プロジェクト: SeekingFunChild/Byaml_Editor
        public Byaml(string byamlFile)
        {
            nodes  = new List <string>();
            values = new List <string>();

            nodeChaches = new List <KeyValuePair <int, ShowNode> >();

            searched_nodes = new List <TreeNode>();

            byte[] bytes = File.ReadAllBytes(byamlFile);
            isYaz0 = Yaz0.IsYaz0(bytes);
            if (isYaz0)
            {
                bytes = Yaz0.decode(bytes);
            }

            var stream = new MemoryStream(bytes);
            var reader = new EndianBinaryReader(stream);

            reader.Endianness = Endianness.BigEndian;

            if (reader.ReadUInt16() != 0x4259)
            {
                throw new InvalidDataException();
            }
            if (reader.ReadUInt16() != 0x0002)
            {
                throw new InvalidDataException();
            }

            path = byamlFile;

            uint nodeOffset = reader.ReadUInt32();

            if (nodeOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            uint valuesOffset = reader.ReadUInt32();

            if (valuesOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            uint treeOffset = reader.ReadUInt32();

            if (treeOffset > reader.BaseStream.Length)
            {
                throw new InvalidDataException();
            }

            if (nodeOffset != 0)
            {
                reader.BaseStream.Seek(nodeOffset, SeekOrigin.Begin);
                nodes.AddRange(new ByamlNode.StringList(reader).Strings);
            }
            if (valuesOffset != 0)
            {
                reader.BaseStream.Seek(valuesOffset, SeekOrigin.Begin);
                values.AddRange(new ByamlNode.StringList(reader).Strings);
            }

            ByamlNodeType rootType;

            reader.BaseStream.Seek(treeOffset, SeekOrigin.Begin);
            rootType = (ByamlNodeType)reader.ReadByte();
            reader.BaseStream.Seek(-1, SeekOrigin.Current);
            if (rootType == ByamlNodeType.UnamedNode)
            {
                tree = new ByamlNode.UnamedNode(reader);
            }
            else
            {
                tree = new ByamlNode.NamedNode(reader);
            }

            root      = new ShowNode("root");
            root.Type = tree.Type;

            reader.Close();
        }