public SauceInfo() { Author = string.Empty; Title = string.Empty; Group = string.Empty; Date = DateTime.Now; DataType = SauceDataType.Character; ByteFileType = (byte)Types.Character.CharacterFileType.Ansi; SetTypeInfo(); comments = new SauceComment(); }
public SauceInfo(SauceInfo sauce) { Title = sauce.Title; Author = sauce.Author; Group = sauce.Group; Date = sauce.Date; FileSize = sauce.FileSize; dataType = sauce.dataType; ByteFileType = sauce.ByteFileType; TInfo1 = sauce.TInfo1; TInfo2 = sauce.TInfo2; TInfo3 = sauce.TInfo3; TInfo4 = sauce.TInfo4; TInfoS = sauce.TInfoS; ByteFlags = sauce.ByteFlags; comments = new SauceComment(sauce.Comments); SetTypeInfo(); }
void LoadSauce(Stream stream, bool seekPosition) { long origin = stream.Position; try { var br = new BinaryReader(stream); if (seekPosition) { var saucePos = stream.Length - SauceSize - 1; if (saucePos < 0) { throw new Exception("Sauce does not exist! File is too small."); } br.BaseStream.Seek(saucePos, SeekOrigin.Begin); } var eof = br.ReadByte(); var hasEof = eof == 26; long start = br.BaseStream.Position; var id = br.ReadBytes(5); var idstring = Encoding.ASCII.GetString(id); if (idstring != SauceID) { throw new Exception("Sauce does not exist!"); } br.ReadBytes(2); // version title = br.ReadBytes(35); author = br.ReadBytes(20); @group = br.ReadBytes(20); date = br.ReadBytes(8); FileSize = br.ReadInt32(); dataType = br.ReadByte(); SetTypeInfo(); ByteFileType = br.ReadByte(); TInfo1 = br.ReadUInt16(); TInfo2 = br.ReadUInt16(); TInfo3 = br.ReadUInt16(); TInfo4 = br.ReadUInt16(); var numComments = br.ReadByte(); ByteFlags = br.ReadByte(); // InfoS is a zero-terminated string var infoSBytes = br.ReadBytes(22); var zeroIdx = Array.FindIndex(infoSBytes, r => r == 0); if (zeroIdx == -1) { zeroIdx = infoSBytes.Length; } TInfoS = Encoding.ASCII.GetString(infoSBytes, 0, zeroIdx); if (numComments > 0) { var commentPos = start - (numComments * SauceComment.CommentSize) - 5; if (commentPos >= 0) { br.BaseStream.Seek(commentPos, SeekOrigin.Begin); } else { numComments = 0; } } comments = new SauceComment(br, numComments); FileSize = (int)(stream.Length - SauceSize); if (numComments > 0) { FileSize -= SauceComment.CommentID.Length + numComments * SauceComment.CommentSize; } if (hasEof) { FileSize--; } } finally { stream.Seek(origin, SeekOrigin.Begin); } }