Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
JAPersistentFileReference.m File Reference
import "JAPersistentFileReference.h"
import <CoreServices/CoreServices.h>
+ Include dependency graph for JAPersistentFileReference.m:

Go to the source code of this file.

Macros

#define kURLKey   @"url"
 
#define kAliasKey   @"alias"
 
#define kBookmarkKey   @"bookmark"
 
#define BookmarkDataSupported()
 

Functions

NSDictionary * JAPersistentFileReferenceFromURL (NSURL *url)
 
static unsigned long BookmarkOptionsFromFlags (JAPersistentFileReferenceResolveFlags flags)
 
static unsigned long AliasMountFlagsFromFlags (JAPersistentFileReferenceResolveFlags flags)
 
NSURL * JAURLFromPersistentFileReference (NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
 
NSDictionary * JAPersistentFileReferenceFromPath (NSString *path)
 
NSString * JAPathFromPersistentFileReference (NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
 

Macro Definition Documentation

◆ BookmarkDataSupported

#define BookmarkDataSupported ( )
Value:
([NSURL instancesRespondToSelector:@selector(bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:)])

Definition at line 44 of file JAPersistentFileReference.m.

Referenced by JAPersistentFileReferenceFromURL(), and JAURLFromPersistentFileReference().

◆ kAliasKey

#define kAliasKey   @"alias"

Definition at line 33 of file JAPersistentFileReference.m.

◆ kBookmarkKey

#define kBookmarkKey   @"bookmark"

Definition at line 34 of file JAPersistentFileReference.m.

◆ kURLKey

#define kURLKey   @"url"

Definition at line 32 of file JAPersistentFileReference.m.

Function Documentation

◆ AliasMountFlagsFromFlags()

static unsigned long AliasMountFlagsFromFlags ( JAPersistentFileReferenceResolveFlags flags)
inlinestatic

Definition at line 125 of file JAPersistentFileReference.m.

126{
127 unsigned long result = 0;
128 if (flags & kJAPersistentFileReferenceWithoutUI) result |= kResolveAliasFileNoUI;
129 return result;
130}
@ kJAPersistentFileReferenceWithoutUI

References kJAPersistentFileReferenceWithoutUI.

Referenced by JAURLFromPersistentFileReference().

+ Here is the caller graph for this function:

◆ BookmarkOptionsFromFlags()

static unsigned long BookmarkOptionsFromFlags ( JAPersistentFileReferenceResolveFlags flags)
inlinestatic

Definition at line 116 of file JAPersistentFileReference.m.

117{
118 unsigned long result = 0;
119 if (flags & kJAPersistentFileReferenceWithoutUI) result |= NSURLBookmarkResolutionWithoutUI;
120 if (flags & NSURLBookmarkResolutionWithoutMounting) result |= NSURLBookmarkResolutionWithoutMounting;
121 return result;
122}

References kJAPersistentFileReferenceWithoutUI.

◆ 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}
@ kJAPersistentFileReferenceReturnReferenceURL
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 BookmarkDataSupported()

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)
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: