Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
OdbStreamWriter.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 
10 namespace SiliconStudio.Core.Storage
11 {
12  public abstract class OdbStreamWriter : Stream
13  {
14  protected readonly Stream stream;
15  private readonly long initialPosition;
16 
17  public Action<OdbStreamWriter> Disposed;
18 
19  protected OdbStreamWriter(Stream stream, string temporaryName)
20  {
21  this.stream = stream;
22  initialPosition = stream.Position;
23  TemporaryName = temporaryName;
24  }
25 
26  public string TemporaryName;
27 
28  public abstract ObjectId CurrentHash { get; }
29 
30  public override bool CanRead { get { return false; } }
31 
32  public override bool CanSeek { get { return true; } }
33 
34  public override bool CanWrite { get { return stream.CanWrite; } }
35 
36  public override void Flush()
37  {
38  stream.Flush();
39  }
40 
41  protected override void Dispose(bool disposing)
42  {
43  // Force hash computation before stream is closed.
44  var hash = CurrentHash;
45  stream.Dispose();
46 
47  var disposed = Disposed;
48  if (disposed != null)
49  disposed(this);
50  }
51 
52  public override long Length
53  {
54  get
55  {
56  return stream.Length - initialPosition;
57  }
58  }
59 
60  public override long Position
61  {
62  get
63  {
64  return stream.Position - initialPosition;
65  }
66  set
67  {
68  stream.Position = initialPosition + value;
69  }
70  }
71 
72  public override int Read(byte[] buffer, int offset, int count)
73  {
74  throw new InvalidOperationException();
75  }
76 
77  public override long Seek(long offset, SeekOrigin origin)
78  {
79  return stream.Seek(offset, origin);
80  }
81 
82  public override void SetLength(long value)
83  {
84  throw new InvalidOperationException();
85  }
86  }
87 }
override void Dispose(bool disposing)
override long Seek(long offset, SeekOrigin origin)
_In_ size_t count
Definition: DirectXTexP.h:174
OdbStreamWriter(Stream stream, string temporaryName)
A hash to uniquely identify data.
Definition: ObjectId.cs:13
override int Read(byte[] buffer, int offset, int count)