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