forked from 0xC0000054/pdn-photoshop-brush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLengthWriter.cs
70 lines (61 loc) · 2.2 KB
/
LengthWriter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/////////////////////////////////////////////////////////////////////////////////
//
// ABR FileType Plugin for Paint.NET
//
// This software is provided under the MIT License:
// Copyright (c) 2012-2017 Nicholas Hayes
//
// See LICENSE.txt for complete licensing and attribution information.
//
/////////////////////////////////////////////////////////////////////////////////
// Portions of this file has been adapted from:
/////////////////////////////////////////////////////////////////////////////////
//
// Photoshop PSD FileType Plugin for Paint.NET
// http://psdplugin.codeplex.com/
//
// This software is provided under the MIT License:
// Copyright (c) 2006-2007 Frank Blumenberg
// Copyright (c) 2010-2011 Tao Yue
//
// Portions of this file are provided under the BSD 3-clause License:
// Copyright (c) 2006, Jonas Beckeman
//
// See LICENSE.txt for complete licensing and attribution information.
//
/////////////////////////////////////////////////////////////////////////////////
using System;
namespace AbrFileTypePlugin
{
internal sealed class LengthWriter : IDisposable
{
private readonly long lengthFieldOffset;
private readonly long startPosition;
private BinaryReverseWriter writer;
private bool disposed;
public LengthWriter(BinaryReverseWriter writer)
{
this.writer = writer;
// we will write the correct length later, so remember
// the position
this.lengthFieldOffset = writer.BaseStream.Position;
writer.Write(0xFEEDFEED);
// remember the start position for calculation Image
// resources length
this.startPosition = writer.BaseStream.Position;
this.disposed = false;
}
public void Dispose()
{
if (!this.disposed)
{
long endPosition = this.writer.BaseStream.Position;
long length = endPosition - this.startPosition;
writer.BaseStream.Position = this.lengthFieldOffset;
writer.Write((uint)length);
writer.BaseStream.Position = endPosition;
this.disposed = true;
}
}
}
}