コード例 #1
0
        public MDXFile(string dbfFile, ZipHelper _ziphelper, char DirSeperator, bool ReadOnly)
        {
            this.boolReadOnly = ReadOnly;
            this.objMDXEntrys = new List <MDX>(MAX_TAGS);
            short i;

            this.strName = Path.GetDirectoryName(dbfFile) + DirSeperator + Path.GetFileNameWithoutExtension(dbfFile) + ".mdx";

            if (_ziphelper.FileExists(this.strName))
            {
                BinaryReader mdxReader = null;
                try
                {
                    byte[]   buffer;
                    GCHandle handle;

                    this.objFileStream = _ziphelper.GetReadStream(this.strName);

                    //Create a Binary Reader for the MDX file
                    mdxReader = new BinaryReader(objFileStream);
                    byte[] completeBuffer = mdxReader.ReadBytes((int)_ziphelper.GetStreamLength(this.strName, objFileStream));
                    mdxReader.Close();
                    mdxReader = new BinaryReader(new MemoryStream(completeBuffer), ASCIIEncoding.ASCII);


                    // Marshall the header into a MDXHeader structure
                    buffer         = mdxReader.ReadBytes(Marshal.SizeOf(typeof(MDXHeader)));
                    handle         = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    this.objHeader = (MDXHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(MDXHeader));
                    handle.Free();


                    //Read the Key Nodes
                    for (i = 0; i < objHeader.numberOfTagsInUse; i++)
                    {
                        int StreamStartPosition = Marshal.SizeOf(typeof(MDXHeader));
                        StreamStartPosition += (this.objHeader.lengthOfTag * i);
                        if (i < objHeader.numberOfTagsInUse)
                        {
                            MDX newMDX = new MDX(i);
                            this.objMDXEntrys.Add(newMDX);
                            newMDX.Read(mdxReader, this.objHeader.lengthOfTag, StreamStartPosition);
                        }
                        else
                        {
                            objMDXEntrys.Add(null);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    mdxReader.Close();
                }
            }
        }
コード例 #2
0
        public MDXFile(string dbfFile, ZipHelper _ziphelper, char DirSeperator, bool ReadOnly)
        {
            this.boolReadOnly = ReadOnly;
            this.objMDXEntrys = new List<MDX>(MAX_TAGS);
            short i;

            this.strName = Path.GetDirectoryName(dbfFile) + DirSeperator + Path.GetFileNameWithoutExtension(dbfFile) + ".mdx";

            if (_ziphelper.FileExists(this.strName))
            {

                BinaryReader mdxReader = null;
                try
                {
                    byte[] buffer;
                    GCHandle handle;

                    this.objFileStream = _ziphelper.GetReadStream(this.strName);

                    //Create a Binary Reader for the MDX file
                    mdxReader = new BinaryReader(objFileStream);
                    byte[] completeBuffer = mdxReader.ReadBytes((int) _ziphelper.GetStreamLength(this.strName, objFileStream));
                    mdxReader.Close();
                    mdxReader = new BinaryReader(new MemoryStream(completeBuffer), ASCIIEncoding.ASCII);


                    // Marshall the header into a MDXHeader structure
                    buffer = mdxReader.ReadBytes(Marshal.SizeOf(typeof (MDXHeader)));
                    handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    this.objHeader = (MDXHeader) Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof (MDXHeader));
                    handle.Free();


                    //Read the Key Nodes
                    for (i = 0; i < objHeader.numberOfTagsInUse; i++)
                    {
                        int StreamStartPosition = Marshal.SizeOf(typeof (MDXHeader));
                        StreamStartPosition += (this.objHeader.lengthOfTag*i);
                        if (i < objHeader.numberOfTagsInUse)
                        {
                            MDX newMDX = new MDX(i);
                            this.objMDXEntrys.Add(newMDX);
                            newMDX.Read(mdxReader, this.objHeader.lengthOfTag, StreamStartPosition);
                        }
                        else
                        {
                            objMDXEntrys.Add(null);
                        }
                    }

                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    mdxReader.Close();
                }
            }
        }