ios: If a .rafilter file has a single filter it is applied automatically.

This commit is contained in:
meancoot 2013-02-19 20:33:36 -05:00
parent b8f0c35833
commit 192f7d56d7
3 changed files with 42 additions and 10 deletions

View File

@ -16,23 +16,51 @@
unsigned _filterCount; unsigned _filterCount;
} }
- (id)initWithPath:(NSString*)path + (RADirectoryFilterList*) directoryFilterListAtPath:(NSString*)path useExpression:(NSRegularExpression**)regex
{
if (regex)
*regex = nil;
if (path && ra_ios_is_file([path stringByAppendingPathComponent:@".rafilter"]))
{
config_file_t* configFile = config_file_new([[path stringByAppendingPathComponent:@".rafilter"] UTF8String]);
unsigned filterCount = 0;
char* regexValue= 0;
if (configFile && config_get_uint(configFile, "filter_count", &filterCount) && filterCount > 1)
return [[RADirectoryFilterList alloc] initWithPath:path config:configFile];
else if (regex && filterCount == 1 && config_get_string(configFile, "filter_1_regex", &regexValue))
*regex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithUTF8String:regexValue] options:0 error:nil];
free(regexValue);
}
return nil;
}
- (id)initWithPath:(NSString*)path config:(config_file_t*)config
{ {
self = [super initWithStyle:UITableViewStylePlain]; self = [super initWithStyle:UITableViewStylePlain];
_path = path; _path = path;
_filterList = config_file_new([[path stringByAppendingPathComponent:@".rafilter"] UTF8String]); _filterList = config;
if (!_filterList || !config_get_uint(_filterList, "filter_count", &_filterCount) || _filterCount == 0) if (!_filterList || !config_get_uint(_filterList, "filter_count", &_filterCount) || _filterCount == 0)
{ {
[RetroArch_iOS displayErrorMessage:@"No valid filters were found."]; [RetroArch_iOS displayErrorMessage:@"No valid filters were found."];
} }
[self setTitle: [path lastPathComponent]]; [self setTitle: [path lastPathComponent]];
return self; return self;
} }
- (id)initWithPath:(NSString*)path
{
return [self initWithPath:path config:config_file_new([[path stringByAppendingPathComponent:@".rafilter"] UTF8String])];
}
- (void)dealloc - (void)dealloc
{ {
if (_filterList) if (_filterList)

View File

@ -41,10 +41,10 @@ static NSString* check_path(NSString* path)
{ {
path = check_path(path); path = check_path(path);
if (path && ra_ios_is_file([path stringByAppendingPathComponent:@".rafilter"])) NSRegularExpression* expr = nil;
return [[RADirectoryFilterList alloc] initWithPath:path]; RADirectoryFilterList* filterList = [RADirectoryFilterList directoryFilterListAtPath:path useExpression:&expr];
else
return [RADirectoryList directoryListWithPath:path filter:nil]; return filterList ? filterList : [RADirectoryList directoryListWithPath:path filter:expr];
} }
+ (id)directoryListWithPath:(NSString*)path filter:(NSRegularExpression*)regex + (id)directoryListWithPath:(NSString*)path filter:(NSRegularExpression*)regex

View File

@ -6,5 +6,9 @@ extern BOOL ra_ios_is_file(NSString* path);
@end @end
@interface RADirectoryFilterList : UITableViewController @interface RADirectoryFilterList : UITableViewController
// Check path to see if a directory filter list is needed.
// If one is not needed useExpression will be set to a default expression to use.
+ (RADirectoryFilterList*) directoryFilterListAtPath:(NSString*)path useExpression:(NSRegularExpression**)regex;
- (id)initWithPath:(NSString*)path; - (id)initWithPath:(NSString*)path;
@end @end