Changeset 1261

Show
Ignore:
Timestamp:
06/05/10 15:40:54 (2 years ago)
Author:
gbooker
Message:

Added ability to calculate a show's sort path based on where files are currently located.

Location:
trunk/SapphireFrappliance
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.h

    r1251 r1261  
    99 
    1010- (NSComparisonResult)compare:(SapphireTVShow *)other; 
     11- (NSString *)calculateAutoSortPath; 
    1112@end 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.m

    r1251 r1261  
    88#import "SapphireFileSorter.h" 
    99#import "SapphireTVTranslation.h" 
     10#import "SapphireFileMetaData.h" 
    1011 
    1112@implementation SapphireTVShow 
     
    147148} 
    148149 
     150- (NSString *)calculateAutoSortPath 
     151{ 
     152        NSArray *files = doFetchRequest(SapphireFileMetaDataName, [self managedObjectContext], [self metaFileFetchPredicate]); 
     153        if([files count] == 0) 
     154                return nil; 
     155         
     156        NSString *sortPath = [[(SapphireFileMetaData *)[files objectAtIndex:0] path] stringByDeletingLastPathComponent]; 
     157        BOOL cropTwoDirs = NO; 
     158        NSEnumerator *fileEnum = [files objectEnumerator]; 
     159        SapphireFileMetaData *file; 
     160        while((file = [fileEnum nextObject]) != nil) 
     161        { 
     162                NSString *dirPath = [[file path] stringByDeletingLastPathComponent]; 
     163                if(cropTwoDirs) 
     164                        dirPath = [dirPath stringByDeletingLastPathComponent]; 
     165                 
     166                if([dirPath isEqualToString:sortPath]) 
     167                        continue; 
     168                 
     169                if(!cropTwoDirs) 
     170                { 
     171                        sortPath = [sortPath stringByDeletingLastPathComponent]; 
     172                        dirPath = [dirPath stringByDeletingLastPathComponent]; 
     173                        cropTwoDirs = YES; 
     174                        if([dirPath isEqualToString:sortPath]) 
     175                                continue; 
     176                } 
     177                 
     178                return nil; 
     179        } 
     180         
     181        return sortPath; 
     182} 
     183 
    149184@end 
  • trunk/SapphireFrappliance/main_debug.m

    r1251 r1261  
    4343#import "SapphireMovieDirectory.h" 
    4444 
    45 #define TESTING_UPGRADE 
     45//#define TESTING_UPGRADE 
    4646//#define LISTING_MOVIES 
    4747//#define TESTING_XML_IMPORT 
     
    5555//#define TESTING_MOVIE_VIRTUAL_DIRS_IN_XML 
    5656//#define TESTING_TV_IMPORT_THROUGH_XML 
     57#define TESTING_AUTO_SORT_PATH 
    5758 
    5859void overrideApplicationSupportdir(NSString *override); 
     
    195196        } 
    196197         
    197 //      overrideApplicationSupportdir([NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Frontrow"]); 
     198        overrideApplicationSupportdir([NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Frontrow"]); 
    198199#ifdef TESTING_UPGRADE 
    199200        { 
     
    348349        } 
    349350#endif 
     351#ifdef TESTING_AUTO_SORT_PATH 
     352        { 
     353                NSArray *shows = doFetchRequest(SapphireTVShowName, moc, nil); 
     354                NSEnumerator *showEnum = [shows objectEnumerator]; 
     355                SapphireTVShow *show; 
     356                while((show = [showEnum nextObject]) != nil) 
     357                { 
     358                        NSString *autoPath = [show calculateAutoSortPath]; 
     359                        NSLog(@"Sort path for %@ is %@", [show name], autoPath); 
     360                } 
     361        } 
     362#endif 
    350363         
    351364        [allImporter release];