bc9300c0c7eabce4e3b31c24019e1f78b1cb4647
[physicsfs] / extras / PhysFS.NET / PhysFS_DLL.cs
1 /* PhysFS_DLL - (c)2003 Gregory S. Read\r
2  * Internal class that provides direct access to the PhysFS DLL.  It is\r
3  * not accessible outside of the PhysFS.NET assembly.\r
4  */\r
5 using System.Collections;\r
6 using System.Runtime.InteropServices;\r
7 \r
8 namespace PhysFS_NET\r
9 {\r
10    internal class PhysFS_DLL\r
11    {\r
12       /* Static constructor\r
13        * Initializes the PhysFS API before any method is called in this class.  This\r
14        * relieves the user from having to explicitly initialize the API.\r
15        * Parameters\r
16        *    none\r
17        * Returns\r
18        *    none\r
19        * Exceptions\r
20        *    PhysFSException - An error occured in the PhysFS API\r
21        */\r
22       static PhysFS_DLL()\r
23       {\r
24          if(PHYSFS_init("") == 0)\r
25             throw new PhysFSException();\r
26       }\r
27 \r
28       /* BytePPToArray\r
29        * Converts a C-style string array into a .NET managed string array\r
30        * Parameters\r
31        *    C-style string array pointer returned from PhysFS\r
32        * Returns\r
33        *    .NET managed string array\r
34        * Exceptions\r
35        *    none\r
36        */\r
37       public unsafe static string[] BytePPToArray(byte **bytearray)\r
38       {\r
39          byte** ptr;\r
40          byte* c;\r
41          string tempstr;\r
42          ArrayList MyArrayList = new ArrayList();\r
43          string[] RetArray;\r
44 \r
45          for(ptr = bytearray; *ptr != null; ptr++)
46          {
47             tempstr = "";
48             for(c = *ptr; *c != 0; c++)
49             {
50                tempstr += (char)*c;\r
51             }\r
52 \r
53             // Add string to our list\r
54             MyArrayList.Add(tempstr);\r
55          }\r
56 \r
57          // Return a normal array of the list\r
58          RetArray = new string[MyArrayList.Count];\r
59          MyArrayList.CopyTo(RetArray, 0);\r
60          return RetArray;\r
61       }\r
62 \r
63       // Name of DLL to import\r
64       private const string PHYSFS_DLLNAME = "physfs.dll";\r
65 \r
66       // DLL import declarations\r
67       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_init(string argv0);\r
68       [DllImport(PHYSFS_DLLNAME)] public static extern int PHYSFS_deinit();\r
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();\r
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);\r
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    }\r
113 }\r