Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public static bool AddHeader(Stream stream)
        {
            var fileHeader = new AutcpFileHeader
            {
                signature     = Encoding.UTF8.GetBytes("AUTCP"),
                version       = FormatVersion,
                compatability = FormatCompatabilityVersion
            };

            return(WriteFileHeader(stream, fileHeader));
        }
Esempio n. 3
0
        public static bool AddHeader(Stream stream)
        {
            var fileHeader = new AutcpFileHeader
            {
                signature = Encoding.UTF8.GetBytes("AUTCP"), 
                version = FormatVersion, 
                compatability = FormatCompatabilityVersion
            };

            return WriteFileHeader(stream, fileHeader);
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        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;
            }
        }