Beispiel #1
0
 public V8File(V8Catalog _parent, String _name, V8File _previous, int _start_data, int _start_header, DateTime _time_create, DateTime _time_modify)
 {
     IsDestructed     = false;
     Flushed          = false;
     Parent           = _parent;
     Name             = _name;
     Previous         = _previous;
     Next             = null;
     Data             = null;
     StartData        = _start_data;
     StartHeader      = _start_header;
     IsDataModified   = (StartData != 0 ? true : false);
     IsHeaderModified = (StartHeader != 0 ? true : false);
     if (Previous != null)
     {
         Previous.Next = this;
     }
     else
     {
         Parent.First = this;
     }
     ISCatalog  = FileIsCatalog.iscatalog_unknown;
     Self       = null;
     IsOpened   = false;
     TimeCreate = _time_create;
     TimeModify = _time_modify;
     SelfZipped = false;
     if (Parent != null)
     {
         Parent.Files[Name.ToUpper()] = this;
     }
 }
Beispiel #2
0
        public void Close()
        {
            int _t = 0;

            if (Parent == null)
            {
                return;
            }

            if (!IsOpened)
            {
                return;
            }

            if (Self != null)
            {
                if (Self.is_destructed)
                {
                    Self = null;
                }
            }
            Self = null;

            if (Parent.Data != null)
            {
                if (IsDataModified || IsHeaderModified)
                {
                    if (IsDataModified)
                    {
                        StartData = Parent.WriteDataBlock(Data, StartData, SelfZipped);
                    }
                    if (IsHeaderModified)
                    {
                        MemoryStream hs = new MemoryStream();
                        hs.Write(BitConverter.GetBytes(TimeCreate.Ticks), 0, 8);
                        hs.Write(BitConverter.GetBytes(TimeModify.Ticks), 0, 8);
                        hs.Write(BitConverter.GetBytes(_t), 0, 4);
                        hs.Write(Encoding.UTF8.GetBytes(Name), 0, Name.Length);
                        hs.Write(BitConverter.GetBytes(_t), 0, 4);

                        StartHeader = Parent.WriteBlock(hs, StartHeader, false);
                        hs.Dispose();
                    }
                }
            }
            Data.Dispose();
            Data             = null;
            ISCatalog        = FileIsCatalog.iscatalog_false;
            IsOpened         = false;
            IsDataModified   = false;
            IsHeaderModified = false;
        }
Beispiel #3
0
        public int WriteAndClose(Stream _Stream, int Length = -1) // перезапись целиком и закрытие файла (для экономии памяти не используется data файла)
        {
            int _t = 0;

            if (!IsOpened)
            {
                if (!Open())
                {
                    return(0);
                }
            }

            if (Parent == null)
            {
                return(0);
            }

            if (Self != null)
            {
                Self = null;
            }

            Data.Dispose();
            Data = null;

            if (Parent.Data != null)
            {
                StartData = Parent.WriteDataBlock(_Stream, StartData, SelfZipped, Length);
                MemoryStream hs = new MemoryStream();
                hs.Write(BitConverter.GetBytes(TimeCreate.Ticks), 0, 8);
                hs.Write(BitConverter.GetBytes(TimeModify.Ticks), 0, 8);
                hs.Write(BitConverter.GetBytes(_t), 0, 4);
                hs.Write(Encoding.UTF8.GetBytes(Name), 0, Name.Length);
                hs.Write(BitConverter.GetBytes(_t), 0, 4);

                StartHeader = Parent.WriteBlock(hs, StartHeader, false);
                hs.Dispose();
            }
            ISCatalog        = FileIsCatalog.iscatalog_unknown;
            IsOpened         = false;
            IsDataModified   = false;
            IsHeaderModified = false;

            if (Length == -1)
            {
                return((int)_Stream.Length);
            }

            return(Length);
        }
Beispiel #4
0
        public void DeleteFile()
        {
            if (Parent != null)
            {
                if (Next != null)
                {
                    Next.Previous = Previous;
                }
                else
                {
                    Parent.Last = Previous;
                }

                if (Previous != null)
                {
                    Previous.Next = Next;
                }
                else
                {
                    Parent.First = Next;
                }

                Parent.is_fatmodified = true;
                Parent.FreeBlock(StartData);
                Parent.FreeBlock(StartHeader);
                Parent.Files.Remove(Name.ToUpper());
                Parent = null;
            }
            Data = null;
            if (Self != null)
            {
                Self.Data = null;
                Self      = null;
            }
            ISCatalog        = FileIsCatalog.iscatalog_false;
            Next             = null;
            Previous         = null;
            IsOpened         = false;
            StartData        = 0;
            StartHeader      = 0;
            IsDataModified   = false;
            IsHeaderModified = false;
        }
Beispiel #5
0
        public bool IsCatalog()
        {
            int _filelen    = 0;
            int _startempty = -1;

            byte[] _t  = new byte[32];
            byte[] _t4 = new byte[8];

            if (ISCatalog == FileIsCatalog.iscatalog_unknown)
            {
                if (!IsOpened)
                {
                    if (!Open())
                    {
                        return(false);
                    }
                }

                _filelen = (int)Data.Length;

                if (_filelen == 16)
                {
                    Data.Seek(0, SeekOrigin.Begin);
                    Data.Read(_t, 0, 16);
                    if (!ByteArrayCompare(_t, _empty_catalog_template))
                    {
                        ISCatalog = FileIsCatalog.iscatalog_false;
                        return(false);
                    }
                    else
                    {
                        ISCatalog = FileIsCatalog.iscatalog_true;
                        return(true);
                    }
                }
                Data.Seek(0, SeekOrigin.Begin);
                Data.Read(_t4, 0, 4);

                if (BitConverter.ToInt32(_t4, 0) != 0x7fffffff)
                {
                    if (_startempty + 31 >= _filelen)
                    {
                        return(false);
                    }
                    Data.Seek(_startempty, SeekOrigin.Begin);
                    Data.Read(_t, 0, 31);
                    if (_t[0] != 0xd || _t[1] != 0xa || _t[10] != 0x20 || _t[19] != 0x20 || _t[28] != 0x20 || _t[29] != 0xd || _t[30] != 0xa)
                    {
                        ISCatalog = FileIsCatalog.iscatalog_false;
                        return(false);
                    }
                }
                if (_filelen < 31 + 16)
                {
                    ISCatalog = FileIsCatalog.iscatalog_false;
                    return(false);
                }
                Data.Seek(16, SeekOrigin.Begin);
                Data.Read(_t, 0, 31);
                if (_t[0] != 0xd || _t[1] != 0xa || _t[10] != 0x20 || _t[19] != 0x20 || _t[28] != 0x20 || _t[29] != 0xd || _t[30] != 0xa)
                {
                    ISCatalog = FileIsCatalog.iscatalog_false;
                    return(false);
                }
                ISCatalog = FileIsCatalog.iscatalog_true;
                return(true);
            }
            return(ISCatalog == FileIsCatalog.iscatalog_true);
        }