- Timestamp:
- 05/08/11 15:38:59 (13 months ago)
- Location:
- trunk/SapphireFrappliance
- Files:
-
- 3 modified
-
MetaData/SapphireMObjects/SapphireTVShow.h (modified) (1 diff)
-
MetaData/SapphireMObjects/SapphireTVShow.m (modified) (2 diffs)
-
Settings/SapphireSettings.m (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.h
r1269 r1345 9 9 10 10 - (NSComparisonResult)compare:(SapphireTVShow *)other; 11 - (NSS tring *)calculateAutoSortPath;11 - (NSSet *)calculateAutoSortPaths; 12 12 - (NSString *)autoSortPath; 13 13 - (void)setAutoSortPath:(NSString *)path; -
trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.m
r1291 r1345 151 151 } 152 152 153 - (NSS tring *)calculateAutoSortPath153 - (NSSet *)calculateAutoSortPaths 154 154 { 155 155 NSArray *files = doFetchRequest(SapphireFileMetaDataName, [self managedObjectContext], [self metaFileFetchPredicate]); … … 157 157 return nil; 158 158 159 NSString *sortPath = [[(SapphireFileMetaData *)[files objectAtIndex:0] path] stringByDeletingLastPathComponent];160 BOOL cropTwoDirs = NO;161 159 NSEnumerator *fileEnum = [files objectEnumerator]; 162 160 SapphireFileMetaData *file; 161 NSMutableSet *paths = [NSMutableSet set]; 163 162 while((file = [fileEnum nextObject]) != nil) 164 163 { 165 164 NSString *dirPath = [[file path] stringByDeletingLastPathComponent]; 166 if(cropTwoDirs) 165 NSString *dirName = [dirPath lastPathComponent]; 166 if([[dirName lowercaseString] hasPrefix:@"season"]) 167 167 dirPath = [dirPath stringByDeletingLastPathComponent]; 168 168 169 if([dirPath isEqualToString:sortPath]) 170 continue; 171 172 if(!cropTwoDirs) 173 { 174 sortPath = [sortPath stringByDeletingLastPathComponent]; 175 dirPath = [dirPath stringByDeletingLastPathComponent]; 176 cropTwoDirs = YES; 177 if([dirPath isEqualToString:sortPath]) 178 continue; 179 } 180 181 return nil; 169 [paths addObject:dirPath]; 182 170 } 183 171 184 if(!cropTwoDirs) 185 { 186 NSString *lastPathComponent = [sortPath lastPathComponent]; 187 if([[lastPathComponent lowercaseString] hasPrefix:@"season"]) 188 sortPath = [sortPath stringByDeletingLastPathComponent]; 189 } 190 191 return sortPath; 172 return paths; 192 173 } 193 174 -
trunk/SapphireFrappliance/Settings/SapphireSettings.m
r1324 r1345 491 491 } 492 492 493 - (SapphireConfirmPrompt *)nextAutoSortPathConfirm:(NSArray *)shows 494 { 495 int i, count = [shows count]; 496 SapphireTVShow *show; 493 int checkPaths(NSString *autoPath, NSArray *computedPaths, int startIndex) 494 { 495 int i, count = [computedPaths count]; 496 for (i=startIndex; i<count; i++) { 497 if(![autoPath isEqualToString:[computedPaths objectAtIndex:i]]) 498 break; 499 } 500 return i; 501 } 502 503 - (SapphireConfirmPrompt *)nextAutoSortPathConfirm:(NSArray *)paths forShow:(SapphireTVShow *)show remaining:(NSArray *)remaining 504 { 497 505 NSString *calcAutoPath = nil; 498 NSString *autoPath ;499 for(i=0; i<count; i++)506 NSString *autoPath = [show autoSortPath]; 507 if([paths count] > 0) 500 508 { 501 show = [shows objectAtIndex:i]; 502 calcAutoPath = [show calculateAutoSortPath]; 503 autoPath = [show autoSortPath]; 504 if(autoPath == nil && calcAutoPath == nil) 505 continue; 506 if(autoPath == nil || calcAutoPath == nil) 507 //Only one of them is nil 508 break; 509 if(![autoPath isEqualToString:calcAutoPath]) 510 break; 509 int skipCount = checkPaths(autoPath, paths, 1); //We had just checked the first one, continue after that. 510 paths = [paths subarrayWithRange:NSMakeRange(skipCount, [paths count]-skipCount)]; 511 511 } 512 513 if(i == count) 514 return nil; 515 516 NSArray *newArray = [shows subarrayWithRange:NSMakeRange(i+1, count-i-1)]; 517 NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(promptResult:forShow:remaining:)]]; 512 if([paths count] != 0) 513 calcAutoPath = [paths objectAtIndex:0]; 514 else 515 { 516 int i, count = [remaining count]; 517 for(i=0; i<count; i++) 518 { 519 show = [remaining objectAtIndex:i]; 520 autoPath = [show autoSortPath]; 521 paths = [[show calculateAutoSortPaths] allObjects]; 522 NSLog(@"Paths for %@ are %@", [show name], paths); 523 if([paths count]) 524 { 525 int skipCount = checkPaths(autoPath, paths, 0); 526 if(skipCount > 0) 527 paths = [paths subarrayWithRange:NSMakeRange(skipCount, [paths count]-skipCount)]; 528 } 529 if([paths count]) 530 { 531 calcAutoPath = [paths objectAtIndex:0]; 532 break; 533 } 534 } 535 if(i == count) 536 return nil; 537 remaining = [remaining subarrayWithRange:NSMakeRange(i + 1, [remaining count] - i - 1)]; 538 } 539 540 NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(promptResult:forShow:paths:remaining:)]]; 518 541 [invoke setTarget:self]; 519 [invoke setSelector:@selector(promptResult:forShow: remaining:)];542 [invoke setSelector:@selector(promptResult:forShow:paths:remaining:)]; 520 543 [invoke setArgument:&show atIndex:3]; 521 [invoke setArgument:&newArray atIndex:4]; 544 [invoke setArgument:&paths atIndex:4]; 545 [invoke setArgument:&remaining atIndex:5]; 522 546 [invoke retainArguments]; 523 547 … … 532 556 } 533 557 534 - (BRLayerController *)promptResult:(SapphireConfirmPromptResult)result forShow:(SapphireTVShow *)show remaining:(NSArray *)remain558 - (BRLayerController *)promptResult:(SapphireConfirmPromptResult)result forShow:(SapphireTVShow *)show paths:(NSArray *)paths remaining:(NSArray *)remain 535 559 { 536 560 if(result == SapphireConfirmPromptResultAbort) … … 539 563 if(result == SapphireConfirmPromptResultOK) 540 564 { 541 [show setAutoSortPath:[ show calculateAutoSortPath]];565 [show setAutoSortPath:[paths objectAtIndex:0]]; 542 566 [SapphireMetaDataSupport save:moc]; 567 return [self nextAutoSortPathConfirm:nil forShow:nil remaining:remain]; 543 568 } 544 569 545 return [self nextAutoSortPathConfirm: remain];570 return [self nextAutoSortPathConfirm:paths forShow:show remaining:remain]; 546 571 } 547 572 … … 683 708 { 684 709 NSArray *shows = doFetchRequest(SapphireTVShowName, moc, nil); 685 SapphireConfirmPrompt *confirm = [self nextAutoSortPathConfirm: shows];710 SapphireConfirmPrompt *confirm = [self nextAutoSortPathConfirm:nil forShow:nil remaining:shows]; 686 711 if(confirm != nil) 687 712 [[self stack] pushController:confirm];
