public static void AddToSearchPath(string NewDir, bool Append) { if (PhysFS_DLL.PHYSFS_addToSearchPath(NewDir, Append?1:0) == 0) { throw new PhysFSException(); } }
public static void RemoveFromSearchPath(string OldDir) { if (PhysFS_DLL.PHYSFS_removeFromSearchPath(OldDir) == 0) { throw new PhysFSException(); } }
public static void MkDir(string Dirname) { if (PhysFS_DLL.PHYSFS_mkdir(Dirname) == 0) { throw new PhysFSException(); } }
public static void Delete(string Filename) { if (PhysFS_DLL.PHYSFS_delete(Filename) == 0) { throw new PhysFSException(); } }
// ***Public methods*** public PhysFSFileStream(string FileName, PhysFSFileMode FileMode, ulong BufferSize) { // Open the specified file with the appropriate file access switch (FileMode) { case PhysFSFileMode.Read: pHandle = PhysFS_DLL.PHYSFS_openRead(FileName); break; case PhysFSFileMode.Write: pHandle = PhysFS_DLL.PHYSFS_openWrite(FileName); break; case PhysFSFileMode.Append: pHandle = PhysFS_DLL.PHYSFS_openAppend(FileName); break; default: throw new PhysFSException("Invalid FileMode specified"); } // If handle is null, an error occured, so raise an exception //!!! Does object get created if exception is thrown? if (pHandle == null) { throw new PhysFSException(); } // Set buffer size, raise an exception if an error occured if (PhysFS_DLL.PHYSFS_setBuffer(pHandle, BufferSize) == 0) { throw new PhysFSException(); } }
public override void Flush() { if (PhysFS_DLL.PHYSFS_flush(pHandle) == 0) { throw new PhysFSException(); } }
/* Deinitialize * Deinits the PhysFS API. It is recommended that this method be called * by the application before exiting in order to gracefully deallocate * resources and close all filehandles, etc. * Parameters * none * Returns * none * Exceptions * PhysFSException - An error occured in the PhysFS API */ public static void Deinitialize() { // Deinit, raise an exception if an error occured if (PhysFS_DLL.PHYSFS_deinit() == 0) { throw new PhysFSException(); } }
/* Initialize * Inits the PhysFS API. This normally does not need to be called unless * the API has been manually deinitialized since the PhysFS_DLL class * initializes just before the first call is made into the DLL. * Parameters * none * Returns * none * Exceptions * PhysFSException - An error occured in the PhysFS API */ public static void Initialize() { // Initialize the physfs library, raise an exception if error if (PhysFS_DLL.PHYSFS_init("") == 0) { throw new PhysFSException(); } }
public override void Close() { // Close the handle if (PhysFS_DLL.PHYSFS_close(pHandle) == 0) { throw new PhysFSException(); } // File has been closed. Rock. Closed = true; }
public static string GetRealDir(string Filename) { string RetValue; RetValue = PhysFS_DLL.PHYSFS_getRealDir(Filename); if (RetValue == null) { throw new PhysFSException("File not found in search path."); } // Return the real file path of the specified filename return(RetValue); }
public unsafe static string[] GetSearchPath() { byte **p; // Searchpath list from PhysFS dll string[] pathlist; // List converted to an array // Get the CDROM drive listing p = PhysFS_DLL.PHYSFS_getSearchPath(); // Convert the C-style array to a .NET style array pathlist = PhysFS_DLL.BytePPToArray(p); // Free the original list since we're done with it PhysFS_DLL.PHYSFS_freeList(p); return(pathlist); }
public unsafe static string[] EnumerateFiles(string Dirname) { byte **p; // File list from PhysFS dll string[] filelist; // List converted to an array // Get the CDROM drive listing p = PhysFS_DLL.PHYSFS_enumerateFiles(Dirname); // Convert the C-style array to a .NET style array filelist = PhysFS_DLL.BytePPToArray(p); // Free the original list since we're done with it PhysFS_DLL.PHYSFS_freeList(p); return(filelist); }
public override void Write(byte[] buffer, int offset, int count) { long RetValue; fixed(byte *pbytes = &buffer[offset]) { // Write buffer RetValue = PhysFS_DLL.PHYSFS_write(pHandle, pbytes, sizeof(byte), (uint)count); } if (RetValue == -1) { throw new PhysFSException(); } }
public unsafe static string[] GetCDROMDrives() { byte **p; // CDROM list from PhysFS dll string[] cdromlist; // List converted to an array // Get the CDROM drive listing p = PhysFS_DLL.PHYSFS_getCdRomDirs(); // Convert the C-style array to a .NET style array cdromlist = PhysFS_DLL.BytePPToArray(p); // Free the original list since we're done with it PhysFS_DLL.PHYSFS_freeList(p); return(cdromlist); }
public override long Seek(long offset, SeekOrigin origin) { // Only seeking from beginning is supported by PhysFS API if (origin != SeekOrigin.Begin) { throw new PhysFSException("Only seek origin of \"Begin\" is supported"); } // Seek to specified offset, raise an exception if error occured if (PhysFS_DLL.PHYSFS_seek(pHandle, (ulong)offset) == 0) { throw new PhysFSException(); } // Since we always seek from beginning, the offset is always // the absolute position. return(offset); }
public override int Read(byte[] buffer, int offset, int count) { long RetValue; fixed(byte *pbytes = &buffer[offset]) { // Read into our allocated pointer RetValue = PhysFS_DLL.PHYSFS_read(pHandle, pbytes, sizeof(byte), (uint)count); } if (RetValue == -1) { throw new PhysFSException(); } // Return number of bytes read // Note: This cast should be safe since we are only reading 'count' items, which // is of type 'int'. return((int)RetValue); }
public static bool IsDirectory(string Filename) { // Return true if non-zero, otherwise return false return((PhysFS_DLL.PHYSFS_isDirectory(Filename) == 0)?false:true); }
public PhysFSException() : base(PhysFS_DLL.PHYSFS_getLastError()) { }