extras/PhysFS.NET/PhysFS_DLL.cs
changeset 532 748f518a6d76
equal deleted inserted replaced
531:3c7cf50a58fb 532:748f518a6d76
       
     1 /* PhysFS_DLL - (c)2003 Gregory S. Read
       
     2  * Internal class that provides direct access to the PhysFS DLL.  It is
       
     3  * not accessible outside of the PhysFS.NET assembly.
       
     4  */
       
     5 using System.Collections;
       
     6 using System.Runtime.InteropServices;
       
     7 
       
     8 namespace PhysFS_NET
       
     9 {
       
    10    internal class PhysFS_DLL
       
    11    {
       
    12       /* Static constructor
       
    13        * Initializes the PhysFS API before any method is called in this class.  This
       
    14        * relieves the user from having to explicitly initialize the API.
       
    15        * Parameters
       
    16        *    none
       
    17        * Returns
       
    18        *    none
       
    19        * Exceptions
       
    20        *    PhysFSException - An error occured in the PhysFS API
       
    21        */
       
    22       static PhysFS_DLL()
       
    23       {
       
    24          if(PHYSFS_init("") == 0)
       
    25             throw new PhysFSException();
       
    26       }
       
    27 
       
    28       /* BytePPToArray
       
    29        * Converts a C-style string array into a .NET managed string array
       
    30        * Parameters
       
    31        *    C-style string array pointer returned from PhysFS
       
    32        * Returns
       
    33        *    .NET managed string array
       
    34        * Exceptions
       
    35        *    none
       
    36        */
       
    37       public unsafe static string[] BytePPToArray(byte **bytearray)
       
    38       {
       
    39          byte** ptr;
       
    40          byte* c;
       
    41          string tempstr;
       
    42          ArrayList MyArrayList = new ArrayList();
       
    43          string[] RetArray;
       
    44 
       
    45          for(ptr = bytearray; *ptr != null; ptr++)
       
    46          {
       
    47             tempstr = "";
       
    48             for(c = *ptr; *c != 0; c++)
       
    49             {
       
    50                tempstr += (char)*c;
       
    51             }
       
    52 
       
    53             // Add string to our list
       
    54             MyArrayList.Add(tempstr);
       
    55          }
       
    56 
       
    57          // Return a normal array of the list
       
    58          RetArray = new string[MyArrayList.Count];
       
    59          MyArrayList.CopyTo(RetArray, 0);
       
    60          return RetArray;
       
    61       }
       
    62 
       
    63       // Name of DLL to import
       
    64       private const string PHYSFS_DLLNAME = "physfs.dll";
       
    65 
       
    66       // DLL import declarations
       
    67       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_init(string argv0);
       
    68       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_deinit();
       
    69       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void PHYSFS_freeList(void *listVar);
       
    70       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getLastError();
       
    71       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getDirSeparator();
       
    72       [DllImport(PHYSFS_DLLNAME)] public static extern void PHYSFS_permitSymbolicLinks(int allow);
       
    73       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_getCdRomDirs();
       
    74       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getBaseDir();
       
    75       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getUserDir();
       
    76       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getWriteDir();
       
    77       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_setWriteDir(string newDir);
       
    78       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_addToSearchPath(string newDir, int appendToPath);
       
    79       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_removeFromSearchPath(string oldDir);
       
    80       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_getSearchPath();
       
    81       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_setSaneConfig(string organization,
       
    82          string appName,
       
    83          string archiveExt,
       
    84          int includeCdRoms,
       
    85          int archivesFirst);
       
    86       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_mkdir(string dirName);
       
    87       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_delete(string filename);
       
    88       [DllImport(PHYSFS_DLLNAME)] public static extern string PHYSFS_getRealDir(string filename);
       
    89       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe byte** PHYSFS_enumerateFiles(string dir);
       
    90       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_exists(string fname);
       
    91       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_isDirectory(string fname);
       
    92       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_isSymbolicLink(string fname);
       
    93       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openWrite(string filename);
       
    94       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openAppend(string filename);
       
    95       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe void* PHYSFS_openRead(string filename);
       
    96       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_close(void* handle);
       
    97       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_getLastModTime(string filename);
       
    98       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_read(void* handle,
       
    99          void *buffer,
       
   100          uint objSize,
       
   101          uint objCount);
       
   102       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_write(void* handle,
       
   103          void *buffer,
       
   104          uint objSize,
       
   105          uint objCount);
       
   106       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_eof(void* handle);
       
   107       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_tell(void* handle);
       
   108       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_seek(void* handle, ulong pos);
       
   109       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe long PHYSFS_fileLength(void* handle);
       
   110       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_setBuffer(void* handle, ulong bufsize);
       
   111       [DllImport(PHYSFS_DLLNAME)] public static extern unsafe int PHYSFS_flush(void* handle);
       
   112    }
       
   113 }