예제 #1
0
        public void AddFile(string name, byte[] data, bool overwrite = false)
        {
            if (IsFile(name))
            {
                if (overwrite == false)
                {
                    throw new ArgumentException($"'{name}' already exists in the hamcore building entries.");
                }
                else
                {
                    DeleteFile(name);
                }
            }

            HamCoreBuilderFileEntry f = new HamCoreBuilderFileEntry();

            Console.Write("{0}: ", name);

            f.Name    = name;
            f.RawData = new Buf(Util.CloneByteArray(data));
            Console.Write("{0} -> ", f.RawData.Size);
            f.CompressedData = new Buf(ZLib.Compress(f.RawData.ByteData));
            Console.WriteLine("{0}", f.CompressedData.Size);

            this.fileList.Add(f);
        }
예제 #2
0
        public void AddFile(string name, byte[] data)
        {
            if (IsFile(name))
            {
                throw new InvalidOperationException("fileName");
            }

            HamCoreBuilderFileEntry f = new HamCoreBuilderFileEntry();

            Console.Write("{0}: ", name);

            f.Name    = name;
            f.RawData = new Buf(Util.CloneByteArray(data));
            Console.Write("{0} -> ", f.RawData.Size);
            f.CompressedData = new Buf(ZLib.Compress(f.RawData.ByteData));
            Console.WriteLine("{0}", f.CompressedData.Size);

            this.fileList.Add(f);
        }
예제 #3
0
        public Buf ReadHamcore(string name)
        {
            if (name[0] == '|')
            {
                name = name.Substring(1);
            }
            if (name[0] == '/' || name[0] == '\\')
            {
                name = name.Substring(1);
            }

            string filename = name;

            filename = filename.Replace("/", "\\");

            Buf b;

            if (this.disableReadRawFile == false)
            {
                try
                {
                    b = Buf.ReadFromFile(HamcoreDirName + "\\" + filename);

                    return(b);
                }
                catch
                {
                }
            }

            lock (list)
            {
                HamCoreEntry c;
                string       key = filename.ToUpper();

                b = null;

                if (list.ContainsKey(key))
                {
                    c = list[key];

                    if (c.Buffer != null)
                    {
                        b = new Buf(c.Buffer);
                        b.SeekToBegin();
                        c.LastAccess = Time.Tick64;
                    }
                    else
                    {
                        if (hamcore_io.Seek(SeekOrigin.Begin, (int)c.Offset))
                        {
                            byte[] data = hamcore_io.Read((int)c.SizeCompressed);

                            int    dstSize = (int)c.Size;
                            byte[] buffer  = ZLib.Uncompress(data, dstSize);

                            c.Buffer = buffer;
                            b        = new Buf(buffer);
                            b.SeekToBegin();
                            c.LastAccess = Time.Tick64;
                        }
                    }
                }

                long now = Time.Tick64;
                foreach (HamCoreEntry cc in list.Values)
                {
                    if (cc.Buffer != null)
                    {
                        if (((cc.LastAccess + HamcoreCacheExpires) < now) ||
                            cc.FileName.StartsWith("Li", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cc.Buffer = null;
                        }
                    }
                }
            }

            return(b);
        }