1 /* PhysFS.cs - (c)2003 Gregory S. Read
2 * Provides access to PhysFS API calls not specific to file handle access.
11 * Inits the PhysFS API. This normally does not need to be called unless
12 * the API has been manually deinitialized since the PhysFS_DLL class
13 * initializes just before the first call is made into the DLL.
19 * PhysFSException - An error occured in the PhysFS API
21 public static void Initialize()
23 // Initialize the physfs library, raise an exception if error
24 if(PhysFS_DLL.PHYSFS_init("") == 0)
25 throw new PhysFSException();
29 * Deinits the PhysFS API. It is recommended that this method be called
30 * by the application before exiting in order to gracefully deallocate
31 * resources and close all filehandles, etc.
37 * PhysFSException - An error occured in the PhysFS API
39 public static void Deinitialize()
41 // Deinit, raise an exception if an error occured
42 if(PhysFS_DLL.PHYSFS_deinit() == 0)
43 throw new PhysFSException();
47 * Gets the base directory configured for PhysFS. See the PhysFS API
48 * documentation for more information.
52 * A string value representing the Base Directory
56 public static string BaseDir
60 // Return the current base directory
61 return PhysFS_DLL.PHYSFS_getBaseDir();
66 * Gets or sets the write directory configured for PhysFS. See the PhysFS API
67 * documentation for more information.
69 * set - Path to set the WriteDir property to
71 * A string value representing the Write Directory
73 * PhysFSException - An error occured in the PhysFS API when
74 * settings the write directory.
76 public static string WriteDir
80 // Return the current write directory
81 return PhysFS_DLL.PHYSFS_getWriteDir();
85 // Set the write directory and raise an exception if an error occured
86 if(PhysFS_DLL.PHYSFS_setWriteDir(value) == 0)
87 throw new PhysFSException();
92 * Gets or sets the write directory configured for PhysFS. See the PhysFS API
93 * documentation for more information.
95 * set - Path to set the WriteDir property to
97 * A string value representing the Write Directory
99 * PhysFSException - An error occured in the PhysFS API when
100 * settings the write directory.
102 public static string UserDir
106 // Return the current user directory
107 return PhysFS_DLL.PHYSFS_getUserDir();
110 public static void AddToSearchPath(string NewDir, bool Append)
112 if(PhysFS_DLL.PHYSFS_addToSearchPath(NewDir, Append?1:0) == 0)
113 throw new PhysFSException();
115 public static void RemoveFromSearchPath(string OldDir)
117 if(PhysFS_DLL.PHYSFS_removeFromSearchPath(OldDir) == 0)
118 throw new PhysFSException();
120 public unsafe static string[] GetSearchPath()
122 byte** p; // Searchpath list from PhysFS dll
123 string[] pathlist; // List converted to an array
125 // Get the CDROM drive listing
126 p = PhysFS_DLL.PHYSFS_getSearchPath();
127 // Convert the C-style array to a .NET style array
128 pathlist = PhysFS_DLL.BytePPToArray(p);
129 // Free the original list since we're done with it
130 PhysFS_DLL.PHYSFS_freeList(p);
134 public unsafe static string[] GetCDROMDrives()
136 byte** p; // CDROM list from PhysFS dll
137 string[] cdromlist; // List converted to an array
139 // Get the CDROM drive listing
140 p = PhysFS_DLL.PHYSFS_getCdRomDirs();
141 // Convert the C-style array to a .NET style array
142 cdromlist = PhysFS_DLL.BytePPToArray(p);
143 // Free the original list since we're done with it
144 PhysFS_DLL.PHYSFS_freeList(p);
148 public static void MkDir(string Dirname)
150 if(PhysFS_DLL.PHYSFS_mkdir(Dirname) == 0)
151 throw new PhysFSException();
153 public static void Delete(string Filename)
155 if(PhysFS_DLL.PHYSFS_delete(Filename) == 0)
156 throw new PhysFSException();
158 public static string GetRealDir(string Filename)
162 RetValue = PhysFS_DLL.PHYSFS_getRealDir(Filename);
164 throw new PhysFSException("File not found in search path.");
166 // Return the real file path of the specified filename
169 public unsafe static string[] EnumerateFiles(string Dirname)
171 byte** p; // File list from PhysFS dll
172 string[] filelist; // List converted to an array
174 // Get the CDROM drive listing
175 p = PhysFS_DLL.PHYSFS_enumerateFiles(Dirname);
176 // Convert the C-style array to a .NET style array
177 filelist = PhysFS_DLL.BytePPToArray(p);
178 // Free the original list since we're done with it
179 PhysFS_DLL.PHYSFS_freeList(p);
183 public static bool IsDirectory(string Filename)
185 // Return true if non-zero, otherwise return false
186 return (PhysFS_DLL.PHYSFS_isDirectory(Filename) == 0)?false:true;