Ejemplo n.º 1
0
        public static DwgObjectCache Parse(BitReader reader, DwgVersionId version)
        {
            var objectCache  = new DwgObjectCache(version);
            var lastHandle   = 0;
            var lastLocation = 0;

            reader.StartCrcCheck();
            var sectionSize = reader.ReadShortBigEndian();

            while (sectionSize != 2)
            {
                var sectionStart = reader.Offset;
                var sectionEnd   = sectionStart + sectionSize - 2;
                while (reader.Offset < sectionEnd)
                {
                    // read data
                    var handleOffset   = reader.Read_MC(allowNegation: false);
                    var locationOffset = reader.Read_MC();
                    var handle         = lastHandle + handleOffset;
                    var location       = lastLocation + locationOffset;
                    objectCache._handleToOffset.Add(handle, location);
                    lastHandle   = handle;
                    lastLocation = location;
                }

                reader.ValidateCrc(initialValue: DwgHeaderVariables.InitialCrcValue, readCrcAsMsb: true);
                reader.StartCrcCheck();
                sectionSize = reader.ReadShortBigEndian();
            }

            reader.ValidateCrc(initialValue: DwgHeaderVariables.InitialCrcValue, readCrcAsMsb: true);
            return(objectCache);
        }
Ejemplo n.º 2
0
        internal static DwgHeaderVariables Parse(BitReader reader, DwgVersionId version)
        {
            var header = new DwgHeaderVariables();

            reader.ValidateSentinel(StartSentinel);
            reader.StartCrcCheck();
            var size        = reader.Read_RL();
            var startOffset = reader.Offset;

            header.ReadVariables(reader, version);
            reader.AlignToByte();
            var unreadByteCount = Math.Max(startOffset + size - reader.Offset, 0);
            var unreadBytes     = reader.ReadBytes(unreadByteCount);

            reader.ValidateCrc(initialValue: InitialCrcValue);
            reader.ValidateSentinel(EndSentinel);
            return(header);
        }
Ejemplo n.º 3
0
        internal static IList <DwgClassDefinition> Parse(BitReader reader, DwgVersionId version)
        {
            reader.ValidateSentinel(StartSentinel);
            reader.StartCrcCheck();
            var sectionSize     = reader.Read_RL();
            var dataStartOffset = reader.Offset;
            var dataEndOffset   = dataStartOffset + sectionSize;
            var classes         = new List <DwgClassDefinition>();

            while (reader.Offset < dataEndOffset - 1) // may be in the middle of a byte
            {
                classes.Add(DwgClassDefinition.Parse(reader));
            }

            reader.ValidateCrc(initialValue: DwgHeaderVariables.InitialCrcValue);
            reader.ValidateSentinel(EndSentinel);
            return(classes);
        }
Ejemplo n.º 4
0
        internal static DwgFileHeader Parse(BitReader reader)
        {
            reader.StartCrcCheck();
            var versionString = reader.ReadStringAscii(6);
            var version       = DwgVersionIdExtensions.VersionIdFromString(versionString);
            var unknown1      = reader.ReadBytes(6);
            var maintVer      = 0;

            if (version == DwgVersionId.R14)
            {
                maintVer = unknown1[5];
            }

            var marker = reader.ReadByte();

            if (marker != 1)
            {
                throw new DwgReadException("Expected value of 1 at offset 13.");
            }

            var imagePointer = reader.ReadInt();
            var unknown2     = reader.ReadBytes(2);
            var codePage     = reader.ReadShort();

            var header = new DwgFileHeader(version, maintVer, imagePointer, codePage);

            var recordLocatorCount = reader.ReadInt();

            for (int i = 0; i < recordLocatorCount; i++)
            {
                var locator = DwgSectionLocator.Parse(reader);
                switch (i)
                {
                case 0:
                    header.HeaderVariablesLocator = locator;
                    break;

                case 1:
                    header.ClassSectionLocator = locator;
                    break;

                case 2:
                    header.ObjectMapLocator = locator;
                    break;

                case 3:
                    header.UnknownSection_R13C3AndLaterLocator = locator;
                    break;

                case 4:
                    header.UnknownSection_PaddingLocator = locator;
                    break;
                }
            }

            ushort crcXorValue;

            switch (recordLocatorCount)
            {
            case 0:
            case 1:
            case 2:
                crcXorValue = 0;
                break;

            case 3:
                crcXorValue = 0xAD98;
                break;

            case 4:
                crcXorValue = 0x8101;
                break;

            case 5:
                crcXorValue = 0x3CC4;
                break;

            case 6:
                crcXorValue = 0x8461;
                break;

            default:
                throw new DwgReadException("Unsupported record locator count.");
            }

            reader.ValidateCrc(xorValue: crcXorValue);
            reader.ValidateSentinel(HeaderSentinel);

            return(header);
        }