| 1 | /* |
|---|
| 2 | * main_debug.c |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Graham Booker on Aug. 2, 2008. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "SapphireImportHelper.h" |
|---|
| 22 | #import <CoreData/CoreData.h> |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | //Debug Imports |
|---|
| 26 | #import "SapphireCollectionDirectory.h" |
|---|
| 27 | #import "SapphireDirectoryMetaData.h" |
|---|
| 28 | |
|---|
| 29 | @interface TestDebug : NSObject <SapphireMetaDataScannerDelegate> |
|---|
| 30 | { |
|---|
| 31 | int i; |
|---|
| 32 | NSArray *collections; |
|---|
| 33 | NSMutableSet *skip; |
|---|
| 34 | } |
|---|
| 35 | - (id)initWithCollections:(NSArray *)col; |
|---|
| 36 | @end |
|---|
| 37 | |
|---|
| 38 | @implementation TestDebug |
|---|
| 39 | |
|---|
| 40 | - (id)initWithCollections:(NSArray *)col |
|---|
| 41 | { |
|---|
| 42 | self = [super init]; |
|---|
| 43 | |
|---|
| 44 | collections = [col retain]; |
|---|
| 45 | skip = [[NSMutableSet alloc] init]; |
|---|
| 46 | i=-1; |
|---|
| 47 | |
|---|
| 48 | return self; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | - (void) dealloc |
|---|
| 52 | { |
|---|
| 53 | [collections release]; |
|---|
| 54 | [skip release]; |
|---|
| 55 | [super dealloc]; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | - (void)gotSubFiles:(NSArray *)subs |
|---|
| 59 | { |
|---|
| 60 | i++; |
|---|
| 61 | if(i==[collections count]) |
|---|
| 62 | NSLog(@"DONE!!!"); |
|---|
| 63 | else |
|---|
| 64 | { |
|---|
| 65 | [[[collections objectAtIndex:i] directory] getSubFileMetasWithDelegate:self skipDirectories:skip]; |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | - (void)scanningDir:(NSString *)dir |
|---|
| 70 | { |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | - (BOOL)getSubFilesCanceled |
|---|
| 74 | { |
|---|
| 75 | return NO; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | @end |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | int main(int argc, char *argv[]) |
|---|
| 82 | { |
|---|
| 83 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 84 | |
|---|
| 85 | NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[0] length:strlen(argv[0])]; |
|---|
| 86 | |
|---|
| 87 | path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Sapphire.frappliance"]; |
|---|
| 88 | |
|---|
| 89 | NSBundle *bundle = [NSBundle bundleWithPath:path]; |
|---|
| 90 | [bundle load]; |
|---|
| 91 | |
|---|
| 92 | NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] init]; |
|---|
| 93 | [moc setUndoManager:nil]; |
|---|
| 94 | NSString *mopath = [bundle pathForResource:@"Sapphire" ofType:@"mom"]; |
|---|
| 95 | NSURL *mourl = [NSURL fileURLWithPath:mopath]; |
|---|
| 96 | NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:mourl]; |
|---|
| 97 | NSPersistentStoreCoordinator *coord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; |
|---|
| 98 | [moc setPersistentStoreCoordinator:coord]; |
|---|
| 99 | [coord release]; |
|---|
| 100 | |
|---|
| 101 | // NSString *storeFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/metaData.sapphireData"]; |
|---|
| 102 | NSString *storeFile = @"/Volumes/frontrow/Library/Application Support/Sapphire/metaData.sapphireData"; |
|---|
| 103 | BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:storeFile]; |
|---|
| 104 | if(!exists) |
|---|
| 105 | return 0; |
|---|
| 106 | NSURL *storeUrl = [NSURL fileURLWithPath:storeFile]; |
|---|
| 107 | NSError *error = nil; |
|---|
| 108 | NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 109 | [NSNumber numberWithBool:YES], NSReadOnlyPersistentStoreOption, |
|---|
| 110 | nil]; |
|---|
| 111 | [coord addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]; |
|---|
| 112 | |
|---|
| 113 | //Debug code goes here: |
|---|
| 114 | NSMutableArray *collections = [[SapphireCollectionDirectory allCollectionsInContext:moc] mutableCopy]; |
|---|
| 115 | //remove / and ~/Movies |
|---|
| 116 | [collections removeObjectAtIndex:0]; |
|---|
| 117 | [collections removeObjectAtIndex:0]; |
|---|
| 118 | TestDebug *debug = [[TestDebug alloc] initWithCollections:collections]; |
|---|
| 119 | [NSTimer scheduledTimerWithTimeInterval:0 target:debug selector:@selector(gotSubFiles:) userInfo:nil repeats:NO]; |
|---|
| 120 | [debug release]; |
|---|
| 121 | |
|---|
| 122 | NSRunLoop *currentRL = [NSRunLoop currentRunLoop]; |
|---|
| 123 | while([currentRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) |
|---|
| 124 | ; |
|---|
| 125 | |
|---|
| 126 | [pool release]; |
|---|
| 127 | |
|---|
| 128 | return 0; |
|---|
| 129 | } |
|---|