ios: File browser cleanup.

This commit is contained in:
meancoot 2013-02-09 13:49:04 -05:00
parent 7cbfae88c1
commit 73fc504546

View File

@ -6,6 +6,13 @@
// Copyright (c) 2013 RetroArch. All rights reserved.
//
static BOOL is_directory(NSString* path)
{
BOOL result = NO;
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&result];
return result;
}
@implementation directory_list
{
NSString* directory;
@ -23,13 +30,12 @@
list = [list sortedArrayUsingComparator:^(id left, id right)
{
BOOL left_is_dir;
BOOL right_is_dir;
const BOOL left_is_dir = is_directory((NSString*)left);
const BOOL right_is_dir = is_directory((NSString*)right);
[[NSFileManager defaultManager] fileExistsAtPath:left isDirectory:&left_is_dir];
[[NSFileManager defaultManager] fileExistsAtPath:right isDirectory:&right_is_dir];
return (left_is_dir != right_is_dir) ? (left_is_dir < right_is_dir) : ([left caseInsensitiveCompare:right]);
return (left_is_dir != right_is_dir) ?
(left_is_dir ? -1 : 1) :
([left caseInsensitiveCompare:right]);
}];
self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button;
@ -41,23 +47,19 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* path = [list objectAtIndex: indexPath.row];
BOOL isdir;
if([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isdir])
if(is_directory(path))
{
if (isdir)
{
[[RetroArch_iOS get].navigator
pushViewController:[[directory_list alloc] initWithPath:path]
animated:YES];
}
else
{
[RetroArch_iOS get].window.rootViewController = [[game_view alloc] init];
[[RetroArch_iOS get].navigator
pushViewController:[[directory_list alloc] initWithPath:path]
animated:YES];
}
else
{
[RetroArch_iOS get].window.rootViewController = [[game_view alloc] init];
extern void ios_load_game(const char*);
ios_load_game([path UTF8String]);
}
extern void ios_load_game(const char*);
ios_load_game([path UTF8String]);
}
}
@ -68,18 +70,14 @@
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* path = [list objectAtIndex: indexPath.row];
BOOL isdir = is_directory(path);
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"path"];
cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"path"];
NSString* path = [list objectAtIndex: indexPath.row];
BOOL isdir;
if([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isdir])
{
cell.textLabel.text = [path lastPathComponent];
cell.accessoryType = (isdir) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
cell.imageView.image = (isdir) ? [RetroArch_iOS get].folder_icon : [RetroArch_iOS get].file_icon;
}
cell.textLabel.text = [path lastPathComponent];
cell.accessoryType = (isdir) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
cell.imageView.image = (isdir) ? [RetroArch_iOS get].folder_icon : [RetroArch_iOS get].file_icon;
return cell;
}