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