PhysFS_DLL.cs 5.3 KB

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