diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 62b2808745..6530c87bfd 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -29,44 +29,33 @@ { NSString* _path; NSMutableArray* _sectionNames; + id _delegate; } -+ (id)directoryListAtBrowseRoot -{ - NSString* rootPath = RetroArch_iOS.get.documentsDirectory; - NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; - RADirectoryList* list = [RADirectoryList directoryListForPath:path_is_directory(ragPath.UTF8String) ? ragPath : rootPath]; - return list; -} -+ (id)directoryListForPath:(NSString*)path -{ - // NOTE: Don't remove or ignore this abstraction, this function will be expanded when cover art comes back. - return [[RADirectoryList alloc] initWithPath:path]; -} - -- (id)initWithPath:(NSString*)path +- (id)initWithPath:(NSString*)path delegate:(id)delegate { _path = path; + _delegate = delegate; self = [super initWithStyle:UITableViewStylePlain]; self.title = path.lastPathComponent; self.hidesHeaders = YES; - NSMutableArray *toolbarButtons = [[NSMutableArray alloc] initWithCapacity:3]; + NSMutableArray *toolbarButtons = [[NSMutableArray alloc] initWithCapacity:3]; - UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)]; - refreshButton.style = UIBarButtonItemStyleBordered; - [toolbarButtons addObject:refreshButton]; + UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)]; + refreshButton.style = UIBarButtonItemStyleBordered; + [toolbarButtons addObject:refreshButton]; - UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; - [toolbarButtons addObject:flexibleSpace]; + UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; + [toolbarButtons addObject:flexibleSpace]; - UIBarButtonItem *newFolderButton = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:self action:@selector(createNewFolder)]; - [toolbarButtons addObject:newFolderButton]; + UIBarButtonItem *newFolderButton = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:self action:@selector(createNewFolder)]; + [toolbarButtons addObject:newFolderButton]; - [[[RetroArch_iOS get] toolbar] setItems:toolbarButtons]; - [self setToolbarItems:toolbarButtons]; + [[[RetroArch_iOS get] toolbar] setItems:toolbarButtons]; + [self setToolbarItems:toolbarButtons]; [self refresh]; @@ -127,18 +116,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - RADirectoryItem* path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; - - if(path.isDirectory) - [[RetroArch_iOS get] pushViewController:[RADirectoryList directoryListForPath:path.path] animated:YES]; - else - { - if (access(_path.UTF8String, R_OK | W_OK | X_OK)) - apple_display_alert(@"The directory containing the selected file has limited permissions. This may " - "prevent zipped games from loading, and will cause some cores to not function.", 0); - - [[RetroArch_iOS get] pushViewController:[[RAModuleList alloc] initWithGame:path.path] animated:YES]; - } + [_delegate directoryList:self itemWasSelected:[self itemForIndexPath:indexPath]]; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -224,15 +202,14 @@ @implementation RAModuleList { - NSString* _game; + id _delegate; } -- (id)initWithGame:(NSString*)path +- (id)initWithGame:(NSString*)path delegate:(id)delegate { self = [super initWithStyle:UITableViewStyleGrouped]; - [self setTitle:[path lastPathComponent]]; - - _game = path; + [self setTitle:path ? [path lastPathComponent] : @"Cores"]; + _delegate = delegate; // Load the modules with their data NSArray* moduleList = [RAModuleInfo getModules]; @@ -242,8 +219,8 @@ for (RAModuleInfo* i in moduleList) { - if ([i supportsFileAtPath:_game]) [supported addObject:i]; - else [other addObject:i]; + if (path && [i supportsFileAtPath:path]) [supported addObject:i]; + else [other addObject:i]; } if (supported.count > 1) @@ -257,7 +234,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - apple_run_core((RAModuleInfo*)[self itemForIndexPath:indexPath], _game.UTF8String); + [_delegate moduleList:self itemWasSelected:[self itemForIndexPath:indexPath]]; } - (void)infoButtonTapped:(id)sender diff --git a/apple/iOS/platform.h b/apple/iOS/platform.h index d7a55f4668..c7d01d7756 100644 --- a/apple/iOS/platform.h +++ b/apple/iOS/platform.h @@ -17,13 +17,16 @@ #ifndef __RARCH_IOS_PLATFORM_H #define __RARCH_IOS_PLATFORM_H +#include "views.h" + @interface RAGameView : UIViewController + (RAGameView*)get; - (void)openPauseMenu; - (void)closePauseMenu; @end -@interface RetroArch_iOS : UINavigationController +@interface RetroArch_iOS : UINavigationController + (RetroArch_iOS*)get; diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index cfe1d8b391..3921d3f37f 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -85,6 +85,7 @@ static void handle_touch_event(NSArray* touches) @implementation RetroArch_iOS { UIWindow* _window; + NSString* _path; bool _isGameTop, _isRomList; uint32_t _settingMenusInBackStack; @@ -117,13 +118,8 @@ static void handle_touch_event(NSArray* touches) else if (!path_make_and_check_directory(self.systemDirectory.UTF8String, 0755, R_OK | W_OK | X_OK)) apple_display_alert([NSString stringWithFormat:@"Failed to create or access system directory: %@", self.systemDirectory], 0); else - { - [self pushViewController:[RADirectoryList directoryListAtBrowseRoot] animated:YES]; - [self refreshSystemConfig]; - - if (apple_use_tv_mode) - apple_run_core(nil, 0); - } + [self beginBrowsingForFile]; + // Warn if there are no cores present if ([RAModuleInfo getModules].count == 0) @@ -140,6 +136,45 @@ static void handle_touch_event(NSArray* touches) apple_enter_stasis(); } +#pragma mark Frontend Browsing Logic +- (void)beginBrowsingForFile +{ + NSString* rootPath = RetroArch_iOS.get.documentsDirectory; + NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; + NSString* target = path_is_directory(ragPath.UTF8String) ? ragPath : rootPath; + + [self pushViewController:[[RADirectoryList alloc] initWithPath:target delegate:self] animated:YES]; + + [self refreshSystemConfig]; + if (apple_use_tv_mode) + apple_run_core(nil, 0); + +} + +- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path +{ + if(path.isDirectory) + [[RetroArch_iOS get] pushViewController:[[RADirectoryList alloc] initWithPath:path.path delegate:self] animated:YES]; + else + { + _path = path.path; + + if (access([path.path stringByDeletingLastPathComponent].UTF8String, R_OK | W_OK | X_OK)) + apple_display_alert(@"The directory containing the selected file has limited permissions. This may " + "prevent zipped games from loading, and will cause some cores to not function.", 0); + + [[RetroArch_iOS get] pushViewController:[[RAModuleList alloc] initWithGame:path.path delegate:self] animated:YES]; + } + + return true; +} + +- (bool)moduleList:(id)list itemWasSelected:(RAModuleInfo*)module +{ + apple_run_core(module, _path.UTF8String); + return true; +} + // UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { diff --git a/apple/iOS/views.h b/apple/iOS/views.h index 5b058b2ede..694ce88439 100644 --- a/apple/iOS/views.h +++ b/apple/iOS/views.h @@ -38,17 +38,22 @@ @end // browser.m +@protocol RADirectoryListDelegate +- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path; +@end + @interface RADirectoryList : RATableViewController @property (nonatomic, weak) RADirectoryItem *selectedItem; - -+ (id)directoryListAtBrowseRoot; -+ (id)directoryListForPath:(NSString*)path; -- (id)initWithPath:(NSString*)path; +- (id)initWithPath:(NSString*)path delegate:(id)delegate; @end // browser.m +@protocol RAModuleListDelegate +- (bool)moduleList:(id)list itemWasSelected:(RAModuleInfo*)module; +@end + @interface RAModuleList : RATableViewController -- (id)initWithGame:(NSString*)path; +- (id)initWithGame:(NSString*)path delegate:(id)delegate; @end // browser.m