Upload 2.0.2
[physicsfs] / extras / PhysFS.NET / PhysFS_DLL.cs
diff --git a/extras/PhysFS.NET/PhysFS_DLL.cs b/extras/PhysFS.NET/PhysFS_DLL.cs
new file mode 100755 (executable)
index 0000000..bc9300c
--- /dev/null
@@ -0,0 +1,113 @@
+/* PhysFS_DLL - (c)2003 Gregory S. Read\r
+ * Internal class that provides direct access to the PhysFS DLL.  It is\r
+ * not accessible outside of the PhysFS.NET assembly.\r
+ */\r
+using System.Collections;\r
+using System.Runtime.InteropServices;\r
+\r
+namespace PhysFS_NET\r
+{\r
+   internal class PhysFS_DLL\r
+   {\r
+      /* Static constructor\r
+       * Initializes the PhysFS API before any method is called in this class.  This\r
+       * relieves the user from having to explicitly initialize the API.\r
+       * Parameters\r
+       *    none\r
+       * Returns\r
+       *    none\r
+       * Exceptions\r
+       *    PhysFSException - An error occured in the PhysFS API\r
+       */\r
+      static PhysFS_DLL()\r
+      {\r
+         if(PHYSFS_init("") == 0)\r
+            throw new PhysFSException();\r
+      }\r
+\r
+      /* BytePPToArray\r
+       * Converts a C-style string array into a .NET managed string array\r
+       * Parameters\r
+       *    C-style string array pointer returned from PhysFS\r
+       * Returns\r
+       *    .NET managed string array\r
+       * Exceptions\r
+       *    none\r
+       */\r
+      public unsafe static string[] BytePPToArray(byte **bytearray)\r
+      {\r
+         byte** ptr;\r
+         byte* c;\r
+         string tempstr;\r
+         ArrayList MyArrayList = new ArrayList();\r
+         string[] RetArray;\r
+\r
+         for(ptr = bytearray; *ptr != null; ptr++)
+         {
+            tempstr = "";
+            for(c = *ptr; *c != 0; c++)
+            {
+               tempstr += (char)*c;\r
+            }\r
+\r
+            // Add string to our list\r
+            MyArrayList.Add(tempstr);\r
+         }\r
+\r
+         // Return a normal array of the list\r
+         RetArray = new string[MyArrayList.Count];\r
+         MyArrayList.CopyTo(RetArray, 0);\r
+         return RetArray;\r
+      }\r
+\r
+      // Name of DLL to import\r
+      private const string PHYSFS_DLLNAME = "physfs.dll";\r
+\r
+      // DLL import declarations\r
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_init(string argv0);\r
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_deinit();\r
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void PHYSFS_freeList(void *listVar);
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getLastError();
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getDirSeparator();
+      [DllImport(PHYSFS_DLLNAME)] public static extern void PHYSFS_permitSymbolicLinks(int allow);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_getCdRomDirs();\r
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getBaseDir();
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getUserDir();
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getWriteDir();
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_setWriteDir(string newDir);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_addToSearchPath(string newDir, int appendToPath);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_removeFromSearchPath(string oldDir);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_getSearchPath();
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_setSaneConfig(string organization,
+         string appName,
+         string archiveExt,
+         int includeCdRoms,
+         int archivesFirst);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_mkdir(string dirName);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_delete(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getRealDir(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_enumerateFiles(string dir);\r
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_exists(string fname);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_isDirectory(string fname);
+      [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_isSymbolicLink(string fname);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openWrite(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openAppend(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openRead(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_close(void* handle);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_getLastModTime(string filename);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_read(void* handle,
+         void *buffer,
+         uint objSize,
+         uint objCount);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_write(void* handle,
+         void *buffer,
+         uint objSize,
+         uint objCount);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_eof(void* handle);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_tell(void* handle);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_seek(void* handle, ulong pos);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_fileLength(void* handle);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_setBuffer(void* handle, ulong bufsize);
+      [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_flush(void* handle);
+   }\r
+}\r