2006-09-02 16:09:20 +00:00
|
|
|
//
|
|
|
|
// Node.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 8/20/2006.
|
|
|
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PathNode.h"
|
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
#import "CogAudio/AudioPlayer.h"
|
|
|
|
|
2007-10-15 03:29:30 +00:00
|
|
|
#import "FileTreeDataSource.h"
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "ContainerNode.h"
|
2008-02-17 18:59:54 +00:00
|
|
|
#import "DirectoryNode.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#import "FileNode.h"
|
2008-02-17 18:59:54 +00:00
|
|
|
#import "SmartFolderNode.h"
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2022-01-23 23:02:46 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
@implementation PathNode
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// From http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
|
|
|
|
// Updated 2018-06-28
|
|
|
|
NSURL *resolveAliases(NSURL *url) {
|
|
|
|
CFErrorRef error;
|
|
|
|
CFDataRef bookmarkRef = CFURLCreateBookmarkDataFromFile(kCFAllocatorDefault, (__bridge CFURLRef)url, &error);
|
|
|
|
if(bookmarkRef) {
|
|
|
|
Boolean isStale;
|
|
|
|
CFURLRef urlRef = CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, bookmarkRef, kCFURLBookmarkResolutionWithSecurityScope, NULL, NULL, &isStale, &error);
|
|
|
|
|
|
|
|
if(urlRef && !isStale) {
|
2018-06-28 10:59:59 +00:00
|
|
|
return (NSURL *)CFBridgingRelease(urlRef);
|
2007-10-15 23:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// DLog(@"Not resolved");
|
2007-10-16 01:22:57 +00:00
|
|
|
return url;
|
2007-10-15 23:37:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)initWithDataSource:(FileTreeDataSource *)ds url:(NSURL *)u {
|
2006-09-02 16:09:20 +00:00
|
|
|
self = [super init];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(self) {
|
2007-10-15 03:29:30 +00:00
|
|
|
dataSource = ds;
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setURL:u];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setURL:(NSURL *)u {
|
2022-01-23 22:43:22 +00:00
|
|
|
url = u;
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2009-08-16 16:49:34 +00:00
|
|
|
display = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[icon setSize:NSMakeSize(16.0, 16.0)];
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSURL *)URL {
|
2007-10-16 01:22:57 +00:00
|
|
|
return url;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)updatePath {
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)processPaths:(NSArray *)contents {
|
|
|
|
NSMutableArray *newSubpathsDirs = [[NSMutableArray alloc] init];
|
2007-10-14 23:24:54 +00:00
|
|
|
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
for(NSString *s in contents) {
|
|
|
|
if([s characterAtIndex:0] == '.') {
|
2007-10-14 23:24:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-16 01:22:57 +00:00
|
|
|
NSURL *u = [NSURL fileURLWithPath:s];
|
2009-08-16 16:49:34 +00:00
|
|
|
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
PathNode *newNode;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
// DLog(@"Before: %@", u);
|
2007-10-16 01:22:57 +00:00
|
|
|
u = resolveAliases(u);
|
2022-02-07 05:49:27 +00:00
|
|
|
// DLog(@"After: %@", u);
|
2007-10-16 01:27:15 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL isDir;
|
|
|
|
|
|
|
|
if([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame) {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Smart folder!");
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource url:u];
|
2022-02-07 05:49:27 +00:00
|
|
|
isDir = NO;
|
|
|
|
} else {
|
2007-10-16 01:22:57 +00:00
|
|
|
[[NSFileManager defaultManager] fileExistsAtPath:[u path] isDirectory:&isDir];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!isDir && ![[AudioPlayer fileTypes] containsObject:[[u pathExtension] lowercaseString]]) {
|
2007-10-14 23:24:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(isDir) {
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource url:u];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if([[AudioPlayer containerTypes] containsObject:[[u pathExtension] lowercaseString]]) {
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[ContainerNode alloc] initWithDataSource:dataSource url:u];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2007-10-16 01:22:57 +00:00
|
|
|
newNode = [[FileNode alloc] initWithDataSource:dataSource url:u];
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
2009-08-16 16:49:34 +00:00
|
|
|
|
|
|
|
[newNode setDisplay:displayName];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(isDir)
|
|
|
|
[newSubpathsDirs addObject:newNode];
|
|
|
|
else
|
|
|
|
[newSubpaths addObject:newNode];
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
[newSubpathsDirs addObjectsFromArray:newSubpaths];
|
2013-10-09 18:30:09 +00:00
|
|
|
[self setSubpaths:newSubpathsDirs];
|
2007-10-14 23:24:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSArray *)subpaths {
|
|
|
|
if(subpaths == nil) {
|
2007-10-15 03:29:30 +00:00
|
|
|
[self updatePath];
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-14 23:24:54 +00:00
|
|
|
return subpaths;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setSubpaths:(NSArray *)s {
|
2007-10-14 23:24:54 +00:00
|
|
|
subpaths = s;
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)isLeaf {
|
2007-10-14 23:24:54 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setDisplay:(NSString *)s {
|
2009-08-16 16:49:34 +00:00
|
|
|
display = s;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)display {
|
2007-10-16 01:22:57 +00:00
|
|
|
return display;
|
2007-10-15 03:29:30 +00:00
|
|
|
}
|
2007-10-14 23:24:54 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSImage *)icon {
|
2007-10-14 23:24:54 +00:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
@end
|