Skip to content

Latest commit

 

History

History
executable file
·
189 lines (176 loc) · 6.21 KB

PhysFS.cs

File metadata and controls

executable file
·
189 lines (176 loc) · 6.21 KB
 
Jan 7, 2003
Jan 7, 2003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* PhysFS.cs - (c)2003 Gregory S. Read
* Provides access to PhysFS API calls not specific to file handle access.
*/
using System;
namespace PhysFS_NET
{
public class PhysFS
{
/* 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();
}
/* 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();
}
/* BaseDir
* Gets the base directory configured for PhysFS. See the PhysFS API
* documentation for more information.
* Parameters
* none
* Returns
* A string value representing the Base Directory
* Exceptions
* none
*/
public static string BaseDir
{
get
{
// Return the current base directory
return PhysFS_DLL.PHYSFS_getBaseDir();
}
}
/* WriteDir
* Gets or sets the write directory configured for PhysFS. See the PhysFS API
* documentation for more information.
* Parameters
* set - Path to set the WriteDir property to
* Returns
* A string value representing the Write Directory
* Exceptions
* PhysFSException - An error occured in the PhysFS API when
* settings the write directory.
*/
public static string WriteDir
{
get
{
// Return the current write directory
return PhysFS_DLL.PHYSFS_getWriteDir();
}
set
{
// Set the write directory and raise an exception if an error occured
if(PhysFS_DLL.PHYSFS_setWriteDir(value) == 0)
throw new PhysFSException();
}
}
/* UserDir
* Gets or sets the write directory configured for PhysFS. See the PhysFS API
* documentation for more information.
* Parameters
* set - Path to set the WriteDir property to
* Returns
* A string value representing the Write Directory
* Exceptions
* PhysFSException - An error occured in the PhysFS API when
* settings the write directory.
*/
public static string UserDir
{
get
{
// Return the current user directory
return PhysFS_DLL.PHYSFS_getUserDir();
}
}
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 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[] 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 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 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[] 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 static bool IsDirectory(string Filename)
{
// Return true if non-zero, otherwise return false
return (PhysFS_DLL.PHYSFS_isDirectory(Filename) == 0)?false:true;
}
}
}