예제 #1
0
        private long Seek(ref RetroVfsFileHandle stream, long offset, int seek)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr))
            {
                return(-1);
            }

            SeekOrigin seekOrigin;

            switch (seek)
            {
            case 0:
                seekOrigin = SeekOrigin.Begin;
                break;

            case 1:
                seekOrigin = SeekOrigin.Current;
                break;

            case 2:
                seekOrigin = SeekOrigin.End;
                break;

            default:
                return(-1);
            }

            return(_fileDictionary[hPtr].Seek(offset, seekOrigin));
        }
예제 #2
0
        private int Close(ref RetroVfsFileHandle stream)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr))
            {
                return(-1);
            }

            try
            {
                using (var fileStream = _fileDictionary[hPtr])
                {
                    if (!_fileDictionary.Remove(hPtr))
                    {
                        return(-1);
                    }

                    fileStream.Close();
                    return(0);
                }
            }
            catch
            {
                return(-1);
            }
        }
예제 #3
0
        private long Tell(ref RetroVfsFileHandle stream)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr))
            {
                return(-1);
            }

            return(_fileDictionary[hPtr].Position);
        }
예제 #4
0
        private long Size(ref RetroVfsFileHandle stream)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr))
            {
                return(-1);
            }

            return(_fileDictionary[hPtr].Length);
        }
예제 #5
0
        private int Flush(ref RetroVfsFileHandle stream)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr))
            {
                return(-1);
            }

            _fileDictionary[hPtr].Flush();

            return(0);
        }
예제 #6
0
        private long Write(ref RetroVfsFileHandle stream, IntPtr s, ulong len)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr) || len > int.MaxValue)
            {
                return(-1);
            }

            var data = new byte[len];

            Marshal.Copy(s, data, 0, (int)len);

            _fileDictionary[hPtr].Write(data, 0, (int)len);

            return((int)len);
        }
예제 #7
0
        private long Read(ref RetroVfsFileHandle stream, IntPtr s, ulong len)
        {
            var hPtr = stream.handle;

            if (!_fileDictionary.ContainsKey(hPtr) || len > int.MaxValue)
            {
                return(-1);
            }

            var data       = new byte[len];
            var fileStream = _fileDictionary[hPtr];

            var res = fileStream.Read(data, 0, (int)len);

            Marshal.Copy(data, 0, s, data.Length);

            return(res);
        }
예제 #8
0
 private string GetPath(ref RetroVfsFileHandle stream)
 {
     return(!_fileDictionary.ContainsKey(stream.handle) ? null : _fileDictionary[stream.handle].Name);
 }