public UnmanagedPhysFSStream(PHYSFS_Io *io) { if (ManagedPhysFSStream.TryGetAsManagedIo(io, out var _)) { throw new ArgumentException("Provided implementation is managed."); } this.io = io; }
static int Flush(PHYSFS_Io *io) { return(Safely(() => { var stream = allocated[io->opaque].stream; if (stream != null) { stream.Flush(); } return 1; })); }
public void Dispose() { PHYSFS_Io *i = io; io = null; if (i != null) { i->destroy(i); } }
static int Seek(PHYSFS_Io *io, ulong offset) { return(Safely(() => { var stream = allocated[io->opaque].stream; if (stream != null) { stream.Position = (long)offset; } return 1; })); }
static long Write(PHYSFS_Io *io, byte[] buf, ulong len) { try { var stream = allocated[io->opaque].stream; if (stream == null) { return((long)len); } return(stream.Write(buf)); } catch (Exception ex) { SetException(ex); PHYSFS_setErrorCode((int)EXCEPTION_ERROR); return(-1); } }
static long Length(PHYSFS_Io *io) { try { var stream = allocated[io->opaque].stream; if (stream == null) { return(0); } return(stream.Length); } catch (Exception ex) { SetException(ex); PHYSFS_setErrorCode((int)EXCEPTION_ERROR); return(-1); } }
static void Destroy(PHYSFS_Io *io) { // Unfortunately, this call may not fail. // We cannot let ANY exception whatsoever // escape this method, so we'll just have // to swallow it. try { var stream = allocated[io->opaque].stream; if (stream != null) { stream.Dispose(); } } catch { } finally { try { allocated[io->opaque].me.Free(); } catch { } } }
public IPhysicsFSStream Duplicate() { CheckDisposed(); PHYSFS_Io *dup = io->duplicate(io); if (dup == null) { var error = (ErrorCode)PHYSFS_getLastErrorCode(); if (error > ErrorCode.Ok) { throw Exception(error); } else { return(null); } } return(new UnmanagedPhysFSStream(dup)); }
static PHYSFS_Io *Duplicate(PHYSFS_Io *io) { try { var stream = allocated[io->opaque].stream; if (stream == null) { return((PHYSFS_Io *)new ManagedPhysFSStream(null)); } var stream2 = stream.Duplicate(); var other = new ManagedPhysFSStream(stream2); return((PHYSFS_Io *)other); } catch (Exception ex) { SetException(ex); PHYSFS_setErrorCode((int)EXCEPTION_ERROR); return(null); } }
public static bool TryGetAsManagedIo(PHYSFS_Io *io, out ManagedPhysFSStream wrapper) { return(allocated.TryGetValue(io->opaque, out wrapper)); }