コード例 #1
0
        static public byte[] ReadFile(string name)
        {
            IO io = FileOpen(name);

            try
            {
                int    size = io.FileSize;
                byte[] ret  = io.Read(size);
                return(ret);
            }
            finally
            {
                io.Close();
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        void init(string filename)
        {
            filename = IO.InnerFilePath(filename);
            string filenameOnly = Path.GetFileName(filename);
            string filenameAlt  = Path.Combine(Path.GetDirectoryName(filename), "_" + filenameOnly);

            try
            {
                IO.FileReplaceRename(filenameAlt, filename);
            }
            catch
            {
            }

            list = new Dictionary <string, HamCoreEntry>();

            try
            {
                hamcore_io = IO.FileOpen(filename);
            }
            catch
            {
                return;
            }

            try
            {
                byte[] header  = hamcore_io.Read(HamcoreHeaderSize);
                byte[] header2 = Str.AsciiEncoding.GetBytes(HamcoreHeaderData);
                if (header == null || Util.CompareByte(header, header2) == false)
                {
                    throw new SystemException();
                }

                uint   num = 0;
                byte[] buf = hamcore_io.Read(Util.SizeOfInt32);
                num = Util.ByteToUInt(buf);
                uint i;
                for (i = 0; i < num; i++)
                {
                    uint str_size;

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    str_size = Util.ByteToUInt(buf);
                    if (str_size >= 1)
                    {
                        str_size--;
                    }

                    byte[] str_data = hamcore_io.Read((int)str_size);
                    string tmp      = Str.ShiftJisEncoding.GetString(str_data);

                    HamCoreEntry c = new HamCoreEntry();
                    c.FileName = tmp;

                    buf    = hamcore_io.Read(Util.SizeOfInt32);
                    c.Size = Util.ByteToUInt(buf);

                    buf = hamcore_io.Read(Util.SizeOfInt32);
                    c.SizeCompressed = Util.ByteToUInt(buf);

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    c.Offset = Util.ByteToUInt(buf);

                    list.Add(c.FileName.ToUpper(), c);
                }
            }
            catch
            {
                hamcore_io.Close();
            }
        }