comparison dstep/foundation/NSFileManager.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 7ff919f595d5
comparison
equal deleted inserted replaced
13:4f583f7e242e 14:89f3c3ef1fd2
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Aug 3, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.foundation.NSFileManager;
8
9 import dstep.corefoundation.CFBase;
10 import dstep.foundation.NSArray;
11 import dstep.foundation.NSData;
12 import dstep.foundation.NSDate;
13 import dstep.foundation.NSDictionary;
14 import dstep.foundation.NSDirectoryEnumerator;
15 import dstep.foundation.NSEnumerator;
16 import dstep.foundation.NSError;
17 import dstep.foundation.NSNumber;
18 import dstep.foundation.NSObject;
19 import dstep.objc.bridge.Bridge;
20 import dstep.objc.objc : id;
21
22 import bindings = dstep.foundation.NSFileManager_bindings;
23
24 const NSString NSFileType;
25 const NSString NSFileTypeDirectory;
26 const NSString NSFileTypeRegular;
27 const NSString NSFileTypeSymbolicLink;
28 const NSString NSFileTypeSocket;
29 const NSString NSFileTypeCharacterSpecial;
30 const NSString NSFileTypeBlockSpecial;
31 const NSString NSFileTypeUnknown;
32 const NSString NSFileSize;
33 const NSString NSFileModificationDate;
34 const NSString NSFileReferenceCount;
35 const NSString NSFileDeviceIdentifier;
36 const NSString NSFileOwnerAccountName;
37 const NSString NSFileGroupOwnerAccountName;
38 const NSString NSFilePosixPermissions;
39 const NSString NSFileSystemNumber;
40 const NSString NSFileSystemFileNumber;
41 const NSString NSFileExtensionHidden;
42 const NSString NSFileHFSCreatorCode;
43 const NSString NSFileHFSTypeCode;
44 const NSString NSFileImmutable;
45 const NSString NSFileAppendOnly;
46 const NSString NSFileCreationDate;
47 const NSString NSFileOwnerAccountID;
48 const NSString NSFileGroupOwnerAccountID;
49 const NSString NSFileBusy;
50 const NSString NSFileSystemSize;
51 const NSString NSFileSystemFreeSize;
52 const NSString NSFileSystemNodes;
53 const NSString NSFileSystemFreeNodes;
54
55 static this ()
56 {
57 NSFileType = new NSString(bindings.NSFileType);
58 NSFileTypeDirectory = new NSString(bindings.NSFileTypeDirectory);
59 NSFileTypeRegular = new NSString(bindings.NSFileTypeRegular);
60 NSFileTypeSymbolicLink = new NSString(bindings.NSFileTypeSymbolicLink);
61 NSFileTypeSocket = new NSString(bindings.NSFileTypeSocket);
62 NSFileTypeCharacterSpecial = new NSString(bindings.NSFileTypeCharacterSpecial);
63 NSFileTypeBlockSpecial = new NSString(bindings.NSFileTypeBlockSpecial);
64 NSFileTypeUnknown = new NSString(bindings.NSFileTypeUnknown);
65 NSFileSize = new NSString(bindings.NSFileSize);
66 NSFileModificationDate = new NSString(bindings.NSFileModificationDate);
67 NSFileReferenceCount = new NSString(bindings.NSFileReferenceCount);
68 NSFileDeviceIdentifier = new NSString(bindings.NSFileDeviceIdentifier);
69 NSFileOwnerAccountName = new NSString(bindings.NSFileOwnerAccountName);
70 NSFileGroupOwnerAccountName = new NSString(bindings.NSFileGroupOwnerAccountName);
71 NSFilePosixPermissions = new NSString(bindings.NSFilePosixPermissions);
72 NSFileSystemNumber = new NSString(bindings.NSFileSystemNumber);
73 NSFileSystemFileNumber = new NSString(bindings.NSFileSystemFileNumber);
74 NSFileExtensionHidden = new NSString(bindings.NSFileExtensionHidden);
75 NSFileHFSCreatorCode = new NSString(bindings.NSFileHFSCreatorCode);
76 NSFileHFSTypeCode = new NSString(bindings.NSFileHFSTypeCode);
77 NSFileImmutable = new NSString(bindings.NSFileImmutable);
78 NSFileAppendOnly = new NSString(bindings.NSFileAppendOnly);
79 NSFileCreationDate = new NSString(bindings.NSFileCreationDate);
80 NSFileOwnerAccountID = new NSString(bindings.NSFileOwnerAccountID);
81 NSFileGroupOwnerAccountID = new NSString(bindings.NSFileGroupOwnerAccountID);
82 NSFileBusy = new NSString(bindings.NSFileBusy);
83 NSFileSystemSize = new NSString(bindings.NSFileSystemSize);
84 NSFileSystemFreeSize = new NSString(bindings.NSFileSystemFreeSize);
85 NSFileSystemNodes = new NSString(bindings.NSFileSystemNodes);
86 NSFileSystemFreeNodes = new NSString(bindings.NSFileSystemFreeNodes);
87 }
88
89 class NSFileManager : NSObject
90 {
91 mixin ObjcWrap;
92
93 static NSFileManager defaultManager ()
94 {
95 return invokeObjcSelfClass!(NSFileManager, "defaultManager"return result is this.objcObject ? this : (result !is null ? new NSFileManager(result) : null); }
96
97 void setDelegate (Object delegate_)
98 {
99 return invokeObjcSelf!(void, "setDelegate:", Object)(delegate_);
100 }
101
102 Object delegate_ ()
103 {
104 return invokeObjcSelf!(Object, "delegate");
105 }
106
107 bool setAttributes (NSDictionary attributes, NSString path, NSError** error)
108 {
109 return invokeObjcSelf!(bool, "setAttributes:ofItemAtPath:error:", NSDictionary, NSString, NSError**)(attributes, path, error);
110 }
111
112 bool createDirectoryAtPath (NSString path, bool createIntermediates, NSDictionary attributes, NSError** error)
113 {
114 return invokeObjcSelf!(bool, "createDirectoryAtPath:withIntermediateDirectories:attributes:error:", NSString, bool, NSDictionary, NSError**)(path, createIntermediates, attributes, error);
115 }
116
117 NSArray contentsOfDirectoryAtPath (NSString path, NSError** error)
118 {
119 return invokeObjcSelf!(NSArray, "contentsOfDirectoryAtPath:error:", NSString, NSError**)(path, error);
120 }
121
122 NSArray subpathsOfDirectoryAtPath (NSString path, NSError** error)
123 {
124 return invokeObjcSelf!(NSArray, "subpathsOfDirectoryAtPath:error:", NSString, NSError**)(path, error);
125 }
126
127 NSDictionary attributesOfItemAtPath (NSString path, NSError** error)
128 {
129 return invokeObjcSelf!(NSDictionary, "attributesOfItemAtPath:error:", NSString, NSError**)(path, error);
130 }
131
132 NSDictionary attributesOfFileSystemForPath (NSString path, NSError** error)
133 {
134 return invokeObjcSelf!(NSDictionary, "attributesOfFileSystemForPath:error:", NSString, NSError**)(path, error);
135 }
136
137 bool createSymbolicLinkAtPath (NSString path, NSString destPath, NSError** error)
138 {
139 return invokeObjcSelf!(bool, "createSymbolicLinkAtPath:withDestinationPath:error:", NSString, NSString, NSError**)(path, destPath, error);
140 }
141
142 NSString destinationOfSymbolicLinkAtPath (NSString path, NSError** error)
143 {
144 return invokeObjcSelf!(NSString, "destinationOfSymbolicLinkAtPath:error:", NSString, NSError**)(path, error);
145 }
146
147 bool copyItemAtPath (NSString srcPath, NSString dstPath, NSError** error)
148 {
149 return invokeObjcSelf!(bool, "copyItemAtPath:toPath:error:", NSString, NSString, NSError**)(srcPath, dstPath, error);
150 }
151
152 bool moveItemAtPath (NSString srcPath, NSString dstPath, NSError** error)
153 {
154 return invokeObjcSelf!(bool, "moveItemAtPath:toPath:error:", NSString, NSString, NSError**)(srcPath, dstPath, error);
155 }
156
157 bool linkItemAtPath (NSString srcPath, NSString dstPath, NSError** error)
158 {
159 return invokeObjcSelf!(bool, "linkItemAtPath:toPath:error:", NSString, NSString, NSError**)(srcPath, dstPath, error);
160 }
161
162 bool removeItemAtPath (NSString path, NSError** error)
163 {
164 return invokeObjcSelf!(bool, "removeItemAtPath:error:", NSString, NSError**)(path, error);
165 }
166
167 NSDictionary fileAttributesAtPath (NSString path, bool yorn)
168 {
169 return invokeObjcSelf!(NSDictionary, "fileAttributesAtPath:traverseLink:", NSString, bool)(path, yorn);
170 }
171
172 bool changeFileAttributes (NSDictionary attributes, NSString path)
173 {
174 return invokeObjcSelf!(bool, "changeFileAttributes:atPath:", NSDictionary, NSString)(attributes, path);
175 }
176
177 NSArray directoryContentsAtPath (NSString path)
178 {
179 return invokeObjcSelf!(NSArray, "directoryContentsAtPath:", NSString)(path);
180 }
181
182 NSDictionary fileSystemAttributesAtPath (NSString path)
183 {
184 return invokeObjcSelf!(NSDictionary, "fileSystemAttributesAtPath:", NSString)(path);
185 }
186
187 NSString pathContentOfSymbolicLinkAtPath (NSString path)
188 {
189 return invokeObjcSelf!(NSString, "pathContentOfSymbolicLinkAtPath:", NSString)(path);
190 }
191
192 bool createSymbolicLinkAtPath (NSString path, NSString otherpath)
193 {
194 return invokeObjcSelf!(bool, "createSymbolicLinkAtPath:pathContent:", NSString, NSString)(path, otherpath);
195 }
196
197 bool createDirectoryAtPath (NSString path, NSDictionary attributes)
198 {
199 return invokeObjcSelf!(bool, "createDirectoryAtPath:attributes:", NSString, NSDictionary)(path, attributes);
200 }
201
202 bool linkPath (NSString src, NSString dest, Object handler)
203 {
204 return invokeObjcSelf!(bool, "linkPath:toPath:handler:", NSString, NSString, Object)(src, dest, handler);
205 }
206
207 bool copyPath (NSString src, NSString dest, Object handler)
208 {
209 return invokeObjcSelf!(bool, "copyPath:toPath:handler:", NSString, NSString, Object)(src, dest, handler);
210 }
211
212 bool movePath (NSString src, NSString dest, Object handler)
213 {
214 return invokeObjcSelf!(bool, "movePath:toPath:handler:", NSString, NSString, Object)(src, dest, handler);
215 }
216
217 bool removeFileAtPath (NSString path, Object handler)
218 {
219 return invokeObjcSelf!(bool, "removeFileAtPath:handler:", NSString, Object)(path, handler);
220 }
221
222 NSString currentDirectoryPath ()
223 {
224 return invokeObjcSelf!(NSString, "currentDirectoryPath");
225 }
226
227 bool changeCurrentDirectoryPath (NSString path)
228 {
229 return invokeObjcSelf!(bool, "changeCurrentDirectoryPath:", NSString)(path);
230 }
231
232 bool fileExistsAtPath (NSString path)
233 {
234 return invokeObjcSelf!(bool, "fileExistsAtPath:", NSString)(path);
235 }
236
237 bool fileExistsAtPath (NSString path, bool* isDirectory)
238 {
239 return invokeObjcSelf!(bool, "fileExistsAtPath:isDirectory:", NSString, bool*)(path, isDirectory);
240 }
241
242 bool isReadableFileAtPath (NSString path)
243 {
244 return invokeObjcSelf!(bool, "isReadableFileAtPath:", NSString)(path);
245 }
246
247 bool isWritableFileAtPath (NSString path)
248 {
249 return invokeObjcSelf!(bool, "isWritableFileAtPath:", NSString)(path);
250 }
251
252 bool isExecutableFileAtPath (NSString path)
253 {
254 return invokeObjcSelf!(bool, "isExecutableFileAtPath:", NSString)(path);
255 }
256
257 bool isDeletableFileAtPath (NSString path)
258 {
259 return invokeObjcSelf!(bool, "isDeletableFileAtPath:", NSString)(path);
260 }
261
262 bool contentsEqualAtPath (NSString path1, NSString path2)
263 {
264 return invokeObjcSelf!(bool, "contentsEqualAtPath:andPath:", NSString, NSString)(path1, path2);
265 }
266
267 NSString displayNameAtPath (NSString path)
268 {
269 return invokeObjcSelf!(NSString, "displayNameAtPath:", NSString)(path);
270 }
271
272 NSArray componentsToDisplayForPath (NSString path)
273 {
274 return invokeObjcSelf!(NSArray, "componentsToDisplayForPath:", NSString)(path);
275 }
276
277 NSDirectoryEnumerator enumeratorAtPath (NSString path)
278 {
279 return invokeObjcSelf!(NSDirectoryEnumerator, "enumeratorAtPath:", NSString)(path);
280 }
281
282 NSArray subpathsAtPath (NSString path)
283 {
284 return invokeObjcSelf!(NSArray, "subpathsAtPath:", NSString)(path);
285 }
286
287 NSData contentsAtPath (NSString path)
288 {
289 return invokeObjcSelf!(NSData, "contentsAtPath:", NSString)(path);
290 }
291
292 bool createFileAtPath (NSString path, NSData data, NSDictionary attr)
293 {
294 return invokeObjcSelf!(bool, "createFileAtPath:contents:attributes:", NSString, NSData, NSDictionary)(path, data, attr);
295 }
296
297 char* fileSystemRepresentationWithPath (NSString path)
298 {
299 return invokeObjcSelf!(char*, "fileSystemRepresentationWithPath:", NSString)(path);
300 }
301
302 NSString stringWithFileSystemRepresentation (char* str, NSUInteger len)
303 {
304 return invokeObjcSelf!(NSString, "stringWithFileSystemRepresentation:length:", char*, NSUInteger)(str, len);
305 }
306 }
307
308 class NSDirectoryEnumerator : NSEnumerator
309 {
310 mixin ObjcWrap;
311
312 NSDictionary fileAttributes ()
313 {
314 return invokeObjcSelf!(NSDictionary, "fileAttributes");
315 }
316
317 NSDictionary directoryAttributes ()
318 {
319 return invokeObjcSelf!(NSDictionary, "directoryAttributes");
320 }
321
322 void skipDescendents ()
323 {
324 return invokeObjcSelf!(void, "skipDescendents");
325 }
326 }
327
328 template TNSFileManagerFileOperationAdditions ()
329 {
330 bool fileManager (NSFileManager fileManager, NSString srcPath, NSString dstPath);
331 bool fileManager (NSFileManager fileManager, NSError error, NSString srcPath, NSString dstPath);
332 bool fileManager (NSFileManager fileManager, NSString srcPath, NSString dstPath);
333 bool fileManager (NSFileManager fileManager, NSError error, NSString srcPath, NSString dstPath);
334 bool fileManager (NSFileManager fileManager, NSString srcPath, NSString dstPath);
335 bool fileManager (NSFileManager fileManager, NSError error, NSString srcPath, NSString dstPath);
336 bool fileManager (NSFileManager fileManager, NSString path);
337 bool fileManager (NSFileManager fileManager, NSError error, NSString path);
338 }
339
340 template TNSCopyLinkMoveHandler ()
341 {
342 bool fileManager (NSFileManager fm, NSDictionary errorInfo);
343 void fileManager (NSFileManager fm, NSString path);
344 }
345
346 template TNSFileAttributes ()
347 {
348 ulong fileSize ()
349 {
350 return invokeObjcSelf!(ulong, "fileSize");
351 }
352
353 NSDate fileModificationDate ()
354 {
355 return invokeObjcSelf!(NSDate, "fileModificationDate");
356 }
357
358 NSString fileType ()
359 {
360 return invokeObjcSelf!(NSString, "fileType");
361 }
362
363 NSUInteger filePosixPermissions ()
364 {
365 return invokeObjcSelf!(NSUInteger, "filePosixPermissions");
366 }
367
368 NSString fileOwnerAccountName ()
369 {
370 return invokeObjcSelf!(NSString, "fileOwnerAccountName");
371 }
372
373 NSString fileGroupOwnerAccountName ()
374 {
375 return invokeObjcSelf!(NSString, "fileGroupOwnerAccountName");
376 }
377
378 NSInteger fileSystemNumber ()
379 {
380 return invokeObjcSelf!(NSInteger, "fileSystemNumber");
381 }
382
383 NSUInteger fileSystemFileNumber ()
384 {
385 return invokeObjcSelf!(NSUInteger, "fileSystemFileNumber");
386 }
387
388 bool fileExtensionHidden ()
389 {
390 return invokeObjcSelf!(bool, "fileExtensionHidden");
391 }
392
393 uint fileHFSCreatorCode ()
394 {
395 return invokeObjcSelf!(uint, "fileHFSCreatorCode");
396 }
397
398 uint fileHFSTypeCode ()
399 {
400 return invokeObjcSelf!(uint, "fileHFSTypeCode");
401 }
402
403 bool fileIsImmutable ()
404 {
405 return invokeObjcSelf!(bool, "fileIsImmutable");
406 }
407
408 bool fileIsAppendOnly ()
409 {
410 return invokeObjcSelf!(bool, "fileIsAppendOnly");
411 }
412
413 NSDate fileCreationDate ()
414 {
415 return invokeObjcSelf!(NSDate, "fileCreationDate");
416 }
417
418 NSNumber fileOwnerAccountID ()
419 {
420 return invokeObjcSelf!(NSNumber, "fileOwnerAccountID");
421 }
422
423 NSNumber fileGroupOwnerAccountID ()
424 {
425 return invokeObjcSelf!(NSNumber, "fileGroupOwnerAccountID");
426 }
427 }
428