forked from alisdair/Nodobo-Replay
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Session.m
65 lines (48 loc) · 1.42 KB
/
Session.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
//
// Session.m
// Nodobo Replay
//
// Created by Alisdair McDiarmid on 30/07/2010.
// Copyright 2010 Nodobo. All rights reserved.
//
#import "Session.h"
#import "Screen.h"
#import "Clue.h"
@implementation Session
@synthesize path;
@synthesize interactions;
@synthesize screens;
+ (Session *) sessionWithPath: (NSString *) p
{
return [[[Session alloc] initWithPath: p] autorelease];
}
- (Session *) initWithPath: (NSString *) p
{
self = [super init];
if (self == nil)
return nil;
[path autorelease];
path = [p copy];
[self readInteractions];
return self;
}
- (void) readInteractions
{
screens = [Screen screensFromDirectoryAtPath: self.path];
NSString * database = [self.path stringByAppendingPathComponent: @"clues.sqlite3"];
NSArray * clues = [Clue cluesFromDatabaseAtPath: database];
NSArray * merged = [screens arrayByAddingObjectsFromArray: clues];
NSArray *sds = [NSArray arrayWithObject:
[[[NSSortDescriptor alloc] initWithKey: @"timestamp" ascending: YES] autorelease]];
interactions = [[merged sortedArrayUsingDescriptors: sds] retain];
NSPredicate * sp = [NSPredicate predicateWithFormat: @"class = %@", [Screen class]];
screens = [[interactions filteredArrayUsingPredicate: sp] retain];
}
- (void) dealloc
{
[path release];
[interactions release];
[screens release];
[super dealloc];
}
@end