From 73fc504546f61534fca594b75bc45f46f3972c57 Mon Sep 17 00:00:00 2001 From: meancoot Date: Sat, 9 Feb 2013 13:49:04 -0500 Subject: [PATCH] ios: File browser cleanup. --- ios/RetroArch/directory_list.m | 60 ++++++++++++++++------------------ 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/ios/RetroArch/directory_list.m b/ios/RetroArch/directory_list.m index 5e84f988ff..c8b74543ea 100644 --- a/ios/RetroArch/directory_list.m +++ b/ios/RetroArch/directory_list.m @@ -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; }