• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgFileHeaderWriterBase.cs
1
using CSUtilities.Converters;
2
using CSUtilities.Text;
3
using System;
4
using System.IO;
5
using System.Text;
6

7
namespace ACadSharp.IO.DWG
8
{
9
        internal abstract class DwgFileHeaderWriterBase : IDwgFileHeaderWriter
10
        {
11
                public abstract int HandleSectionOffset { get; }
12

13
                protected abstract int _fileHeaderSize { get; }
14

15
                protected DwgFileHeader _fileHeader { get; }
×
16

17
                protected ACadVersion _version;
18

19
                protected Encoding _encoding;
20

21
                protected Stream _stream;
22

23
                protected CadDocument _document;
24

25
                public DwgFileHeaderWriterBase(Stream stream, Encoding encoding, CadDocument model)
×
26
                {
×
27
                        if (!stream.CanSeek || !stream.CanWrite)
×
28
                        {
×
29
                                throw new ArgumentException();
×
30
                        }
31

32
                        this._document = model;
×
33
                        this._stream = stream;
×
34
                        this._version = model.Header.Version;
×
35
                        this._encoding = encoding;
×
36
                }
×
37

38
                public abstract void AddSection(string name, MemoryStream stream, bool isCompressed, int decompsize = 0x7400);
39

40
                public abstract void WriteFile();
41

42
                protected ushort getFileCodePage()
43
                {
×
44
                        ushort codePage = (ushort)CadUtils.GetCodeIndex(CadUtils.GetCodePage(_document.Header.CodePage));
×
45
                        if (codePage < 1)
×
46
                        {
×
47
                                return 30;
×
48
                        }
49
                        else
50
                        {
×
51
                                return codePage;
×
52
                        }
53
                }
×
54

55
                protected void applyMask(byte[] buffer, int offset, int length)
56
                {
×
57
                        byte[] bytes = LittleEndianConverter.Instance.GetBytes(0x4164536B ^ (int)this._stream.Position);
×
58
                        int diff = offset + length;
×
59
                        while (offset < diff)
×
60
                        {
×
61
                                for (int i = 0; i < 4; i++)
×
62
                                {
×
63
                                        buffer[offset + i] ^= bytes[i];
×
64
                                }
×
65

66
                                offset += 4;
×
67
                        }
×
68
                }
×
69

70
                protected bool checkEmptyBytes(byte[] buffer, ulong offset, ulong spearBytes)
71
                {
×
72
                        bool result = true;
×
73
                        ulong num = offset + spearBytes;
×
74

75
                        for (ulong i = offset; i < num; i++)
×
76
                        {
×
77
                                if (buffer[i] != 0)
×
78
                                {
×
79
                                        result = false;
×
80
                                        break;
×
81
                                }
82
                        }
×
83

84
                        return result;
×
85
                }
×
86

87
                protected void writeMagicNumber()
88
                {
×
89
                        for (int i = 0; i < (int)(this._stream.Position % 0x20); i++)
×
90
                        {
×
91
                                this._stream.WriteByte(DwgCheckSumCalculator.MagicSequence[i]);
×
92
                        }
×
93
                }
×
94

95
                protected void applyMagicSequence(MemoryStream stream)
96
                {
×
97
                        byte[] buffer = stream.GetBuffer();
×
98
                        for (int i = 0; i < (int)stream.Length; i++)
×
99
                        {
×
100
                                buffer[i] ^= DwgCheckSumCalculator.MagicSequence[i];
×
101
                        }
×
102
                }
×
103
        }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc