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)); }
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); } }
private long Tell(ref RetroVfsFileHandle stream) { var hPtr = stream.handle; if (!_fileDictionary.ContainsKey(hPtr)) { return(-1); } return(_fileDictionary[hPtr].Position); }
private long Size(ref RetroVfsFileHandle stream) { var hPtr = stream.handle; if (!_fileDictionary.ContainsKey(hPtr)) { return(-1); } return(_fileDictionary[hPtr].Length); }
private int Flush(ref RetroVfsFileHandle stream) { var hPtr = stream.handle; if (!_fileDictionary.ContainsKey(hPtr)) { return(-1); } _fileDictionary[hPtr].Flush(); return(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); }
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); }
private string GetPath(ref RetroVfsFileHandle stream) { return(!_fileDictionary.ContainsKey(stream.handle) ? null : _fileDictionary[stream.handle].Name); }