2006-09-02 16:09:20 +00:00
|
|
|
//
|
|
|
|
// DirectoryNode.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 8/20/2006.
|
|
|
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DirectoryNode.h"
|
|
|
|
#import "FileNode.h"
|
2006-09-26 22:22:56 +00:00
|
|
|
#import "SmartFolderNode.h"
|
2006-09-02 16:09:20 +00:00
|
|
|
|
|
|
|
@implementation DirectoryNode
|
|
|
|
|
|
|
|
-(id)initWithPath:(NSString *)p controller:(id) c
|
|
|
|
{
|
|
|
|
self = [super initWithPath:p];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
controller = [c retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2006-09-17 18:11:29 +00:00
|
|
|
[[controller watcher] removePath:[self path]];
|
|
|
|
|
|
|
|
NSLog(@"DEALLOC: %@", self);
|
|
|
|
if (subpaths)
|
|
|
|
[subpaths release];
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[controller release];
|
2006-09-17 18:11:29 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isLeaf
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-09-26 22:22:56 +00:00
|
|
|
- (void)processContents: (NSArray *)contents
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2006-09-26 22:22:56 +00:00
|
|
|
NSEnumerator *e = [contents objectEnumerator];
|
|
|
|
NSString *s;
|
|
|
|
while ((s = [e nextObject]))
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2006-09-26 22:22:56 +00:00
|
|
|
if ([s characterAtIndex:0] == '.')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PathNode *newNode;
|
|
|
|
NSString *newSubpath = [path stringByAppendingPathComponent: s];
|
|
|
|
|
|
|
|
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
newNode = [[SmartFolderNode alloc] initWithPath:newSubpath controller:controller];
|
|
|
|
}
|
|
|
|
else
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
|
|
|
BOOL isDir;
|
|
|
|
|
|
|
|
[[NSFileManager defaultManager] fileExistsAtPath:newSubpath isDirectory:&isDir];
|
|
|
|
|
|
|
|
if (!isDir && ![[controller acceptableFileTypes] containsObject:[s pathExtension]])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
newNode = [[DirectoryNode alloc] initWithPath: newSubpath controller:controller];
|
|
|
|
else
|
|
|
|
newNode = [[FileNode alloc] initWithPath: newSubpath];
|
|
|
|
}
|
2006-09-26 22:22:56 +00:00
|
|
|
|
|
|
|
[subpaths addObject:newNode];
|
|
|
|
|
|
|
|
[newNode release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)subpaths
|
|
|
|
{
|
|
|
|
if (subpaths == nil)
|
|
|
|
{
|
|
|
|
subpaths = [[NSMutableArray alloc] init];
|
|
|
|
NSArray *contents = [[NSFileManager defaultManager] directoryContentsAtPath:path];
|
|
|
|
|
|
|
|
[self processContents: contents];
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[[controller watcher] addPath:[self path]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return subpaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSubpaths:(id)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[subpaths release];
|
|
|
|
subpaths = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int)countOfSubpaths
|
|
|
|
{
|
|
|
|
return [[self subpaths] count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PathNode *)objectInSubpathsAtIndex:(unsigned int)index
|
|
|
|
{
|
|
|
|
return [[self subpaths] objectAtIndex:index];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|