-
Notifications
You must be signed in to change notification settings - Fork 1
/
Screen.m
75 lines (58 loc) · 1.89 KB
/
Screen.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
//
// Screen.m
// Nodobo Replay
//
// Created by Alisdair McDiarmid on 30/07/2010.
// Copyright 2010 Nodobo. All rights reserved.
//
#import "Screen.h"
@implementation Screen
@synthesize path;
@synthesize image;
+ (NSArray *) screensFromDirectoryAtPath: (NSString *) p
{
NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
BOOL isDir;
if (!([fm fileExistsAtPath: p isDirectory: &isDir] && isDir))
return [NSArray array];
NSArray * files = [fm contentsOfDirectoryAtPath: p error: NULL];
NSPredicate * pngPredicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH '.png'"];
NSArray * pngFiles = [files filteredArrayUsingPredicate: pngPredicate];
NSMutableArray * screens = [NSMutableArray arrayWithCapacity: [pngFiles count]];
for (NSString * file in pngFiles)
{
Screen * screen = [Screen screenWithPath: [p stringByAppendingPathComponent: file]];
if (screen.timestamp != nil)
[screens addObject: screen];
}
return [NSArray arrayWithArray: screens];
}
+ (Screen *) screenWithPath: (NSString *) p
{
return [[[Screen alloc] initWithPath: p] autorelease];
}
- (Screen *) initWithPath: (NSString *) p
{
self = [super init];
if (self == nil)
return nil;
// Copy path
[path autorelease];
path = [p copy];
// Parse the timestamp from the filename
NSString * filename = [[path lastPathComponent] stringByDeletingPathExtension];
NSDateFormatter * f = [[[NSDateFormatter alloc] init] autorelease];
[f setTimeStyle: NSDateFormatterFullStyle];
[f setDateFormat: @"yyyyMMddHHmmss.SSS"];
timestamp = [[f dateFromString:filename] retain];
// Load the image
image = [[NSImage alloc] initWithContentsOfFile: self.path];
return self;
}
- (void) dealloc
{
[path release];
[image release];
[super dealloc];
}
@end