Ejemplo n.º 1
0
        private void GetData()
        {
            try
            {
                if (Data == null)
                {
                    Data = new byte[Size];
                    var dataPtr = Marshal.AllocHGlobal(Size);

                    int num;
                    DatExport.GetSubfileData(_handle, (int)FileId, dataPtr, 0, out num);

                    Marshal.Copy(dataPtr, Data, 0, Size);
                    Marshal.FreeHGlobal(dataPtr);

                    if (IsCompressed)
                    {
                        Data = Decompress();
                    }
                }

                IsValid = true;
            }
            catch
            {
                Logger.Write($"файл #{FileId} повреждён, пропускаю.");
            }
        }
Ejemplo n.º 2
0
        internal Subfile(int handle, uint fileId, int size, int iteration, int version)
        {
            _handle      = handle;
            FileId       = fileId;
            Size         = size;
            Iteration    = iteration;
            Version      = version;
            IsCompressed = 1 == DatExport.GetSubfileCompressionFlag(_handle, (int)fileId);

            GetData();
            CheckHeader();
        }
Ejemplo n.º 3
0
        private void Load()
        {
            var count = DatExport.GetNumSubfiles(_handle);

            for (var i = 0; i < count; ++i)
            {
                int fileId;
                int size;
                int iteration;
                DatExport.GetSubfileSizes(_handle, out fileId, out size, out iteration, i, 1);

                SubfileInfo.Add((uint)fileId, new SubfileInfo((uint)fileId, size, iteration));
            }
        }
Ejemplo n.º 4
0
        public Subfile this[uint index]
        {
            get
            {
                Subfile subfile = null;

                if (SubfileInfo.ContainsKey(index))
                {
                    var si = SubfileInfo[index];
                    subfile = new Subfile(_handle, index, si.Size, si.Iteration, DatExport.GetSubfileVersion(_handle, (int)index));
                }

                return(subfile);
            }
        }
Ejemplo n.º 5
0
        private byte[] Decompress()
        {
            var size   = Data.Length;
            var num    = Data[3] << 24 | Data[2] << 16 | Data[1] << 8 | Data[0];
            var num2   = size - 4;
            var array2 = new byte[num];
            var array3 = new byte[num2];

            for (var j = 4; j < size; j++)
            {
                array3[j - 4] = Data[j];
            }

            DatExport.uncompress(array2, ref num, array3, num2);

            return(array2);
        }
Ejemplo n.º 6
0
        public void Open(string path, bool readOnly)
        {
            // detect
            ClientDat = ClientDat.WhoIs(path);

            // open
            _handle = AllocHandle();

            try
            {
                var  datIdStamp    = new StringBuilder(64);
                var  firstIterGuid = new StringBuilder(64);
                uint num           = 130u;

                if (readOnly)
                {
                    num |= 4u;
                }

                int   num2;
                int   num3;
                int   num4;
                int   num5;
                ulong num6;

                if (DatExport.OpenDatFile(_handle, path, num, out num2, out num3, out num4, out num5, out num6, datIdStamp, firstIterGuid) == -1)
                {
                    throw new DatFileException("Unable to open file [ " + path + " ]");
                }

                Load();
            }
            catch
            {
                FreeHandle(_handle);
                throw;
            }
        }
Ejemplo n.º 7
0
 public void Close()
 {
     DatExport.CloseDatFile(_handle);
 }
Ejemplo n.º 8
0
 public void Flush()
 {
     DatExport.Flush(_handle);
 }
Ejemplo n.º 9
0
 public int Purge(uint id)
 {
     return(DatExport.PurgeSubfileData(_handle, (int)id));
 }
Ejemplo n.º 10
0
 public int Put(uint id, IntPtr buffer, int offset, int size, int version, int iteration, bool compress = false)
 {
     return(DatExport.PutSubfileData(_handle, (int)id, buffer, offset, size, version, iteration, compress));
 }