示例#1
0
        /// <summary>
        /// Создать каталог из потока
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="_zipped"></param>
        /// <param name="leave_stream"></param>
        public V8Catalog(Stream stream, bool _zipped, bool leave_stream = false)
        {
            is_cfu           = false;
            iscatalogdefined = false;
            zipped           = _zipped;
            Data             = stream;
            File             = null;

            if (Data.Length != 0)
            {
                Data.Write(StringToByteArray(_EMPTY_CATALOG_TEMPLATE), 0, CATALOG_HEADER_LEN2);
            }

            if (IsCatalog())
            {
                Initialize();
            }
            else
            {
                First       = null;
                Last        = null;
                start_empty = 0;
                page_size   = 0;
                version     = 0;
                zipped      = false;

                is_fatmodified   = false;
                is_emptymodified = false;
                is_modified      = false;
                is_destructed    = false;
                flushed          = false;
            }
            leave_data = leave_stream;
        } // создать каталог из потока
示例#2
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;
     }
 }
示例#3
0
        public void SaveToDir(String DirName)
        {
            V8File f = First;

            DirectoryInfo di = new DirectoryInfo(DirName);

            di.Create();

            if (!DirName.EndsWith("\\"))
            {
                DirName += '\\';
            }

            while (f != null)
            {
                if (f.IsCatalog())
                {
                    f.GetCatalog().SaveToDir(DirName + f.Name);
                }
                else
                {
                    f.SaveToFile(DirName + f.Name);
                }
                f.Close();
                f = f.Next;
            }
        }
示例#4
0
        public V8Catalog CreateCatalog(String FileName, bool _selfzipped = false)
        {
            V8Catalog ret;

            V8File f = CreateFile(FileName, _selfzipped);

            if (f.GetFileLength() > 0)
            {
                if (f.IsCatalog())
                {
                    ret = f.GetCatalog();
                }
                else
                {
                    ret = null;
                }
            }
            else
            {
                f.Write(Encoding.UTF8.GetBytes(_EMPTY_CATALOG_TEMPLATE), CATALOG_HEADER_LEN2);
                ret = f.GetCatalog();
            }

            return(ret);
        }
示例#5
0
        public bool leave_data;    // признак, что не нужно удалять основной поток (data) при уничтожении объекта

        #region Конструкторы класса
        /// <summary>
        /// создать каталог из файла
        /// </summary>
        /// <param name="f"></param>
        public V8Catalog(V8File f) // создать каталог из файла
        {
            is_cfu           = false;
            iscatalogdefined = false;
            File             = f;

            File.Open();
            Data   = File.Data;
            zipped = false;

            if (IsCatalog())
            {
                Initialize();
            }
            else
            {
                First       = null;
                Last        = null;
                start_empty = 0;
                page_size   = 0;
                version     = 0;
                zipped      = false;

                is_fatmodified   = false;
                is_emptymodified = false;
                is_modified      = false;
                is_destructed    = false;
                flushed          = false;
                leave_data       = false;
            }
        }
示例#6
0
        public static Tree Get_treeFromV8file(V8File f)
        {
            //TBytesStream* sb;

            Encoding enc;

            Byte[] bytes = new Byte[0x1000];
            Int32  offset;
            Tree   rt;

            //MemoryStream sb = new MemoryStream(bytes);
            MemoryTributary sb = new MemoryTributary(bytes);

            //f.SaveToStream(sb);
            f.SaveToStream(sb);

            enc = null;

            /*
             * //offset = Encoding::GetBufferEncoding(sb->GetBytes(), enc);
             * offset = Encoding.GetEncoding()
             * if (offset == 0)
             * {
             *  msreg_g.AddError("Ошибка определения кодировки файла контейнера",
             *      "Файл", f->GetFullName());
             *  delete sb;
             *  return nullptr;
             * }
             * bytes = TEncoding::Convert(enc, TEncoding::Unicode, sb->GetBytes(), offset, sb->GetSize() - offset);
             *
             * rt = parse_1Ctext(String((WCHART*)&bytes[0], bytes.size() / 2), f->GetFullName());
             * delete sb;
             */
            return(null);
        }
示例#7
0
        public V8File CreateFile(String FileName, bool _selfzipped = false) // CreateFile в win64 определяется как CreateFileW, пришлось заменить на маленькую букву
        {
            Int64  v8t = 0;
            V8File f;

            f = GetFile(FileName);
            if (f != null)
            {
                SetCurrentTime(v8t);
                f              = new V8File(this, FileName, Last, 0, 0, new DateTime(v8t), new DateTime(v8t));
                f.SelfZipped   = _selfzipped;
                Last           = f;
                is_fatmodified = true;
            }

            return(f);
        }
示例#8
0
        public V8File GetFile(String FileName)
        {
            V8File ret = null;

            foreach (KeyValuePair <String, V8File> kvp in Files)
            {
                if (kvp.Key.Equals(FileName.ToUpper()))
                {
                    ret = kvp.Value;
                    break;
                }
                else
                {
                    ret = null;
                }
            }
            return(ret);
        }
示例#9
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;
        }
示例#10
0
        public void DeleteFile(String FileName)
        {
            V8File f = First;

            while (f != null)
            {
                //if (!f.name.CompareIC(FileName))
                if (String.Compare(f.Name, FileName, true) != 0)
                {
                    f.DeleteFile();
                    f = null;
                }

                if (f != null)
                {
                    f = f.Next;
                }
            }
        }
示例#11
0
        public V8Catalog(String name, bool _zipped) // создать каталог из физического файла (cf, epf, erf, hbk, cfu)
        {
            iscatalogdefined = false;
            is_cfu           = false;
            zipped           = _zipped;

            if (!System.IO.File.Exists(name))
            {
                Data = new FileStream(name, FileMode.Create);
                Data.Write(StringToByteArray(_EMPTY_CATALOG_TEMPLATE), 0, CATALOG_HEADER_LEN2);
                Data.Dispose();
            }
            Data = new FileStream(name, FileMode.Open);
            File = null;
            if (IsCatalog())
            {
                Initialize();
            }
            else
            {
                First       = null;
                Last        = null;
                start_empty = 0;
                page_size   = 0;
                version     = 0;
                zipped      = false;

                is_fatmodified   = false;
                is_emptymodified = false;
                is_modified      = false;
                is_destructed    = false;
                flushed          = false;
                leave_data       = false;
            }

            Data?.Dispose();
        }
示例#12
0
        public bool is_modified;       // признак модифицированности

        /// <summary>
        /// Инициализация объекта
        /// </summary>
        public void Initialize()
        {
            is_destructed = false;
            Catalog_Header _ch   = new Catalog_Header();
            int            _temp = 0;
            string         _name = "";
            FAT_Item       _fi;
            //char* _temp_buf;
            //byte[] _temp_buf = new byte[32];

            MemoryStream _file_header = new MemoryStream();
            Stream       _fat         = null;
            V8File       _prev        = null;
            V8File       _file        = null;
            V8File       f            = null;
            int          _countfiles  = 0;

            Data.Seek(0, SeekOrigin.Begin);

            _ch = ReadFromData(Data);

            // т.к. читаем не с помощью метода чтения потока Data, позицию необходимо менять вручную
            //Data.Seek(16, SeekOrigin.Begin);

            start_empty = _ch.Start_Empty;
            page_size   = _ch.Page_Size;
            version     = _ch.Version;

            First = null;

            _prev = null;

            try
            {
                if (Data.Length > 16)
                {
                    int rlen = 0;
                    _fat = Read_Block(Data, 16, ref rlen);
                    _fat.Seek(0, SeekOrigin.Begin);

                    //_countfiles = (int)_fat.Length / 12;
                    _countfiles = rlen / 12;

                    //_countfiles = ((MemoryStream)_fat).Capacity / 0x100 / 12;
                    //_countfiles = (int)_fat.Length / 12;

                    for (int i = 0; i < _countfiles; i++)
                    {
                        //_fi = ReadFatItemFromData(Data);
                        _fi = ReadFatItemFromData(_fat);

                        Read_Block(Data, _fi.Header_Start, ref rlen, _file_header);

                        _file_header.Seek(0, SeekOrigin.Begin);

                        byte[] _temp_buf = new byte[_file_header.Length];

                        //_file_header->Read(_temp_buf, _file_header->Size);
                        _file_header.Read(_temp_buf, 0, (int)_file_header.Length);

                        // TODO: Надо пристально проверять что здесь происходит
                        // _name = (wchar_t*)(_temp_buf + 20);  - это ГУИД из 36 символов
                        //_name = GetString(_temp_buf)[20].ToString();
                        byte[] _tmp_uid = new byte[72];
                        Array.Copy(_temp_buf, 20, _tmp_uid, 0, 72);
                        _name = GetString(_tmp_uid);

                        if (_name.IndexOf("root") != -1)
                        {
                            _name = "root";
                        }
                        if (_name.IndexOf("version") != -1)
                        {
                            if (_name.IndexOf("versions") != -1)
                            {
                                _name = "versions";
                            }
                            else
                            {
                                _name = "version";
                            }
                        }


                        // TODO: Надо пристально проверять что здесь происходит
                        //_file = new v8file(this, _name, _prev, _fi.data_start, _fi.header_start, (__int64*)_temp_buf, (__int64*)(_temp_buf + 8));
                        _file = new V8File(this, _name, _prev, _fi.Data_Start, _fi.Header_Start, new DateTime(), new DateTime());
                        if (_prev == null)
                        {
                            First = _file;
                        }
                        _prev = _file;
                    }
                    //_file_header.Close();
                    //_fat.Close();
                }
            }
            catch (Exception)
            {
                f = First;
                while (f != null)
                {
                    f.Close();
                    f = f.Next;
                }
                while (First != null)
                {
                    First.Close();
                }
                iscatalog        = false;
                iscatalogdefined = true;

                First       = null;
                Last        = null;
                start_empty = 0;
                page_size   = 0;
                version     = 0;
                zipped      = false;
            }
            Last = _prev;

            is_fatmodified   = false;
            is_emptymodified = false;
            is_modified      = false;
            is_destructed    = false;
            flushed          = false;
            leave_data       = false;
        }
示例#13
0
        /// <summary>
        /// создать каталог из физического файла (cf, epf, erf, hbk, cfu)
        /// </summary>
        /// <param name="name"></param>
        public V8Catalog(String name) // создать каталог из физического файла (cf, epf, erf, hbk, cfu)
        {
            iscatalogdefined = false;

            String ext = Path.GetExtension(name).ToLower();

            if (ext == str_cfu)
            {
                is_cfu = true;
                zipped = false;
                //data = new MemoryStream();
                Data = new MemoryTributary();
                if (!System.IO.File.Exists(name))
                {
                    //data.WriteBuffer(_EMPTY_CATALOG_TEMPLATE, CATALOG_HEADER_LEN);
                    Data.Write(StringToByteArray(_EMPTY_CATALOG_TEMPLATE), 0, CATALOG_HEADER_LEN2);
                    CFu = new FileStream(name, FileMode.Create);
                }
                else
                {
                    CFu = new FileStream(name, FileMode.Append);
                    // Inflate((MemoryTributary)cfu, out data); TODO надо дорабатывать обязательно
                }
            }
            else
            {
                zipped = ext == str_cf || ext == str_epf || ext == str_erf || ext == str_cfe;
                is_cfu = false;

                if (!System.IO.File.Exists(name))
                {
                    // FileStream data1 = new FileStream(name, FileMode.Create);
                    // data1.Write(StringToByteArray(_EMPTY_CATALOG_TEMPLATE), 0, CATALOG_HEADER_LEN2);
                    // //data1 = null;
                    // data1.Dispose();
                    Data = new FileStream(name, FileMode.Create);
                    Data.Write(StringToByteArray(_EMPTY_CATALOG_TEMPLATE), 0, CATALOG_HEADER_LEN2);
                    //data1 = null;
                    if (Data != null)
                    {
                        Data.Dispose();
                    }
                }
                //Data = new FileStream(name, FileMode.Append);
                Data = new FileStream(name, FileMode.Open);
            }

            File = null;
            if (IsCatalog())
            {
                Initialize();
            }
            else
            {
                First       = null;
                Last        = null;
                start_empty = 0;
                page_size   = 0;
                version     = 0;
                zipped      = false;

                is_fatmodified   = false;
                is_emptymodified = false;
                is_modified      = false;
                is_destructed    = false;
                flushed          = false;
                leave_data       = false;
            }

            // if (CFu != null)
            //     CFu.Dispose();
            // if (Data != null)
            //     Data.Dispose();
        }