public static bool ReadFileHeader(Stream stream, out AutcpFileHeader fileHeader) { try { var buffer = new byte[FileHeaderSize]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, FileHeaderSize); var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); fileHeader = Marshal.PtrToStructure <AutcpFileHeader>(gch.AddrOfPinnedObject()); gch.Free(); // test for valid data var sig = Encoding.UTF8.GetString(fileHeader.signature, 0, fileHeader.signature.Length); var isSuccessful = sig == "AUTCP"; return(isSuccessful); } catch (Exception ex) { fileHeader = new AutcpFileHeader(); return(false); } }
public static bool AddHeader(Stream stream) { var fileHeader = new AutcpFileHeader { signature = Encoding.UTF8.GetBytes("AUTCP"), version = FormatVersion, compatability = FormatCompatabilityVersion }; return(WriteFileHeader(stream, fileHeader)); }
public static bool AddHeader(Stream stream) { var fileHeader = new AutcpFileHeader { signature = Encoding.UTF8.GetBytes("AUTCP"), version = FormatVersion, compatability = FormatCompatabilityVersion }; return WriteFileHeader(stream, fileHeader); }
public static bool WriteFileHeader(Stream stream, AutcpFileHeader fileHeader) { try { var buffer = new byte[FileHeaderSize]; var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(fileHeader, gch.AddrOfPinnedObject(), false); gch.Free(); stream.Seek(0, SeekOrigin.Begin); stream.Write(buffer, 0, FileHeaderSize); return(true); } catch { return(false); } }
public static bool WriteFileHeader(Stream stream, AutcpFileHeader fileHeader) { try { var buffer = new byte[FileHeaderSize]; var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); Marshal.StructureToPtr(fileHeader, gch.AddrOfPinnedObject(), false); gch.Free(); stream.Seek(0, SeekOrigin.Begin); stream.Write(buffer, 0, FileHeaderSize); return true; } catch { return false; } }
public static bool ReadFileHeader(Stream stream, out AutcpFileHeader fileHeader) { try { var buffer = new byte[FileHeaderSize]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, FileHeaderSize); var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); fileHeader = Marshal.PtrToStructure<AutcpFileHeader>(gch.AddrOfPinnedObject()); gch.Free(); // test for valid data var sig = Encoding.UTF8.GetString(fileHeader.signature, 0, fileHeader.signature.Length); var isSuccessful = sig == "AUTCP"; return isSuccessful; } catch (Exception ex) { fileHeader = new AutcpFileHeader(); return false; } }