-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathPGResourceIdentifier.m
704 lines (597 loc) · 18 KB
/
PGResourceIdentifier.m
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/* Copyright © 2007-2009, The Sequential Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the the Sequential Project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE SEQUENTIAL PROJECT ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE SEQUENTIAL PROJECT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#import "PGResourceIdentifier.h"
// Models
#import "PGSubscription.h"
// Other Sources
#import "PGAttachments.h"
#import "PGFoundationAdditions.h"
NSString *const PGDisplayableIdentifierIconDidChangeNotification = @"PGDisplayableIdentifierIconDidChange";
NSString *const PGDisplayableIdentifierDisplayNameDidChangeNotification = @"PGDisplayableIdentifierDisplayNameDidChange";
@interface PGDisplayableIdentifier(Private)
- (id)_initWithIdentifier:(PGResourceIdentifier *)ident;
@end
@interface PGAliasIdentifier : PGResourceIdentifier <NSCoding>
{
@private
AliasHandle _alias;
BOOL _hasValidRef;
FSRef _ref;
NSURL *_cachedURL;
}
+ (void)clearCache;
- (id)initWithURL:(NSURL *)URL; // Must be a file URL.
- (id)initWithAliasData:(const uint8_t *)data length:(NSUInteger)length;
- (BOOL)setAliasWithData:(const uint8_t *)data length:(NSUInteger)length;
- (BOOL)getRef:(out FSRef *)outRef byFollowingAliases:(BOOL)follow validate:(BOOL)validate;
- (void)cacheURL:(NSURL *)URL;
- (void)clearCache;
@end
@interface PGURLIdentifier : PGResourceIdentifier <NSCoding>
{
@private
NSURL *_URL;
}
- (id)initWithURL:(NSURL *)URL; // Must not be a file URL.
@end
@interface PGIndexIdentifier : PGResourceIdentifier <NSCoding>
{
@private
PGResourceIdentifier *_superidentifier;
NSInteger _index;
}
- (id)initWithSuperidentifier:(PGResourceIdentifier *)identifier index:(NSInteger)index;
@end
@implementation PGResourceIdentifier
#pragma mark +PGResourceIdentifier
+ (id)resourceIdentifierWithURL:(NSURL *)URL
{
return [[[([URL isFileURL] ? [PGAliasIdentifier class] : [PGURLIdentifier class]) alloc] initWithURL:URL] autorelease];
}
+ (id)resourceIdentifierWithAliasData:(const uint8_t *)data length:(NSUInteger)length
{
return [[[PGAliasIdentifier alloc] initWithAliasData:data length:length] autorelease];
}
#pragma mark -PGResourceIdentifier
- (PGResourceIdentifier *)identifier
{
return self;
}
- (PGDisplayableIdentifier *)displayableIdentifier
{
return [[[PGDisplayableIdentifier alloc] _initWithIdentifier:self] autorelease];
}
- (PGResourceIdentifier *)superidentifier
{
return nil;
}
- (PGResourceIdentifier *)rootIdentifier
{
return [self superidentifier] ? [[self superidentifier] rootIdentifier] : self;
}
- (NSURL *)URL
{
return [self URLByFollowingAliases:NO];
}
- (NSInteger)index
{
return NSNotFound;
}
- (BOOL)hasTarget
{
return NO;
}
- (BOOL)isFileIdentifier
{
return NO;
}
#pragma mark -
- (PGResourceIdentifier *)subidentifierWithIndex:(NSInteger)index
{
return [[[PGIndexIdentifier alloc] initWithSuperidentifier:self index:index] autorelease];
}
#pragma mark -
- (NSURL *)superURLByFollowingAliases:(BOOL)flag
{
NSURL *const URL = [self URLByFollowingAliases:flag];
return URL ? URL : [[self superidentifier] superURLByFollowingAliases:flag];
}
- (NSURL *)URLByFollowingAliases:(BOOL)flag
{
return nil;
}
- (BOOL)getRef:(out FSRef *)outRef byFollowingAliases:(BOOL)flag
{
return NO;
}
#pragma mark -
- (PGSubscription *)subscriptionWithDescendents:(BOOL)flag
{
return [self isFileIdentifier] ? [PGSubscription subscriptionWithPath:[[self URL] path] descendents:flag] : nil;
}
#pragma mark -NSObject(NSKeyedArchiverObjectSubstitution)
- (Class)classForKeyedArchiver
{
return [PGResourceIdentifier class];
}
#pragma mark -<NSCoding>
- (id)initWithCoder:(NSCoder *)aCoder
{
if([self class] == [PGResourceIdentifier class]) {
[self release];
return [[PGDisplayableIdentifier alloc] initWithCoder:aCoder];
}
return [self init];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
if([self class] != [PGResourceIdentifier class] && [self class] != [PGDisplayableIdentifier class]) [aCoder encodeObject:NSStringFromClass([self class]) forKey:@"ClassName"];
}
#pragma mark -<NSObject>
- (NSUInteger)hash
{
return [[PGResourceIdentifier class] hash] ^ (NSUInteger)[self index];
}
- (BOOL)isEqual:(id)obj
{
if(![obj isKindOfClass:[PGResourceIdentifier class]]) return NO;
if([self identifier] == [(PGResourceIdentifier *)obj identifier]) return YES;
if([self index] != [(PGResourceIdentifier *)obj index]) return NO;
if(!PGEqualObjects([self superidentifier], [obj superidentifier])) return NO;
return PGEqualObjects([self URL], [obj URL]);
}
#pragma mark -
- (NSString *)description
{
return [NSString stringWithFormat:@"%@", [self URL]];
}
@end
@implementation PGDisplayableIdentifier
#pragma mark +PGResourceIdentifier
+ (id)resourceIdentifierWithURL:(NSURL *)URL
{
return [[[self alloc] _initWithIdentifier:[super resourceIdentifierWithURL:URL]] autorelease];
}
+ (id)resourceIdentifierWithAliasData:(const uint8_t *)data length:(NSUInteger)length
{
return [[[self alloc] _initWithIdentifier:[super resourceIdentifierWithAliasData:data length:length]] autorelease];
}
#pragma mark -PGDisplayableIdentifier
- (BOOL)postsNotifications
{
return _postsNotifications;
}
- (void)setPostsNotifications:(BOOL)flag
{
if(flag) _postsNotifications = YES;
}
- (NSImage *)icon
{
return _icon ? [[_icon retain] autorelease] : [[self URL] PG_icon];
}
- (void)setIcon:(NSImage *)icon
{
if(icon == _icon) return;
[_icon release];
_icon = [icon retain];
if(_postsNotifications) [self PG_postNotificationName:PGDisplayableIdentifierIconDidChangeNotification];
}
- (NSString *)displayName
{
return _customDisplayName ? [[_customDisplayName retain] autorelease] : [self naturalDisplayName];
}
- (NSString *)customDisplayName
{
return [[_customDisplayName retain] autorelease];
}
- (void)setCustomDisplayName:(NSString *)aString
{
NSString *const string = [aString length] ? aString : nil;
if(PGEqualObjects(string, _customDisplayName)) return;
[_customDisplayName release];
_customDisplayName = [string copy];
if(_postsNotifications) [self PG_postNotificationName:PGDisplayableIdentifierDisplayNameDidChangeNotification];
}
- (NSString *)naturalDisplayName
{
if(_naturalDisplayName) return [[_naturalDisplayName retain] autorelease];
NSString *name = @"";
NSURL *const URL = [self URL];
if(URL) {
if(LSCopyDisplayNameForURL((CFURLRef)URL, (CFStringRef *)&name) == noErr && name) [name autorelease];
else {
NSString *const path = [URL path];
name = PGEqualObjects(path, @"/") ? [URL absoluteString] : [path lastPathComponent];
}
}
return [name PG_stringByReplacingOccurrencesOfCharactersInSet:[NSCharacterSet newlineCharacterSet] withString:@""];
}
- (void)setNaturalDisplayName:(NSString *)aString
{
if(PGEqualObjects(aString, _naturalDisplayName)) return;
[_naturalDisplayName release];
_naturalDisplayName = [aString copy];
[self noteNaturalDisplayNameDidChange];
}
- (PGLabelColor)labelColor
{
FSRef ref;
FSCatalogInfo catalogInfo;
if(![self getRef:&ref byFollowingAliases:NO] || FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo | kFSCatInfoNodeFlags, &catalogInfo, NULL, NULL, NULL) != noErr) return PGLabelNone;
UInt16 finderFlags;
if(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) finderFlags = ((FolderInfo *)&catalogInfo.finderInfo)->finderFlags;
else finderFlags = ((FileInfo *)&catalogInfo.finderInfo)->finderFlags;
return (finderFlags >> 1) & 0x07;
}
#pragma mark -
- (NSAttributedString *)attributedStringWithAncestory:(BOOL)flag
{
NSMutableAttributedString *const result = [NSMutableAttributedString PG_attributedStringWithFileIcon:[self icon] name:[self displayName]];
if(!flag) return result;
NSURL *const URL = [self URL];
if(!URL) return result;
NSString *const parent = [URL isFileURL] ? [[URL path] stringByDeletingLastPathComponent] : [URL absoluteString];
NSString *const parentName = [URL isFileURL] ? [parent lastPathComponent] : parent;
if(![parentName length]) return result;
[[result mutableString] appendString:[NSString stringWithFormat:@" %C ", (unichar)0x2014]];
[result appendAttributedString:[NSAttributedString PG_attributedStringWithFileIcon:[URL isFileURL] ? [[parent PG_fileURL] PG_icon] : nil name:parentName]];
return result;
}
- (void)noteNaturalDisplayNameDidChange
{
if(_postsNotifications && !_customDisplayName) [self PG_postNotificationName:PGDisplayableIdentifierDisplayNameDidChangeNotification];
}
#pragma mark -PGDisplayableIdentifier(Private)
- (id)_initWithIdentifier:(PGResourceIdentifier *)ident
{
if((self = [super init])) {
_identifier = [[ident identifier] retain];
}
return self;
}
#pragma mark -PGResourceIdentifier
- (PGResourceIdentifier *)identifier
{
return [_identifier identifier];
}
- (PGDisplayableIdentifier *)displayableIdentifier
{
return self;
}
- (PGResourceIdentifier *)superidentifier
{
return [_identifier superidentifier];
}
- (PGResourceIdentifier *)rootIdentifier
{
return [_identifier rootIdentifier];
}
- (NSURL *)URL
{
return [_identifier URL];
}
- (NSInteger)index
{
return [_identifier index];
}
- (BOOL)hasTarget
{
return [_identifier hasTarget];
}
- (BOOL)isFileIdentifier
{
return [_identifier isFileIdentifier];
}
#pragma mark -
- (PGResourceIdentifier *)subidentifierWithIndex:(NSInteger)index
{
return [_identifier subidentifierWithIndex:index];
}
#pragma mark -
- (NSURL *)superURLByFollowingAliases:(BOOL)flag
{
return [_identifier superURLByFollowingAliases:flag];
}
- (NSURL *)URLByFollowingAliases:(BOOL)flag
{
return [_identifier URLByFollowingAliases:flag];
}
- (BOOL)getRef:(out FSRef *)outRef byFollowingAliases:(BOOL)flag
{
return [_identifier getRef:outRef byFollowingAliases:flag];
}
#pragma mark -
- (PGSubscription *)subscriptionWithDescendents:(BOOL)flag
{
return [_identifier subscriptionWithDescendents:flag];
}
#pragma mark -NSObject
- (void)dealloc
{
[_identifier release];
[_icon release];
[_naturalDisplayName release];
[_customDisplayName release];
[super dealloc];
}
#pragma mark -NSObject(AEAdditions)
- (void)PG_addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)aName
{
_postsNotifications = YES;
[super PG_addObserver:observer selector:aSelector name:aName];
}
#pragma mark -<NSCoding>
- (id)initWithCoder:(NSCoder *)aCoder
{
Class class = NSClassFromString([aCoder decodeObjectForKey:@"ClassName"]);
if([PGResourceIdentifier class] == class || [PGDisplayableIdentifier class] == class) class = Nil;
if((self = [self _initWithIdentifier:[[[class alloc] initWithCoder:aCoder] autorelease]])) {
[self setIcon:[aCoder decodeObjectForKey:@"Icon"]];
[self setCustomDisplayName:[aCoder decodeObjectForKey:@"DisplayName"]];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[_identifier encodeWithCoder:aCoder]; // For backward compatibility, we can't use encodeObject:forKey:, so encode it directly.
[aCoder encodeObject:_icon forKey:@"Icon"];
[aCoder encodeObject:_customDisplayName forKey:@"DisplayName"];
}
#pragma mark -<NSObject>
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p: %@ (\"%@\")>", [self class], self, _identifier, [self displayName]];
}
@end
@implementation PGAliasIdentifier
static NSMutableArray *PGCachedAliasIdentifiers;
#pragma mark +PGAliasIdentifier
+ (void)clearCache
{
[PGCachedAliasIdentifiers makeObjectsPerformSelector:@selector(clearCache)];
[PGCachedAliasIdentifiers release];
PGCachedAliasIdentifiers = nil;
}
#pragma mark -PGAliasIdentifier
- (id)initWithURL:(NSURL *)URL
{
NSParameterAssert([URL isFileURL]);
if((self = [super init])) {
if(!CFURLGetFSRef((CFURLRef)URL, &_ref) || FSNewAliasMinimal(&_ref, &_alias) != noErr) {
[self release];
return (PGAliasIdentifier *)[[PGURLIdentifier alloc] initWithURL:URL];
}
_hasValidRef = YES;
[self cacheURL:URL];
}
return self;
}
- (id)initWithAliasData:(const uint8_t *)data length:(NSUInteger)length
{
if((self = [super init])) {
if(![self setAliasWithData:data length:length]) {
[self release];
return nil;
}
}
return self;
}
- (BOOL)setAliasWithData:(const uint8_t *)data length:(NSUInteger)length
{
if(!data || !length) return NO;
_alias = (AliasHandle)NewHandle(length);
if(!_alias) return NO;
memcpy(*_alias, data, length);
return YES;
}
- (BOOL)getRef:(out FSRef *)outRef byFollowingAliases:(BOOL)follow validate:(BOOL)validate
{
Boolean dontCare1, dontCare2;
if(validate && _hasValidRef && !follow) _hasValidRef = FSIsFSRefValid(&_ref);
if(!_hasValidRef && FSResolveAliasWithMountFlags(NULL, _alias, &_ref, &dontCare1, kResolveAliasFileNoUI) != noErr) return NO;
_hasValidRef = YES;
if(outRef) *outRef = _ref;
return follow ? FSResolveAliasFileWithMountFlags(outRef, true, &dontCare1, &dontCare2, kResolveAliasFileNoUI) == noErr : YES;
}
- (void)cacheURL:(NSURL *)URL
{
if(!URL) return;
[_cachedURL release];
_cachedURL = [URL retain];
if(!PGCachedAliasIdentifiers) {
PGCachedAliasIdentifiers = [[NSMutableArray alloc] init];
[PGAliasIdentifier performSelector:@selector(clearCache) withObject:nil afterDelay:0.0f];
}
[PGCachedAliasIdentifiers addObject:self];
}
- (void)clearCache
{
[_cachedURL release];
_cachedURL = nil;
}
#pragma mark -PGResourceIdentifier
- (BOOL)hasTarget
{
return [self getRef:NULL byFollowingAliases:NO validate:YES];
}
- (BOOL)isFileIdentifier
{
return YES;
}
#pragma mark -
- (NSURL *)URLByFollowingAliases:(BOOL)flag
{
if(!flag && _cachedURL) return [[_cachedURL retain] autorelease];
FSRef ref;
if(![self getRef:&ref byFollowingAliases:flag]) return nil;
NSURL *const URL = [(NSURL *)CFURLCreateFromFSRef(kCFAllocatorDefault, &ref) autorelease];
if(!flag) [self cacheURL:URL];
return URL;
}
- (BOOL)getRef:(out FSRef *)outRef byFollowingAliases:(BOOL)flag
{
return [self getRef:outRef byFollowingAliases:flag validate:YES];
}
#pragma mark -NSObject
- (void)dealloc
{
if(_alias) DisposeHandle((Handle)_alias);
[super dealloc];
}
#pragma mark -<NSCoding>
- (id)initWithCoder:(NSCoder *)aCoder
{
if((self = [super initWithCoder:aCoder])) {
NSUInteger length;
uint8_t const *const data = [aCoder decodeBytesForKey:@"Alias" returnedLength:&length];
if(![self setAliasWithData:data length:length]) {
[self release];
return nil;
}
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
if(_alias) [aCoder encodeBytes:(uint8_t const *)*_alias length:GetHandleSize((Handle)_alias) forKey:@"Alias"];
}
#pragma mark -<NSObject>
- (BOOL)isEqual:(id)obj
{
if(obj == self) return YES;
if(![obj isKindOfClass:[PGAliasIdentifier class]]) return [super isEqual:obj];
FSRef ourRef, theirRef;
if(![self getRef:&ourRef byFollowingAliases:NO validate:NO] || ![obj getRef:&theirRef byFollowingAliases:NO validate:NO]) return NO;
return FSCompareFSRefs(&ourRef, &theirRef) == noErr;
}
@end
@implementation PGURLIdentifier
#pragma mark -PGURLIdentifier
- (id)initWithURL:(NSURL *)URL
{
if((self = [super init])) {
_URL = [URL retain];
}
return self;
}
#pragma mark -PGResourceIdentifier
- (BOOL)hasTarget
{
return YES;
}
- (BOOL)isFileIdentifier
{
return [_URL isFileURL];
}
#pragma mark -
- (NSURL *)URLByFollowingAliases:(BOOL)flag
{
return [[_URL retain] autorelease];
}
#pragma mark -NSObject
- (void)dealloc
{
[_URL release];
[super dealloc];
}
#pragma mark -<NSCoding>
- (id)initWithCoder:(NSCoder *)aCoder
{
if((self = [super initWithCoder:aCoder])) {
_URL = [[aCoder decodeObjectForKey:@"URL"] retain];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_URL forKey:@"URL"];
}
@end
@implementation PGIndexIdentifier
#pragma mark -PGIndexIdentifier
- (id)initWithSuperidentifier:(PGResourceIdentifier *)identifier index:(NSInteger)index
{
NSParameterAssert(identifier);
if((self = [super init])) {
_superidentifier = [identifier retain];
_index = index;
}
return self;
}
#pragma mark -PGResourceIdentifier
- (PGResourceIdentifier *)superidentifier
{
return [[_superidentifier retain] autorelease];
}
- (NSInteger)index
{
return _index;
}
- (BOOL)hasTarget
{
return NSNotFound != _index && [_superidentifier hasTarget];
}
- (BOOL)isFileIdentifier
{
return [_superidentifier isFileIdentifier];
}
#pragma mark -NSObject
- (void)dealloc
{
[_superidentifier release];
[super dealloc];
}
#pragma mark -<NSCoding>
- (id)initWithCoder:(NSCoder *)aCoder
{
if((self = [super initWithCoder:aCoder])) {
_superidentifier = [[aCoder decodeObjectForKey:@"Superidentifier"] retain];
_index = [aCoder decodeIntegerForKey:@"Index"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_superidentifier forKey:@"Superidentifier"];
[aCoder encodeInteger:_index forKey:@"Index"];
}
#pragma mark -<NSObject>
- (NSString *)description
{
return [NSString stringWithFormat:@"%@:%ld", [self superidentifier], (long)[self index]];
}
@end
@implementation NSURL(PGResourceIdentifierCreation)
- (PGResourceIdentifier *)PG_resourceIdentifier
{
return [PGResourceIdentifier resourceIdentifierWithURL:self];
}
- (PGDisplayableIdentifier *)PG_displayableIdentifier
{
return [[[PGDisplayableIdentifier alloc] _initWithIdentifier:[self PG_resourceIdentifier]] autorelease];
}
@end