MoonTools.NETPhysFS/SharpPhysFS/PhysFS.LowLevel.cs

96 lines
2.3 KiB
C#
Raw Normal View History

2016-02-08 21:25:37 +00:00
using System;
namespace SharpPhysFS
{
public partial class PhysFS
{
internal static class LowLevel
2016-02-08 21:25:37 +00:00
{
public static IntPtr OpenWrite(string filename, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
var val = Interop.PHYSFS_openWrite(filename);
2016-02-08 21:25:37 +00:00
if (val == null)
throw new PhysFSException(physFS);
return val;
}
public static IntPtr OpenAppend(string filename, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
var val = Interop.PHYSFS_openAppend(filename);
2016-02-08 21:25:37 +00:00
if (val == null)
throw new PhysFSException(physFS);
return val;
}
public static IntPtr OpenRead(string filename, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
var val = Interop.PHYSFS_openRead(filename);
2016-02-08 21:25:37 +00:00
if (val == null)
throw new PhysFSException(physFS);
return val;
}
public static void Close(IntPtr file, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
int err = Interop.PHYSFS_close(file);
2016-02-08 21:25:37 +00:00
physFS.ThrowException(err);
}
2017-05-26 11:14:23 +00:00
public static long Read(IntPtr file, byte[] buffer, uint objSize, uint objCount)
2016-02-08 21:25:37 +00:00
{
unsafe
{
fixed (void* ptr = buffer)
{
2017-05-26 11:14:23 +00:00
return Interop.PHYSFS_read(file, (IntPtr)ptr, objSize, objCount);
2016-02-08 21:25:37 +00:00
}
}
}
2017-05-26 11:14:23 +00:00
public static long Write(IntPtr file, byte[] buffer, uint objSize, uint objCount)
2016-02-08 21:25:37 +00:00
{
unsafe
{
fixed (void* ptr = buffer)
{
2017-05-26 11:14:23 +00:00
return Interop.PHYSFS_write(file, (IntPtr)ptr, objSize, objCount);
2016-02-08 21:25:37 +00:00
}
}
}
2017-05-26 11:14:23 +00:00
public static bool EOF(IntPtr file)
2016-02-08 21:25:37 +00:00
{
2017-05-26 11:14:23 +00:00
return Interop.PHYSFS_eof(file) != 0;
2016-02-08 21:25:37 +00:00
}
2017-05-26 11:14:23 +00:00
public static long Tell(IntPtr file)
2016-02-08 21:25:37 +00:00
{
2017-05-26 11:14:23 +00:00
return Interop.PHYSFS_tell(file);
2016-02-08 21:25:37 +00:00
}
public static void Seek(IntPtr file, ulong pos, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
int err = Interop.PHYSFS_seek(file, pos);
2016-02-08 21:25:37 +00:00
physFS.ThrowException(err);
}
2017-05-26 11:14:23 +00:00
public static long FileLength(IntPtr file)
2016-02-08 21:25:37 +00:00
{
2017-05-26 11:14:23 +00:00
return Interop.PHYSFS_fileLength(file);
2016-02-08 21:25:37 +00:00
}
public static void SetBuffer(IntPtr file, ulong bufSize, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
int err = Interop.PHYSFS_setBuffer(file, bufSize);
2016-02-08 21:25:37 +00:00
physFS.ThrowException(err);
}
public static void Flush(IntPtr file, PhysFS physFS)
{
2017-05-26 11:14:23 +00:00
int err = Interop.PHYSFS_flush(file);
2016-02-08 21:25:37 +00:00
physFS.ThrowException(err);
}
}
}
}