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