Skip to content
Francesco Bertolaccini edited this page Apr 9, 2017 · 4 revisions

Welcome to the SharpPhysFS wiki!

Getting started

To get started with SharpPhysFS you will need:

  • .NET Framework 4.5 / Mono 3.0 (I suppose)
  • xbuild / msbuild / VisualStudio / whatever to compile the wrapper
  • Working binaries for PhysFS / a working C compiler to compile PhysFS

Step 1a: Adding SharpPhysFS as a NuGet package

Simply run:

Install-Package SharpPhysFS

Step 1b: Compiling SharpPhysFS

First of all, clone the repo:

$ git clone https://github.com/frabert/SharpPhysFS.git
$ cd SharpPhysFS

Now you can move onto compiling: On Windows:

$ msbuild SharpPhysFS.sln /p:Configuration=Release

On Linux/OSX:

$ xbuild SharpPhysFS.sln /p:Configuration=Release

Step 2: Preparing PhysFS

To use SharpPhysFS you need to have PhysFS binaries available in your system. This means either installed system-wide or (at least on Windows) locally inside the directory of your app. On Windows, the standard name for the DLL is physfs.dll and it can be together with your app's binary or inside system32.

On Linux/unix it is called libphysfs.so and I've only tried it inside /usr/lib on Arch.

On OSX it is called libphysfs.dylib and I have no idea how it should work 😄 It should supposedly work if you put inside your standard location for libraries or inside the bundle of your app. I haven't tested it, but the functionality is there.

Step 3: Using SharpPhysFS

Now you can create your app: add a reference to the library and you can start. The first thing you've got to do is create a PhysFS object: this will try to load PhysFS and throw a PhysFSLibNotFound exception if the process fails. From now on, it works pretty much like plain PhysFS, note however that Init() and Deinit() are called automatically on object creation and disposal. Use the using pattern for added security against leaks. Easy!

Open files using PhysFSStream:

using(var pfs = new PhysFS(""))
using(var stream = pfs.OpenRead("/helloworld.txt"))
{
  var reader = new StreamReader(stream);
  var contents = reader.ReadToEnd();
}

Refer to the sample application for further examples, or drop an issue if need be.