@@ -32,28 +32,6 @@ public unsafe static string GetSearchPath(string pathId, int searchPathType, int
3232 }
3333 }
3434
35- private unsafe static delegate * unmanaged< byte * , byte * , byte > _FileExists ;
36-
37- public unsafe static bool FileExists ( string fileName , string pathId ) {
38- var pool = ArrayPool < byte > . Shared ;
39- var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
40- var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
41- Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
42- fileNameBuffer [ fileNameLength ] = 0 ;
43- var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
44- var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
45- Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
46- pathIdBuffer [ pathIdLength ] = 0 ;
47- fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
48- fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
49- var ret = _FileExists ( fileNameBufferPtr , pathIdBufferPtr ) ;
50- pool . Return ( fileNameBuffer ) ;
51- pool . Return ( pathIdBuffer ) ;
52- return ret == 1 ;
53- }
54- }
55- }
56-
5735 private unsafe static delegate * unmanaged< byte * , byte * , int , int , void > _AddSearchPath ;
5836
5937 public unsafe static void AddSearchPath ( string path , string pathId , int searchPathAdd , int searchPathPriority ) {
@@ -97,6 +75,28 @@ public unsafe static bool RemoveSearchPath(string path, string pathId) {
9775 }
9876 }
9977
78+ private unsafe static delegate * unmanaged< byte * , byte * , byte > _FileExists ;
79+
80+ public unsafe static bool FileExists ( string fileName , string pathId ) {
81+ var pool = ArrayPool < byte > . Shared ;
82+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
83+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
84+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
85+ fileNameBuffer [ fileNameLength ] = 0 ;
86+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
87+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
88+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
89+ pathIdBuffer [ pathIdLength ] = 0 ;
90+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
91+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
92+ var ret = _FileExists ( fileNameBufferPtr , pathIdBufferPtr ) ;
93+ pool . Return ( fileNameBuffer ) ;
94+ pool . Return ( pathIdBuffer ) ;
95+ return ret == 1 ;
96+ }
97+ }
98+ }
99+
100100 private unsafe static delegate * unmanaged< byte * , byte * , byte > _IsDirectory ;
101101
102102 public unsafe static bool IsDirectory ( string path , string pathId ) {
@@ -124,4 +124,149 @@ public unsafe static bool IsDirectory(string path, string pathId) {
124124 public unsafe static void PrintSearchPaths ( ) {
125125 _PrintSearchPaths ( ) ;
126126 }
127+
128+ private unsafe static delegate * unmanaged< byte * , byte * , byte * , int > _ReadFile ;
129+
130+ public unsafe static string ReadFile ( string fileName , string pathId ) {
131+ var pool = ArrayPool < byte > . Shared ;
132+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
133+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
134+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
135+ fileNameBuffer [ fileNameLength ] = 0 ;
136+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
137+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
138+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
139+ pathIdBuffer [ pathIdLength ] = 0 ;
140+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
141+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
142+ var ret = _ReadFile ( null , fileNameBufferPtr , pathIdBufferPtr ) ;
143+ var retBuffer = pool . Rent ( ret + 1 ) ;
144+ fixed ( byte * retBufferPtr = retBuffer ) {
145+ ret = _ReadFile ( retBufferPtr , fileNameBufferPtr , pathIdBufferPtr ) ;
146+ var retString = Encoding . UTF8 . GetString ( retBufferPtr , ret ) ;
147+ pool . Return ( retBuffer ) ;
148+ pool . Return ( fileNameBuffer ) ;
149+ pool . Return ( pathIdBuffer ) ;
150+ return retString ;
151+ }
152+ }
153+ }
154+ }
155+
156+ private unsafe static delegate * unmanaged< byte * , byte * , byte * , byte > _WriteFile ;
157+
158+ public unsafe static bool WriteFile ( string fileName , string pathId , string content ) {
159+ var pool = ArrayPool < byte > . Shared ;
160+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
161+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
162+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
163+ fileNameBuffer [ fileNameLength ] = 0 ;
164+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
165+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
166+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
167+ pathIdBuffer [ pathIdLength ] = 0 ;
168+ var contentLength = Encoding . UTF8 . GetByteCount ( content ) ;
169+ var contentBuffer = pool . Rent ( contentLength + 1 ) ;
170+ Encoding . UTF8 . GetBytes ( content , contentBuffer ) ;
171+ contentBuffer [ contentLength ] = 0 ;
172+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
173+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
174+ fixed ( byte * contentBufferPtr = contentBuffer ) {
175+ var ret = _WriteFile ( fileNameBufferPtr , pathIdBufferPtr , contentBufferPtr ) ;
176+ pool . Return ( fileNameBuffer ) ;
177+ pool . Return ( pathIdBuffer ) ;
178+ pool . Return ( contentBuffer ) ;
179+ return ret == 1 ;
180+ }
181+ }
182+ }
183+ }
184+
185+ private unsafe static delegate * unmanaged< byte * , byte * , uint > _GetFileSize ;
186+
187+ public unsafe static uint GetFileSize ( string fileName , string pathId ) {
188+ var pool = ArrayPool < byte > . Shared ;
189+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
190+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
191+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
192+ fileNameBuffer [ fileNameLength ] = 0 ;
193+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
194+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
195+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
196+ pathIdBuffer [ pathIdLength ] = 0 ;
197+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
198+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
199+ var ret = _GetFileSize ( fileNameBufferPtr , pathIdBufferPtr ) ;
200+ pool . Return ( fileNameBuffer ) ;
201+ pool . Return ( pathIdBuffer ) ;
202+ return ret ;
203+ }
204+ }
205+ }
206+
207+ private unsafe static delegate * unmanaged< byte * , byte * , byte > _PrecacheFile ;
208+
209+ public unsafe static bool PrecacheFile ( string fileName , string pathId ) {
210+ var pool = ArrayPool < byte > . Shared ;
211+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
212+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
213+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
214+ fileNameBuffer [ fileNameLength ] = 0 ;
215+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
216+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
217+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
218+ pathIdBuffer [ pathIdLength ] = 0 ;
219+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
220+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
221+ var ret = _PrecacheFile ( fileNameBufferPtr , pathIdBufferPtr ) ;
222+ pool . Return ( fileNameBuffer ) ;
223+ pool . Return ( pathIdBuffer ) ;
224+ return ret == 1 ;
225+ }
226+ }
227+ }
228+
229+ private unsafe static delegate * unmanaged< byte * , byte * , byte > _IsFileWritable ;
230+
231+ public unsafe static bool IsFileWritable ( string fileName , string pathId ) {
232+ var pool = ArrayPool < byte > . Shared ;
233+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
234+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
235+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
236+ fileNameBuffer [ fileNameLength ] = 0 ;
237+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
238+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
239+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
240+ pathIdBuffer [ pathIdLength ] = 0 ;
241+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
242+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
243+ var ret = _IsFileWritable ( fileNameBufferPtr , pathIdBufferPtr ) ;
244+ pool . Return ( fileNameBuffer ) ;
245+ pool . Return ( pathIdBuffer ) ;
246+ return ret == 1 ;
247+ }
248+ }
249+ }
250+
251+ private unsafe static delegate * unmanaged< byte * , byte * , byte , byte > _SetFileWritable ;
252+
253+ public unsafe static bool SetFileWritable ( string fileName , string pathId , bool writable ) {
254+ var pool = ArrayPool < byte > . Shared ;
255+ var fileNameLength = Encoding . UTF8 . GetByteCount ( fileName ) ;
256+ var fileNameBuffer = pool . Rent ( fileNameLength + 1 ) ;
257+ Encoding . UTF8 . GetBytes ( fileName , fileNameBuffer ) ;
258+ fileNameBuffer [ fileNameLength ] = 0 ;
259+ var pathIdLength = Encoding . UTF8 . GetByteCount ( pathId ) ;
260+ var pathIdBuffer = pool . Rent ( pathIdLength + 1 ) ;
261+ Encoding . UTF8 . GetBytes ( pathId , pathIdBuffer ) ;
262+ pathIdBuffer [ pathIdLength ] = 0 ;
263+ fixed ( byte * fileNameBufferPtr = fileNameBuffer ) {
264+ fixed ( byte * pathIdBufferPtr = pathIdBuffer ) {
265+ var ret = _SetFileWritable ( fileNameBufferPtr , pathIdBufferPtr , writable ? ( byte ) 1 : ( byte ) 0 ) ;
266+ pool . Return ( fileNameBuffer ) ;
267+ pool . Return ( pathIdBuffer ) ;
268+ return ret == 1 ;
269+ }
270+ }
271+ }
127272}
0 commit comments