(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;
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
{
// 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<RADirectoryListDelegate>)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<RAModuleListDelegate> _delegate;
}
- (id)initWithGame:(NSString*)path
- (id)initWithGame:(NSString*)path delegate:(id<RAModuleListDelegate>)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

View File

@ -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<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform>
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform,
RADirectoryListDelegate, RAModuleListDelegate>
+ (RetroArch_iOS*)get;

View File

@ -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];
[self beginBrowsingForFile];
if (apple_use_tv_mode)
apple_run_core(nil, 0);
}
// 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
{

View File

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