diff --git a/ios/RetroArch.xcodeproj/project.pbxproj b/ios/RetroArch.xcodeproj/project.pbxproj index 3e284ba004..461c22e844 100644 --- a/ios/RetroArch.xcodeproj/project.pbxproj +++ b/ios/RetroArch.xcodeproj/project.pbxproj @@ -83,7 +83,6 @@ 96AFAFAC16C1E279009DE44C /* state_tracker.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAF7B16C1E00A009DE44C /* state_tracker.c */; }; 96AFAFAD16C1EEE9009DE44C /* sinc.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAEF716C1DC73009DE44C /* sinc.c */; }; 96AFAFD416C1FBC0009DE44C /* input_common.c in Sources */ = {isa = PBXBuildFile; fileRef = 96AFAFC916C1FBC0009DE44C /* input_common.c */; }; - 96C19C2216D2F3BA00FE8D5A /* RADirectoryFilterList.m in Sources */ = {isa = PBXBuildFile; fileRef = 96C19C2116D2F3BA00FE8D5A /* RADirectoryFilterList.m */; }; 96C19C2416D453BA00FE8D5A /* RADirectoryGrid.m in Sources */ = {isa = PBXBuildFile; fileRef = 96C19C2316D453BA00FE8D5A /* RADirectoryGrid.m */; }; 96C19C2916D5A56500FE8D5A /* browser.m in Sources */ = {isa = PBXBuildFile; fileRef = 96C19C2816D5A56400FE8D5A /* browser.m */; }; 96C19C3016D7045700FE8D5A /* RAConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 96C19C2F16D7045700FE8D5A /* RAConfig.m */; }; @@ -232,7 +231,6 @@ 96AFAFCA16C1FBC0009DE44C /* input_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = input_common.h; sourceTree = ""; }; 96AFAFCE16C1FBC0009DE44C /* overlay.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = overlay.c; sourceTree = ""; }; 96AFAFCF16C1FBC0009DE44C /* overlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = overlay.h; sourceTree = ""; }; - 96C19C2116D2F3BA00FE8D5A /* RADirectoryFilterList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RADirectoryFilterList.m; sourceTree = ""; }; 96C19C2316D453BA00FE8D5A /* RADirectoryGrid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RADirectoryGrid.m; sourceTree = ""; }; 96C19C2516D455BE00FE8D5A /* browser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = browser.h; sourceTree = ""; }; 96C19C2616D455BE00FE8D5A /* rarch_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rarch_wrapper.h; sourceTree = ""; }; @@ -564,7 +562,6 @@ children = ( 96C19C2516D455BE00FE8D5A /* browser.h */, 96C19C2816D5A56400FE8D5A /* browser.m */, - 96C19C2116D2F3BA00FE8D5A /* RADirectoryFilterList.m */, 96C19C2316D453BA00FE8D5A /* RADirectoryGrid.m */, 963F5AC416CC523B009BBD19 /* RADirectoryList.m */, ); @@ -700,7 +697,6 @@ 963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */, 963F5AC916CC523B009BBD19 /* RAModuleList.m in Sources */, 96096DD816D1ABAF00BF4499 /* RAModuleInfoList.m in Sources */, - 96C19C2216D2F3BA00FE8D5A /* RADirectoryFilterList.m in Sources */, 96C19C2416D453BA00FE8D5A /* RADirectoryGrid.m in Sources */, 96C19C2916D5A56500FE8D5A /* browser.m in Sources */, 96C19C3016D7045700FE8D5A /* RAConfig.m in Sources */, diff --git a/ios/RetroArch/RADirectoryFilterList.m b/ios/RetroArch/RADirectoryFilterList.m deleted file mode 100644 index 02fb61dde5..0000000000 --- a/ios/RetroArch/RADirectoryFilterList.m +++ /dev/null @@ -1,92 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#import "RAConfig.h" -#import "browser.h" - -@implementation RADirectoryFilterList -{ - NSString* _path; - - RAConfig* _filterList; - unsigned _filterCount; -} - -+ (RADirectoryFilterList*) directoryFilterListAtPath:(NSString*)path useExpression:(NSRegularExpression**)regex -{ - if (regex) - *regex = nil; - - if (path && ra_ios_is_file([path stringByAppendingPathComponent:@".rafilter"])) - { - RAConfig* configFile = [[RAConfig alloc] initWithPath:[path stringByAppendingPathComponent:@".rafilter"]]; - unsigned filterCount = [configFile getUintNamed:@"filter_count" withDefault:0]; - - if (filterCount > 1) - return [[RADirectoryFilterList alloc] initWithPath:path config:configFile]; - - if (regex && filterCount == 1) - { - NSString* expr = [configFile getStringNamed:@"filter_1_regex" withDefault:@".*"]; - *regex = [NSRegularExpression regularExpressionWithPattern:expr options:0 error:nil]; - } - } - - return nil; -} - -- (id)initWithPath:(NSString*)path config:(RAConfig*)config -{ - self = [super initWithStyle:UITableViewStylePlain]; - - _path = path; - _filterList = config; - _filterCount = [_filterList getUintNamed:@"filter_count" withDefault:0]; - - if (_filterCount == 0) - [RetroArch_iOS displayErrorMessage:@"No valid filters were found."]; - - [self setTitle: [path lastPathComponent]]; - return self; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - NSString* regex = [NSString stringWithFormat:@"filter_%d_regex", indexPath.row + 1]; - regex = [_filterList getStringNamed:regex withDefault:@".*"]; - - NSRegularExpression* expr = [NSRegularExpression regularExpressionWithPattern:regex options:0 error:nil]; - - [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListWithPath:_path filter:expr] isGame:NO]; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return _filterCount ? _filterCount : 1; -} - -- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - NSString* name = [NSString stringWithFormat:@"filter_%d_name", indexPath.row + 1]; - name = [_filterList getStringNamed:name withDefault:@"BAD NAME"]; - - UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"filter"]; - cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"filter"]; - cell.textLabel.text = name; - - return cell; -} - -@end diff --git a/ios/RetroArch/RADirectoryGrid.m b/ios/RetroArch/RADirectoryGrid.m index d48d9efa2c..b97ec9ea0c 100644 --- a/ios/RetroArch/RADirectoryGrid.m +++ b/ios/RetroArch/RADirectoryGrid.m @@ -20,24 +20,23 @@ { NSString* _path; NSArray* _list; + RAConfig* _config; } -- (id)initWithPath:(NSString*)path filter:(NSRegularExpression*)regex +- (id)initWithPath:(NSString*)path config:(RAConfig*)config { - _path = path ? path : ra_ios_get_browser_root(); - - // - RAConfig* config = [[RAConfig alloc] initWithPath:[NSString stringWithFormat:@"%@/.coverart/.config", _path]]; + _path = path; + _config = config; + _list = ra_ios_list_directory(_path); - UICollectionViewFlowLayout* layout = [UICollectionViewFlowLayout new]; - layout.itemSize = CGSizeMake([config getUintNamed:@"item_width" withDefault:100], [config getUintNamed:@"item_height" withDefault:100]); - self = [super initWithCollectionViewLayout:layout]; - - _list = ra_ios_list_directory(_path, regex); - self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button; [self setTitle: [_path lastPathComponent]]; + // Init collection view + UICollectionViewFlowLayout* layout = [UICollectionViewFlowLayout new]; + layout.itemSize = CGSizeMake([config getUintNamed:@"cover_width" withDefault:100], [config getUintNamed:@"cover_height" withDefault:100]); + self = [super initWithCollectionViewLayout:layout]; + [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"dircell"]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"textcell"]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"imagecell"]; @@ -60,7 +59,7 @@ RADirectoryItem* path = [_list objectAtIndex: indexPath.row]; if(path.isDirectory) - [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListWithPath:path.path] isGame:NO]; + [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListOrGridWithPath:path.path] isGame:NO]; else [[RetroArch_iOS get] runGame:path.path]; } diff --git a/ios/RetroArch/RADirectoryList.m b/ios/RetroArch/RADirectoryList.m index a27a86c636..f7f2f97b1e 100644 --- a/ios/RetroArch/RADirectoryList.m +++ b/ios/RetroArch/RADirectoryList.m @@ -15,53 +15,35 @@ #import "browser.h" -static NSString* check_path(NSString* path) -{ - if (path && !ra_ios_is_directory(path)) - { - [RetroArch_iOS displayErrorMessage:@"Browsed path is not a directory."]; - return nil; - } - else - return path; -} - @implementation RADirectoryList { NSString* _path; NSArray* _list; + RAConfig* _config; } -+ (id)directoryListWithPath:(NSString*)path ++ (id)directoryListOrGridWithPath:(NSString*)path { - path = check_path(path); - - NSRegularExpression* expr = nil; - RADirectoryFilterList* filterList = [RADirectoryFilterList directoryFilterListAtPath:path useExpression:&expr]; - - return filterList ? filterList : [RADirectoryList directoryListWithPath:path filter:expr]; -} - -+ (id)directoryListWithPath:(NSString*)path filter:(NSRegularExpression*)regex -{ - path = check_path(path); + path = ra_ios_check_path(path); + RAConfig* config = [[RAConfig alloc] initWithPath:[path stringByAppendingPathComponent:@".raconfig"]]; if ([UICollectionViewController instancesRespondToSelector:@selector(initWithCollectionViewLayout:)]) { - NSString* coverDir = path ? [path stringByAppendingPathComponent:@".coverart"] : nil; - if (coverDir && ra_ios_is_directory(coverDir)) - return [[RADirectoryGrid alloc] initWithPath:path filter:regex]; + NSString* coverDir = [path stringByAppendingPathComponent:@".coverart"]; + if (ra_ios_is_directory(coverDir)) + return [[RADirectoryGrid alloc] initWithPath:path config:config]; } - return [[RADirectoryList alloc] initWithPath:path filter:regex]; + return [[RADirectoryList alloc] initWithPath:path config:config]; } -- (id)initWithPath:(NSString*)path filter:(NSRegularExpression*)regex +- (id)initWithPath:(NSString*)path config:(RAConfig*)config { self = [super initWithStyle:UITableViewStylePlain]; - _path = path ? path : ra_ios_get_browser_root(); - _list = ra_ios_list_directory(_path, regex); + _path = path; + _config = config; + _list = ra_ios_list_directory(_path); self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button; [self setTitle: [_path lastPathComponent]]; @@ -74,7 +56,7 @@ static NSString* check_path(NSString* path) RADirectoryItem* path = [_list objectAtIndex: indexPath.row]; if(path.isDirectory) - [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListWithPath:path.path] isGame:NO]; + [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListOrGridWithPath:path.path] isGame:NO]; else [[RetroArch_iOS get] runGame:path.path]; } diff --git a/ios/RetroArch/RAModuleList.m b/ios/RetroArch/RAModuleList.m index be37cf1e3e..30e633af88 100644 --- a/ios/RetroArch/RAModuleList.m +++ b/ios/RetroArch/RAModuleList.m @@ -13,6 +13,8 @@ * If not, see . */ +#import "browser.h" + @implementation RAModuleList { NSMutableArray* _modules; @@ -59,7 +61,7 @@ RAModuleInfo* info = (RAModuleInfo*)[_modules objectAtIndex:indexPath.row]; [RetroArch_iOS get].module_path = info.path; - [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListWithPath:nil] isGame:NO]; + [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListOrGridWithPath:nil] isGame:NO]; } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath diff --git a/ios/RetroArch/browser.h b/ios/RetroArch/browser.h index ffaa75850f..85cf74d42e 100644 --- a/ios/RetroArch/browser.h +++ b/ios/RetroArch/browser.h @@ -15,8 +15,8 @@ extern BOOL ra_ios_is_directory(NSString* path); extern BOOL ra_ios_is_file(NSString* path); -extern NSArray* ra_ios_list_directory(NSString* path, NSRegularExpression* regex); -extern NSString* ra_ios_get_browser_root(); +extern NSArray* ra_ios_list_directory(NSString* path); +extern NSString* ra_ios_check_path(NSString* path); @interface RADirectoryItem : NSObject @property (strong) NSString* path; @@ -25,11 +25,10 @@ extern NSString* ra_ios_get_browser_root(); @end @interface RADirectoryGrid : UICollectionViewController -- (id)initWithPath:(NSString*)path filter:(NSRegularExpression*)regex; +- (id)initWithPath:(NSString*)path config:(RAConfig*)config; @end -@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; +@interface RADirectoryList : UITableViewController ++ (id)directoryListOrGridWithPath:(NSString*)path; +- (id)initWithPath:(NSString*)path config:(RAConfig*)config; @end diff --git a/ios/RetroArch/browser.m b/ios/RetroArch/browser.m index dc096da460..f933658c1e 100644 --- a/ios/RetroArch/browser.m +++ b/ios/RetroArch/browser.m @@ -52,7 +52,7 @@ BOOL ra_ios_is_directory(NSString* path) return result; } -NSArray* ra_ios_list_directory(NSString* path, NSRegularExpression* regex) +NSArray* ra_ios_list_directory(NSString* path) { NSMutableArray* result = [NSMutableArray array]; @@ -79,18 +79,7 @@ NSArray* ra_ios_list_directory(NSString* path, NSRegularExpression* regex) closedir(dir); free(cpath); - // Filter and sort - if (regex) - { - [result filterUsingPredicate:[NSPredicate predicateWithBlock:^(RADirectoryItem* object, NSDictionary* bindings) - { - if (object.isDirectory) - return YES; - - return (BOOL)([regex numberOfMatchesInString:[object.path lastPathComponent] options:0 range:NSMakeRange(0, [[object.path lastPathComponent] length])] != 0); - }]]; - } - + // Sort [result sortUsingComparator:^(RADirectoryItem* left, RADirectoryItem* right) { return (left.isDirectory != right.isDirectory) ? @@ -101,8 +90,14 @@ NSArray* ra_ios_list_directory(NSString* path, NSRegularExpression* regex) return result; } -NSString* ra_ios_get_browser_root() +NSString* ra_ios_check_path(NSString* path) { + if (path && ra_ios_is_directory(path)) + return path; + + if (path) + [RetroArch_iOS displayErrorMessage:@"Browsed path is not a directory."]; + if (ra_ios_is_directory(@"/var/mobile/RetroArchGames")) return @"/var/mobile/RetroArchGames"; else if (ra_ios_is_directory(@"/var/mobile")) return @"/var/mobile"; else return @"/"; diff --git a/ios/RetroArch/views.h b/ios/RetroArch/views.h index 698d6c8f7f..3b6db9cbec 100644 --- a/ios/RetroArch/views.h +++ b/ios/RetroArch/views.h @@ -35,12 +35,6 @@ @interface RAModuleList : UITableViewController @end -@interface RADirectoryList : UITableViewController -+ (id)directoryListWithPath:(NSString*)path; -+ (id)directoryListWithPath:(NSString*)path filter:(NSRegularExpression*)regex; -- (id)initWithPath:(NSString*)path filter:(NSRegularExpression*)regex; -@end - @interface RASettingsSubList : UITableViewController - (id)initWithSettings:(NSArray*)values title:(NSString*)title; - (void)writeSettings:(NSArray*)settingList toConfig:(RAConfig*)config;