aboutsummaryrefslogtreecommitdiff
path: root/src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs')
-rw-r--r--src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs b/src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs
new file mode 100644
index 00000000..82e8fb46
--- /dev/null
+++ b/src/dtf/WixToolset.Dtf.WindowsInstaller/RecordStream.cs
@@ -0,0 +1,92 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Dtf.WindowsInstaller
4{
5 using System;
6 using System.IO;
7
8 internal class RecordStream : Stream
9 {
10 private Record record;
11 private int field;
12 private long position;
13
14 internal RecordStream(Record record, int field)
15 : base()
16 {
17 this.record = record;
18 this.field = field;
19 }
20
21 public override bool CanRead { get { return true; } }
22 public override bool CanWrite { get { return false; } }
23 public override bool CanSeek { get { return false; } }
24
25 public override long Length
26 {
27 get
28 {
29 return this.record.GetDataSize(this.field);
30 }
31 }
32
33 public override long Position
34 {
35 get
36 {
37 return this.position;
38 }
39
40 set
41 {
42 throw new NotSupportedException();
43 }
44 }
45
46 public override long Seek(long offset, SeekOrigin origin)
47 {
48 throw new NotSupportedException();
49 }
50
51 public override void SetLength(long value)
52 {
53 throw new NotSupportedException();
54 }
55
56 public override void Flush()
57 {
58 throw new NotSupportedException();
59 }
60
61 public override int Read(byte[] buffer, int offset, int count)
62 {
63 if (count > 0)
64 {
65 byte[] readBuffer = (offset == 0 ? buffer : new byte[count]);
66 uint ucount = (uint) count;
67 uint ret = RemotableNativeMethods.MsiRecordReadStream((int) this.record.Handle, (uint) this.field, buffer, ref ucount);
68 if (ret != 0)
69 {
70 throw InstallerException.ExceptionFromReturnCode(ret);
71 }
72 count = (int) ucount;
73 if (offset > 0)
74 {
75 Array.Copy(readBuffer, 0, buffer, offset, count);
76 }
77 this.position += count;
78 }
79 return count;
80 }
81
82 public override void Write(byte[] array, int offset, int count)
83 {
84 throw new NotSupportedException();
85 }
86
87 public override string ToString()
88 {
89 return "[Binary data]";
90 }
91 }
92}