Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
JAPersistentFileReference.h File Reference
import <Foundation/Foundation.h>
+ Include dependency graph for JAPersistentFileReference.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef uint32_t JAPersistentFileReferenceResolveFlags
 

Enumerations

enum  { kJAPersistentFileReferenceWithoutUI = 0x00000001UL , kJAPersistentFileReferenceWithoutMounting = 0x00000002UL , kJAPersistentFileReferenceReturnReferenceURL = 0x00000004UL }
 

Functions

NSDictionary * JAPersistentFileReferenceFromURL (NSURL *url)
 
NSURL * JAURLFromPersistentFileReference (NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
 
NSDictionary * JAPersistentFileReferenceFromPath (NSString *path)
 
NSString * JAPathFromPersistentFileReference (NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
 

Typedef Documentation

◆ JAPersistentFileReferenceResolveFlags

Definition at line 42 of file JAPersistentFileReference.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kJAPersistentFileReferenceWithoutUI 
kJAPersistentFileReferenceWithoutMounting 
kJAPersistentFileReferenceReturnReferenceURL 

Definition at line 35 of file JAPersistentFileReference.h.

36{
37 kJAPersistentFileReferenceWithoutUI = 0x00000001UL, // Avoid user interaction.
38 kJAPersistentFileReferenceWithoutMounting = 0x00000002UL, // Avoid mounting volumes.
39 kJAPersistentFileReferenceReturnReferenceURL = 0x00000004UL // Return a file reference URL if possible.
40};
@ kJAPersistentFileReferenceReturnReferenceURL
@ kJAPersistentFileReferenceWithoutUI
@ kJAPersistentFileReferenceWithoutMounting

Function Documentation

◆ JAPathFromPersistentFileReference()

NSString * JAPathFromPersistentFileReference ( NSDictionary * fileRef,
JAPersistentFileReferenceResolveFlags flags,
BOOL * isStale )

Definition at line 239 of file JAPersistentFileReference.m.

240{
242 if ([url isFileURL]) return [url path];
243 return nil;
244}
NSURL * JAURLFromPersistentFileReference(NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
return nil

References JAURLFromPersistentFileReference(), kJAPersistentFileReferenceReturnReferenceURL, and nil.

+ Here is the call graph for this function:

◆ JAPersistentFileReferenceFromPath()

NSDictionary * JAPersistentFileReferenceFromPath ( NSString * path)

Definition at line 233 of file JAPersistentFileReference.m.

234{
235 return JAPersistentFileReferenceFromURL([NSURL fileURLWithPath:path]);
236}
NSDictionary * JAPersistentFileReferenceFromURL(NSURL *url)

References JAPersistentFileReferenceFromURL().

+ Here is the call graph for this function:

◆ JAPersistentFileReferenceFromURL()

NSDictionary * JAPersistentFileReferenceFromURL ( NSURL * url)

Definition at line 71 of file JAPersistentFileReference.m.

72{
73 if (url == nil) return nil;
74
75 NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:3];
76 [result setObject:[url absoluteString] forKey:kURLKey];
77
78 if ([url isFileURL])
79 {
80 FSRef fsRef;
81 if (CFURLGetFSRef((CFURLRef)[url absoluteURL], &fsRef))
82 {
83 AliasHandle alias = NULL;
84 if (FSNewAlias(NULL, &fsRef, &alias) == noErr)
85 {
86 NSData *aliasData = [NSData dataWithBytes:*alias length:GetAliasSize(alias)];
87 if (aliasData != NULL)
88 {
89 [result setObject:aliasData forKey:kAliasKey];
90 }
91 DisposeHandle((Handle)alias);
92 }
93 }
94 }
95
97 {
98 NSURL *refURL = [url fileReferenceURL];
99 if (refURL != nil)
100 {
101 NSData *bookmarkData = [refURL bookmarkDataWithOptions:0
102 includingResourceValuesForKeys:nil
103 relativeToURL:nil
104 error:NULL];
105 if (bookmarkData != nil)
106 {
107 [result setObject:bookmarkData forKey:kBookmarkKey];
108 }
109 }
110 }
111
112 return result;
113}
#define kURLKey
#define kAliasKey
#define BookmarkDataSupported()
#define kBookmarkKey

References BookmarkDataSupported, and nil.

Referenced by JAPersistentFileReferenceFromPath().

+ Here is the caller graph for this function:

◆ JAURLFromPersistentFileReference()

NSURL * JAURLFromPersistentFileReference ( NSDictionary * fileRef,
JAPersistentFileReferenceResolveFlags flags,
BOOL * isStale )

Definition at line 133 of file JAPersistentFileReference.m.

134{
135 NSURL *result = nil;
136 BOOL stale = NO, staleIfFile = NO;
137
138 // Try bookmark.
140 {
141 NSData *bookmarkData = [fileRef objectForKey:kBookmarkKey];
142 if ([bookmarkData isKindOfClass:[NSData class]])
143 {
144 result = [NSURL URLByResolvingBookmarkData:bookmarkData
145 options:BookmarkOptionsFromFlags(flags)
146 relativeToURL:nil
147 bookmarkDataIsStale:&stale
148 error:NULL];
149 }
150 else staleIfFile = YES;
151 }
152
153 // Try alias.
154 if (result == nil)
155 {
156 NSData *aliasData = [fileRef objectForKey:kAliasKey];
157 if ([aliasData isKindOfClass:[NSData class]])
158 {
159 size_t size = [aliasData length];
160 AliasHandle alias = (AliasHandle)NewHandle(size);
161 if (alias != NULL)
162 {
163 memcpy(*alias, [aliasData bytes], size);
164 FSRef fsRef;
165
166 Boolean carbonStale;
167 if (FSResolveAliasWithMountFlags(NULL, alias, &fsRef, &carbonStale, AliasMountFlagsFromFlags(flags)) == noErr)
168 {
169 stale = carbonStale;
170 result = (NSURL *)CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
171#if 1050 <= MAC_OS_X_VERSION_MAX_ALLOWED
172 CFMakeCollectable((CFURLRef)result);
173#endif
174 [result autorelease];
175 }
176 DisposeHandle((Handle)alias);
177 }
178 }
179 else staleIfFile = YES;
180 }
181
182 // Try URL.
183 if (result == nil)
184 {
185 NSString *urlString = [fileRef objectForKey:kURLKey];
186 if ([urlString isKindOfClass:[NSString class]])
187 {
188 result = [NSURL URLWithString:urlString relativeToURL:nil];
189 if ([result isFileURL] && ![[NSFileManager defaultManager] fileExistsAtPath:[result path]])
190 {
191 result = nil;
192 }
193 }
194 }
195
196 // If we got nothing, it's definitely stale.
197 if (result == nil)
198 {
199 stale = YES;
200 }
201 else
202 {
203 if ([result isFileURL] && staleIfFile) stale = YES;
204
205 // Convert to/from file reference URL as appropriate.
207 {
209 {
210 if (![result isFileReferenceURL] && [result isFileURL])
211 {
212 NSURL *refURL = [result fileReferenceURL];
213 if (refURL != nil) result = refURL;
214 }
215 }
216 else
217 {
218 if ([result isFileReferenceURL])
219 {
220 NSURL *pathURL = [result filePathURL];
221 if (pathURL != nil) result = pathURL;
222 }
223 }
224 }
225 }
226
227
228 if (isStale != NULL) *isStale = stale;
229 return result;
230}
static unsigned long AliasMountFlagsFromFlags(JAPersistentFileReferenceResolveFlags flags)
static unsigned long BookmarkOptionsFromFlags(JAPersistentFileReferenceResolveFlags flags)
voidpf void uLong size
Definition ioapi.h:134

References AliasMountFlagsFromFlags(), BookmarkDataSupported, kJAPersistentFileReferenceReturnReferenceURL, and nil.

Referenced by JAPathFromPersistentFileReference().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: