(iOS) Move browser logic into platform.m

This commit is contained in:
meancoot 2013-08-24 20:27:04 -04:00
parent edfab9630a
commit 7a72899c15
4 changed files with 77 additions and 57 deletions

View File

@ -29,44 +29,33 @@
{ {
NSString* _path; NSString* _path;
NSMutableArray* _sectionNames; NSMutableArray* _sectionNames;
id<RADirectoryListDelegate> _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 - (id)initWithPath:(NSString*)path delegate:(id<RADirectoryListDelegate>)delegate
{
// 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
{ {
_path = path; _path = path;
_delegate = delegate;
self = [super initWithStyle:UITableViewStylePlain]; self = [super initWithStyle:UITableViewStylePlain];
self.title = path.lastPathComponent; self.title = path.lastPathComponent;
self.hidesHeaders = YES; 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)]; UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)];
refreshButton.style = UIBarButtonItemStyleBordered; refreshButton.style = UIBarButtonItemStyleBordered;
[toolbarButtons addObject:refreshButton]; [toolbarButtons addObject:refreshButton];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[toolbarButtons addObject:flexibleSpace]; [toolbarButtons addObject:flexibleSpace];
UIBarButtonItem *newFolderButton = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:self action:@selector(createNewFolder)]; UIBarButtonItem *newFolderButton = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:self action:@selector(createNewFolder)];
[toolbarButtons addObject:newFolderButton]; [toolbarButtons addObject:newFolderButton];
[[[RetroArch_iOS get] toolbar] setItems:toolbarButtons]; [[[RetroArch_iOS get] toolbar] setItems:toolbarButtons];
[self setToolbarItems:toolbarButtons]; [self setToolbarItems:toolbarButtons];
[self refresh]; [self refresh];
@ -127,18 +116,7 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
RADirectoryItem* path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; [_delegate directoryList:self itemWasSelected:[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];
}
} }
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@ -224,15 +202,14 @@
@implementation RAModuleList @implementation RAModuleList
{ {
NSString* _game; id<RAModuleListDelegate> _delegate;
} }
- (id)initWithGame:(NSString*)path - (id)initWithGame:(NSString*)path delegate:(id<RAModuleListDelegate>)delegate
{ {
self = [super initWithStyle:UITableViewStyleGrouped]; self = [super initWithStyle:UITableViewStyleGrouped];
[self setTitle:[path lastPathComponent]]; [self setTitle:path ? [path lastPathComponent] : @"Cores"];
_delegate = delegate;
_game = path;
// Load the modules with their data // Load the modules with their data
NSArray* moduleList = [RAModuleInfo getModules]; NSArray* moduleList = [RAModuleInfo getModules];
@ -242,8 +219,8 @@
for (RAModuleInfo* i in moduleList) for (RAModuleInfo* i in moduleList)
{ {
if ([i supportsFileAtPath:_game]) [supported addObject:i]; if (path && [i supportsFileAtPath:path]) [supported addObject:i];
else [other addObject:i]; else [other addObject:i];
} }
if (supported.count > 1) if (supported.count > 1)
@ -257,7 +234,7 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (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 - (void)infoButtonTapped:(id)sender

View File

@ -17,13 +17,16 @@
#ifndef __RARCH_IOS_PLATFORM_H #ifndef __RARCH_IOS_PLATFORM_H
#define __RARCH_IOS_PLATFORM_H #define __RARCH_IOS_PLATFORM_H
#include "views.h"
@interface RAGameView : UIViewController @interface RAGameView : UIViewController
+ (RAGameView*)get; + (RAGameView*)get;
- (void)openPauseMenu; - (void)openPauseMenu;
- (void)closePauseMenu; - (void)closePauseMenu;
@end @end
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform> @interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform,
RADirectoryListDelegate, RAModuleListDelegate>
+ (RetroArch_iOS*)get; + (RetroArch_iOS*)get;

View File

@ -85,6 +85,7 @@ static void handle_touch_event(NSArray* touches)
@implementation RetroArch_iOS @implementation RetroArch_iOS
{ {
UIWindow* _window; UIWindow* _window;
NSString* _path;
bool _isGameTop, _isRomList; bool _isGameTop, _isRomList;
uint32_t _settingMenusInBackStack; 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)) 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); apple_display_alert([NSString stringWithFormat:@"Failed to create or access system directory: %@", self.systemDirectory], 0);
else else
{ [self beginBrowsingForFile];
[self pushViewController:[RADirectoryList directoryListAtBrowseRoot] animated:YES];
[self refreshSystemConfig];
if (apple_use_tv_mode)
apple_run_core(nil, 0);
}
// Warn if there are no cores present // Warn if there are no cores present
if ([RAModuleInfo getModules].count == 0) if ([RAModuleInfo getModules].count == 0)
@ -140,6 +136,45 @@ static void handle_touch_event(NSArray* touches)
apple_enter_stasis(); 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 // UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{ {

View File

@ -38,17 +38,22 @@
@end @end
// browser.m // browser.m
@protocol RADirectoryListDelegate
- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path;
@end
@interface RADirectoryList : RATableViewController <UIActionSheetDelegate> @interface RADirectoryList : RATableViewController <UIActionSheetDelegate>
@property (nonatomic, weak) RADirectoryItem *selectedItem; @property (nonatomic, weak) RADirectoryItem *selectedItem;
- (id)initWithPath:(NSString*)path delegate:(id<RADirectoryListDelegate>)delegate;
+ (id)directoryListAtBrowseRoot;
+ (id)directoryListForPath:(NSString*)path;
- (id)initWithPath:(NSString*)path;
@end @end
// browser.m // browser.m
@protocol RAModuleListDelegate
- (bool)moduleList:(id)list itemWasSelected:(RAModuleInfo*)module;
@end
@interface RAModuleList : RATableViewController @interface RAModuleList : RATableViewController
- (id)initWithGame:(NSString*)path; - (id)initWithGame:(NSString*)path delegate:(id<RAModuleListDelegate>)delegate;
@end @end
// browser.m // browser.m