-
Notifications
You must be signed in to change notification settings - Fork 13
/
PassDataController.mm
67 lines (49 loc) · 1.44 KB
/
PassDataController.mm
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
/*
* Copyright (C) 2012 Brian A. Mattern <[email protected]>.
* All Rights Reserved.
* This file is licensed under the GPLv2+.
* Please see COPYING for more information
*/
#import "PassDataController.h"
#import "PassEntry.h"
#import <dirent.h>
@interface PassDataController ()
@property (nonatomic, copy, readwrite) NSMutableArray *entries;
- (void) readEntries:(NSString *)path;
@end
@implementation PassDataController
@synthesize entries;
- (id)initWithPath:(NSString *)path {
if ( (self = [super init]) ) {
[self readEntries:path];
}
return self;
}
- (void)readEntries:(NSString *)path {
DIR *d;
struct dirent *dent;
PassEntry *entry;
NSMutableArray *list = [[NSMutableArray alloc] init];
d = opendir([path cStringUsingEncoding:NSUTF8StringEncoding]);
if (!d) {
// XXX handle error!
return;
}
while ( (dent = readdir(d)) ) {
if (dent->d_name[0] == '.') continue; // skip hidden files
entry = [[PassEntry alloc] init];
entry.name = [[NSString alloc] initWithCString:dent->d_name
encoding:NSUTF8StringEncoding];
entry.path = [NSString stringWithFormat:@"%@/%s", path, dent->d_name];
entry.is_dir = (dent->d_type == DT_DIR ? YES : NO);
[list addObject:entry];
}
self.entries = list;
}
- (unsigned) numEntries {
return [self.entries count];
}
- (PassEntry *)entryAtIndex:(unsigned)index {
return [self.entries objectAtIndex:index];
}
@end