/[MorrowindCustomClothingSlotCreator]/trunk/libTES3FileFormat/ICustomCommitWriter.cs
ViewVC logotype

Contents of /trunk/libTES3FileFormat/ICustomCommitWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations) (download)
Sat Jul 30 12:33:46 2011 UTC (9 years ago) by william
File size: 2307 byte(s)
** workout Save() and SaveAs()
** SaveAs() does not seem to write the other data out (only contains the data for the clothing section(s))

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6
7 namespace libTES3FileFormat
8 {
9 public interface ICustomCommitFileWriter : ICommitWriter, ISetCommitWriter
10 {
11 //bool WriteToFile(string filename);
12 }
13
14 public class CustomCommitFileWriter : ICustomCommitFileWriter
15 {
16 private string filename;
17 public CustomCommitFileWriter() : this(new byte[] { 0x0 }, "") { }
18 public CustomCommitFileWriter(MemoryStream stream, string filename) : this(stream.ToArray(), filename) { }
19 public CustomCommitFileWriter(Stream stream, string filename)
20 {
21 stream.Seek(0, SeekOrigin.Begin);
22 BinaryReader reader = new BinaryReader(stream);
23 byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);
24 this.init(data,filename);
25 }
26 public CustomCommitFileWriter(ICommitWriter writer, string filename) : this(writer.GetWriter().BaseStream, filename) { }
27 public CustomCommitFileWriter(BinaryReader reader, string filename)
28 {
29 reader.BaseStream.Seek(0, SeekOrigin.Begin);
30 byte[] data = reader.ReadBytes((int)reader.BaseStream.Length);
31 this.init(data, filename);
32 }
33 public CustomCommitFileWriter(byte[] data, string filename)
34 {
35 this.init(data, filename);
36 }
37
38 private void init(byte[] data, string filename)
39 {
40 MemoryStream ms = new MemoryStream(data, 0, data.Length);
41 FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
42 BinaryWriter write = new BinaryWriter(fs);
43 this.SetWriter(write);
44 this.filename = filename;
45
46 }
47
48 private BinaryWriter _writer;
49 private BinaryWriter Writer
50 {
51 get { return _writer; }
52 set { _writer = value; }
53 }
54 #region ICommitWriter Members
55 public System.IO.BinaryWriter GetWriter() { return this.Writer; }
56 #endregion
57
58 #region ISetCommitWriter Members
59 public void SetWriter(System.IO.BinaryWriter writer) { this.Writer = writer; }
60 #endregion
61 }
62 }

  ViewVC Help
Powered by ViewVC 1.1.22