2013-02-20 19:52:52 -05:00
/ * RetroArch - A frontend for libretro .
2014-01-01 01:50:59 +01:00
* Copyright ( C ) 2013 -2014 - Jason Fetters
2015-01-07 17:46:50 +01:00
* Copyright ( C ) 2014 -2015 - Jay McCarthy
2013-02-20 19:52:52 -05:00
*
* RetroArch is free software : you can redistribute it and / or modify it under the terms
* of the GNU General Public License as published by the Free Software Found -
* ation , either version 3 of the License , or ( at your option ) any later version .
*
* RetroArch is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE . See the GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along with RetroArch .
* If not , see < http : // www . gnu . org / licenses / > .
* /
2014-05-22 18:54:10 +02:00
# include "../../file_extract.h"
2013-12-16 20:15:24 -05:00
2014-05-22 18:54:10 +02:00
# import "../common/RetroArch_Apple.h"
2013-06-14 00:45:35 -04:00
# import "views.h"
2014-10-21 23:56:51 +02:00
# include "../../content.h"
2015-01-01 18:47:39 +01:00
# include "../../general.h"
2014-10-22 01:13:05 +02:00
# include < file / dir_list . h >
2014-10-21 23:56:51 +02:00
# include "../../file_ops.h"
2014-10-22 00:23:06 +02:00
# include < file / file_path . h >
2015-01-17 05:47:33 +01:00
# include < retro_miscellaneous . h >
2013-02-20 23:30:56 -05:00
2013-09-24 19:34:59 -04:00
static const void * const associated_module _key = & associated_module _key ;
2015-02-23 01:23:21 +01:00
static int zlib_extract _callback ( const char * name , const char * valid_exts ,
2015-01-31 12:03:38 +01:00
const uint8_t * cdata , unsigned cmode , uint32_t csize , uint32_t size ,
uint32_t crc32 , void * userdata )
2013-12-16 20:15:24 -05:00
{
2015-01-31 12:03:38 +01:00
char path [ PATH_MAX _LENGTH ] ;
2015-01-17 05:47:33 +01:00
/ * Make directory * /
2013-12-16 20:15:24 -05:00
fill_pathname _join ( path , ( const char * ) userdata , name , sizeof ( path ) ) ;
path_basedir ( path ) ;
2014-07-22 07:25:36 +02:00
2014-07-22 18:33:54 +02:00
if ( ! path_mkdir ( path ) )
2014-07-22 07:25:36 +02:00
{
2014-07-22 18:33:54 +02:00
RARCH_ERR ( "Failed to create dir: %s.\n" , path ) ;
2014-07-22 07:25:36 +02:00
return false ;
}
2013-12-16 20:15:24 -05:00
// Ignore directories
if ( name [ strlen ( name ) - 1 ] = = ' / ' )
2015-02-23 01:23:21 +01:00
return 1 ;
2014-09-20 22:56:41 -04:00
2014-07-20 21:30:31 +02:00
fill_pathname _join ( path , ( const char * ) userdata , name , sizeof ( path ) ) ;
2014-09-20 22:56:41 -04:00
2013-12-16 20:15:24 -05:00
switch ( cmode )
{
case 0 : // Uncompressed
write_file ( path , cdata , size ) ;
2014-07-19 06:41:46 +02:00
break ;
2013-12-16 20:15:24 -05:00
case 8 : // Deflate
2015-01-30 20:51:08 +01:00
zlib_inflate _data _to _file ( path , valid_exts , cdata , csize , size , crc32 ) ;
2014-07-19 06:41:46 +02:00
break ;
2013-12-16 20:15:24 -05:00
}
2015-02-23 01:23:21 +01:00
return 1 ;
2013-12-16 20:15:24 -05:00
}
static void unzip_file ( const char * path , const char * output_directory )
{
if ( ! path_file _exists ( path ) )
2014-05-03 21:34:13 +02:00
apple_display _alert ( "Could not locate zip file." , "Action Failed" ) ;
2013-12-16 20:15:24 -05:00
else if ( path_is _directory ( output_directory ) )
2014-05-03 21:34:13 +02:00
apple_display _alert ( "Output directory for zip must not already exist." , "Action Failed" ) ;
2013-12-16 20:15:24 -05:00
else if ( ! path_mkdir ( output_directory ) )
2014-05-03 21:34:13 +02:00
apple_display _alert ( "Could not create output directory to extract zip." , "Action Failed" ) ;
2015-01-30 20:41:54 +01:00
else if ( ! zlib_parse _file ( path , NULL , zlib_extract _callback , ( void * ) output_directory ) )
2014-05-03 21:34:13 +02:00
apple_display _alert ( "Could not process zip file." , "Action Failed" ) ;
2013-12-16 20:15:24 -05:00
}
enum file_action { FA_DELETE = 10000 , FA_CREATE , FA_MOVE , FA_UNZIP } ;
2013-09-24 19:34:59 -04:00
static void file_action ( enum file_action action , NSString * source , NSString * target )
{
NSError * error = nil ;
bool result = false ;
NSFileManager * manager = [ NSFileManager defaultManager ] ;
2014-09-20 22:56:41 -04:00
2013-09-24 19:34:59 -04:00
switch ( action )
{
2014-07-19 06:41:46 +02:00
case FA_DELETE :
result = [ manager removeItemAtPath : target error : & error ] ;
break ;
case FA_CREATE :
result = [ manager createDirectoryAtPath : target withIntermediateDirectories : YES
attributes : nil error : & error ] ;
break ;
case FA_MOVE :
result = [ manager moveItemAtPath : source toPath : target error : & error ] ;
break ;
case FA_UNZIP :
2014-07-20 21:30:31 +02:00
unzip_file ( source . UTF8String , target . UTF8String ) ;
2014-07-19 06:41:46 +02:00
break ;
2013-09-24 19:34:59 -04:00
}
if ( ! result && error )
2014-05-03 21:34:13 +02:00
apple_display _alert ( error . localizedDescription . UTF8String , "Action failed" ) ;
2013-09-24 19:34:59 -04:00
}
2013-11-22 15:30:02 +01:00
@ implementation RADirectoryItem
+ ( RADirectoryItem * ) directoryItemFromPath : ( NSString * ) path
{
RADirectoryItem * item = [ RADirectoryItem new ] ;
2015-01-07 01:18:41 +01:00
if ( ! item )
return NULL ;
2013-11-22 15:30:02 +01:00
item . path = path ;
2013-12-24 14:03:43 -05:00
item . isDirectory = path_is _directory ( path . UTF8String ) ;
2015-01-07 01:18:41 +01:00
2013-11-22 15:30:02 +01:00
return item ;
}
+ ( RADirectoryItem * ) directoryItemFromElement : ( struct string_list _elem * ) element
{
RADirectoryItem * item = [ RADirectoryItem new ] ;
2015-01-07 01:18:41 +01:00
if ( ! item )
return NULL ;
2013-12-12 14:49:18 -05:00
item . path = BOXSTRING ( element -> data ) ;
2014-09-04 21:46:14 +02:00
item . isDirectory = ( element -> attr . i = = RARCH_DIRECTORY ) ;
2015-01-07 01:18:41 +01:00
2013-11-22 15:30:02 +01:00
return item ;
}
- ( UITableViewCell * ) cellForTableView : ( UITableView * ) tableView
{
static NSString * const cell_id = @ "path_item" ;
static NSString * const icon_types [ 2 ] = { @ "ic_file" , @ "ic_dir" } ;
uint32_t type_id = self . isDirectory ? 1 : 0 ;
UITableViewCell * result = [ tableView dequeueReusableCellWithIdentifier : cell_id ] ;
2015-01-07 01:18:41 +01:00
2013-11-22 15:30:02 +01:00
if ( ! result )
result = [ [ UITableViewCell alloc ] initWithStyle : UITableViewCellStyleDefault reuseIdentifier : cell_id ] ;
result . textLabel . text = [ self . path lastPathComponent ] ;
result . imageView . image = [ UIImage imageNamed : icon_types [ type_id ] ] ;
2014-09-20 22:56:41 -04:00
2013-11-22 15:30:02 +01:00
return result ;
}
- ( void ) wasSelectedOnTableView : ( UITableView * ) tableView ofController : ( UIViewController * ) controller
{
if ( self . isDirectory )
[ ( id ) controller browseTo : self . path ] ;
else
2013-12-26 01:43:10 -05:00
[ ( id ) controller chooseAction ] ( ( id ) controller , self ) ;
2013-11-22 15:30:02 +01:00
}
@ end
2013-06-05 23:12:22 -04:00
@ implementation RADirectoryList
2013-04-04 07:54:33 +02:00
2013-12-26 01:43:10 -05:00
- ( id ) initWithPath : ( NSString * ) path extensions : ( const char * ) extensions action : ( void ( ^ ) ( RADirectoryList * list , RADirectoryItem * item ) ) action
2013-04-04 07:54:33 +02:00
{
2013-11-22 15:30:02 +01:00
if ( ( self = [ super initWithStyle : UITableViewStylePlain ] ) )
2013-09-24 19:34:59 -04:00
{
2014-09-20 22:56:41 -04:00
self . path = path ? path : NSHomeDirectory ( ) ;
self . chooseAction = action ;
self . extensions = extensions ? BOXSTRING ( extensions ) : 0 ;
2013-09-24 19:34:59 -04:00
self . hidesHeaders = YES ;
2014-09-20 22:56:41 -04:00
2013-12-24 14:03:43 -05:00
self . navigationItem . leftBarButtonItem = [ [ UIBarButtonItem alloc ] initWithTitle : @ "Up" style : UIBarButtonItemStyleBordered target : self
action : @ selector ( gotoParent ) ] ;
self . navigationItem . rightBarButtonItem = [ [ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemCancel target : self
action : @ selector ( cancelBrowser ) ] ;
2013-09-24 19:34:59 -04:00
2013-11-29 16:04:37 -05:00
// NOTE : The "App" and "Root" buttons aren ' t really needed for non - jailbreak devices .
2013-12-24 14:03:43 -05:00
NSMutableArray * toolbarButtons = [ NSMutableArray arrayWithObjects :
2013-11-29 16:04:37 -05:00
[ [ UIBarButtonItem alloc ] initWithTitle : @ "Home" style : UIBarButtonItemStyleBordered target : self
action : @ selector ( gotoHomeDir ) ] ,
[ [ UIBarButtonItem alloc ] initWithTitle : @ "App" style : UIBarButtonItemStyleBordered target : self
action : @ selector ( gotoAppDir ) ] ,
[ [ UIBarButtonItem alloc ] initWithTitle : @ "Root" style : UIBarButtonItemStyleBordered target : self
action : @ selector ( gotoRootDir ) ] ,
2013-09-24 19:34:59 -04:00
[ [ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemFlexibleSpace target : self
action : nil ] ,
2013-11-29 16:04:37 -05:00
[ [ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemRefresh target : self
action : @ selector ( refresh ) ] ,
2013-09-24 19:34:59 -04:00
[ [ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemAdd target : self
2013-12-24 14:03:43 -05:00
action : @ selector ( createNewFolder ) ] ,
nil
2013-09-24 19:34:59 -04:00
] ;
2014-09-20 22:56:41 -04:00
2013-12-24 14:03:43 -05:00
self . toolbarItems = toolbarButtons ;
2013-09-24 19:34:59 -04:00
[ self . tableView addGestureRecognizer : [ [ UILongPressGestureRecognizer alloc ] initWithTarget : self
action : @ selector ( fileAction : ) ] ] ;
}
2013-04-04 07:54:33 +02:00
2013-06-12 20:00:25 -04:00
return self ;
}
2013-12-24 14:03:43 -05:00
- ( void ) cancelBrowser
{
[ self . navigationController popViewControllerAnimated : YES ] ;
}
- ( void ) gotoParent
{
2014-09-20 22:56:41 -04:00
[ self browseTo : [ self . path stringByDeletingLastPathComponent ] ] ;
2013-12-24 14:03:43 -05:00
}
2013-11-29 16:04:37 -05:00
- ( void ) gotoHomeDir
{
[ self browseTo : NSHomeDirectory ( ) ] ;
}
- ( void ) gotoAppDir
{
[ self browseTo : NSBundle . mainBundle . bundlePath ] ;
}
- ( void ) gotoRootDir
{
[ self browseTo : @ "/" ] ;
}
2013-12-16 18:15:50 -05:00
- ( void ) refresh
{
2014-09-20 22:56:41 -04:00
[ self browseTo : self . path ] ;
2013-12-16 18:15:50 -05:00
}
2013-11-22 15:30:02 +01:00
- ( void ) browseTo : ( NSString * ) path
2013-08-24 20:36:03 -04:00
{
2015-03-20 22:41:15 +01:00
settings_t * settings = config_get _ptr ( ) ;
2014-09-20 22:56:41 -04:00
self . path = path ;
self . title = self . path . lastPathComponent ;
2013-08-24 20:36:03 -04:00
2015-01-07 01:18:41 +01:00
/ * Need one array per section . * /
2013-09-24 19:34:59 -04:00
self . sections = [ NSMutableArray array ] ;
2014-09-20 22:56:41 -04:00
2013-09-24 19:34:59 -04:00
for ( NSString * i in [ self sectionIndexTitlesForTableView : self . tableView ] )
[ self . sections addObject : [ NSMutableArray arrayWithObject : i ] ] ;
2014-09-20 22:56:41 -04:00
2015-01-07 01:18:41 +01:00
/ * List contents * /
2015-03-20 22:41:15 +01:00
struct string_list * contents = dir_list _new ( self . path . UTF8String ,
settings -> menu . navigation . browser . filter . supported_extensions _enable ? self . extensions . UTF8String : NULL , true ) ;
2014-09-20 22:56:41 -04:00
2013-06-09 20:13:05 -04:00
if ( contents )
2013-06-05 23:12:22 -04:00
{
2015-01-07 01:18:41 +01:00
ssize_t i ;
2013-12-24 14:03:43 -05:00
RADirectoryList __weak * weakSelf = self ;
2014-09-20 22:56:41 -04:00
2013-12-24 14:03:43 -05:00
if ( self . allowBlank )
[ self . sections [ 0 ] addObject : [ RAMenuItemBasic itemWithDescription : @ "[ Use Empty Path ]"
2013-12-26 01:43:10 -05:00
action : ^ { weakSelf . chooseAction ( weakSelf , nil ) ; } ] ] ;
2013-12-24 14:03:43 -05:00
if ( self . forDirectory )
[ self . sections [ 0 ] addObject : [ RAMenuItemBasic itemWithDescription : @ "[ Use This Folder ]"
2013-12-26 01:43:10 -05:00
action : ^ { weakSelf . chooseAction ( weakSelf , [ RADirectoryItem directoryItemFromPath : path ] ) ; } ] ] ;
2013-12-24 14:03:43 -05:00
2013-06-09 20:13:05 -04:00
dir_list _sort ( contents , true ) ;
2014-09-20 22:56:41 -04:00
2015-01-07 01:18:41 +01:00
for ( i = 0 ; i < contents -> size ; i + + )
2013-06-09 20:13:05 -04:00
{
const char * basename = path_basename ( contents -> elems [ i ] . data ) ;
2014-09-20 22:56:41 -04:00
2013-06-09 20:13:05 -04:00
uint32_t section = isalpha ( basename [ 0 ] ) ? ( toupper ( basename [ 0 ] ) - ' A ' ) + 2 : 1 ;
2014-11-11 12:11:48 -05:00
char is_directory = ( contents -> elems [ i ] . attr . i = = RARCH_DIRECTORY ) ;
section = is_directory ? 0 : section ;
2013-06-14 00:45:35 -04:00
2014-11-11 12:11:48 -05:00
if ( ! ( self . forDirectory && ! is_directory ) ) {
[ self . sections [ section ] addObject : [ RADirectoryItem directoryItemFromElement : & contents -> elems [ i ] ] ] ;
}
2013-06-09 20:13:05 -04:00
}
2014-09-20 22:56:41 -04:00
2013-06-09 20:13:05 -04:00
dir_list _free ( contents ) ;
2013-06-05 23:12:22 -04:00
}
else
2013-12-24 14:03:43 -05:00
{
[ self gotoHomeDir ] ;
return ;
}
2013-11-22 15:30:02 +01:00
[ self . tableView scrollRectToVisible : CGRectMake ( 0 , 0 , 1 , 1 ) animated : NO ] ;
[ UIView transitionWithView : self . tableView duration : .25 f options : UIViewAnimationOptionTransitionCrossDissolve
animations :
^ {
[ self . tableView reloadData ] ;
} completion : nil ] ;
2013-04-04 07:54:33 +02:00
}
2013-11-22 15:30:02 +01:00
- ( void ) viewWillAppear : ( BOOL ) animated
2013-04-04 07:54:33 +02:00
{
2013-11-22 15:30:02 +01:00
[ super viewWillAppear : animated ] ;
2014-09-20 22:56:41 -04:00
[ self browseTo : self . path ] ;
2013-11-22 15:30:02 +01:00
}
2013-08-24 20:36:03 -04:00
2013-11-22 15:30:02 +01:00
- ( NSArray * ) sectionIndexTitlesForTableView : ( UITableView * ) tableView
{
static NSArray * names = nil ;
2013-09-24 19:34:59 -04:00
2013-11-22 15:30:02 +01:00
if ( ! names )
names = @ [ @ "/" , @ "#" , @ "A" , @ "B" , @ "C" , @ "D" , @ "E" , @ "F" , @ "G" , @ "H" , @ "I" , @ "J" , @ "K" , @ "L" ,
@ "M" , @ "N" , @ "O" , @ "P" , @ "Q" , @ "R" , @ "S" , @ "T" , @ "U" , @ "V" , @ "W" , @ "X" , @ "Y" , @ "Z" ] ;
2013-04-04 07:54:33 +02:00
2013-11-22 15:30:02 +01:00
return names ;
}
2013-09-24 19:34:59 -04:00
// File management
// Called as a selector from a toolbar button
- ( void ) createNewFolder
2013-09-21 19:25:24 -04:00
{
2013-09-24 19:34:59 -04:00
UIAlertView * alertView = [ [ UIAlertView alloc ] initWithTitle : @ "Enter new folder name" message : @ "" delegate : self
cancelButtonTitle : @ "Cancel" otherButtonTitles : @ "OK" , nil ] ;
alertView . alertViewStyle = UIAlertViewStylePlainTextInput ;
alertView . tag = FA_CREATE ;
[ alertView show ] ;
2013-07-11 23:40:40 -03:00
}
2013-09-24 19:34:59 -04:00
// Called by the long press gesture recognizer
- ( void ) fileAction : ( UILongPressGestureRecognizer * ) gesture
2013-09-21 19:25:24 -04:00
{
2013-09-24 19:34:59 -04:00
if ( gesture . state = = UIGestureRecognizerStateBegan )
{
CGPoint point = [ gesture locationInView : self . tableView ] ;
2014-10-20 19:33:50 +02:00
NSIndexPath * idx_path = [ self . tableView indexPathForRowAtPoint : point ] ;
2014-09-20 22:56:41 -04:00
2014-10-20 19:33:50 +02:00
if ( idx_path )
2013-09-24 19:34:59 -04:00
{
2015-01-07 01:18:41 +01:00
bool is_zip ;
UIActionSheet * menu ;
2015-02-25 00:09:36 +01:00
NSString * button4_name = ( get_ios _version _major ( ) >= 7 ) ? @ "AirDrop" : @ "Delete" ;
NSString * button5_name = ( get_ios _version _major ( ) >= 7 ) ? @ "Delete" : nil ;
2015-01-07 01:18:41 +01:00
2014-10-20 19:33:50 +02:00
self . selectedItem = [ self itemForIndexPath : idx_path ] ;
2015-01-07 01:18:41 +01:00
is_zip = ! ( strcmp ( self . selectedItem . path . pathExtension . UTF8String , "zip" ) ) ;
2013-09-24 19:34:59 -04:00
2015-01-07 01:18:41 +01:00
menu = [ [ UIActionSheet alloc ] initWithTitle : self . selectedItem . path . lastPathComponent delegate : self
2013-09-24 19:34:59 -04:00
cancelButtonTitle : @ "Cancel" destructiveButtonTitle : nil
2013-12-16 22:51:00 -05:00
otherButtonTitles : is_zip ? @ "Unzip" : @ "Zip" , @ "Move" , @ "Rename" , button4_name , button5_name , nil ] ;
2013-09-24 19:34:59 -04:00
[ menu showFromToolbar : self . navigationController . toolbar ] ;
}
}
}
2015-01-07 01:18:41 +01:00
/ * Called by the action sheet created in ( void ) fileAction : * /
2013-09-24 19:34:59 -04:00
- ( void ) actionSheet : ( UIActionSheet * ) actionSheet clickedButtonAtIndex : ( NSInteger ) buttonIndex
{
NSString * target = self . selectedItem . path ;
2013-12-16 22:51:00 -05:00
NSString * action = [ actionSheet buttonTitleAtIndex : buttonIndex ] ;
2015-01-07 01:18:41 +01:00
if ( ! strcmp ( action . UTF8String , "Unzip" ) )
2013-12-16 20:15:24 -05:00
{
2013-12-16 22:51:00 -05:00
UIAlertView * alertView = [ [ UIAlertView alloc ] initWithTitle : @ "Enter target directory" message : @ "" delegate : self
2013-12-16 20:15:24 -05:00
cancelButtonTitle : @ "Cancel" otherButtonTitles : @ "OK" , nil ] ;
2013-12-16 22:51:00 -05:00
alertView . alertViewStyle = UIAlertViewStylePlainTextInput ;
alertView . tag = FA_UNZIP ;
[ alertView textFieldAtIndex : 0 ] . text = [ [ target lastPathComponent ] stringByDeletingPathExtension ] ;
[ alertView show ] ;
2013-12-16 20:15:24 -05:00
}
2015-01-07 01:18:41 +01:00
else if ( ! strcmp ( action . UTF8String , "Move" ) )
2013-09-24 19:34:59 -04:00
[ self . navigationController pushViewController : [ [ RAFoldersList alloc ] initWithFilePath : target ] animated : YES ] ;
2015-01-07 01:18:41 +01:00
else if ( ! strcmp ( action . UTF8String , "Rename" ) )
2013-09-21 19:25:24 -04:00
{
2015-01-07 01:18:41 +01:00
UIAlertView * alertView = [ [ UIAlertView alloc ] initWithTitle : @ "Enter new name" message : @ "" delegate : self cancelButtonTitle : @ "Cancel" otherButtonTitles : @ "OK" , nil ] ;
2013-09-21 19:25:24 -04:00
alertView . alertViewStyle = UIAlertViewStylePlainTextInput ;
2013-09-24 19:34:59 -04:00
alertView . tag = FA_MOVE ;
[ alertView textFieldAtIndex : 0 ] . text = target . lastPathComponent ;
2013-09-21 19:25:24 -04:00
[ alertView show ] ;
}
2013-12-16 22:51:00 -05:00
# ifdef __IPHONE _7 _0
2015-02-25 00:09:36 +01:00
else if ( ! strcmp ( action . UTF8String , "AirDrop" ) && ( get_ios _version _major ( ) >= 7 ) )
2013-12-16 22:51:00 -05:00
{
// TODO : Zip if not already zipped
2014-09-20 22:56:41 -04:00
2013-12-16 22:51:00 -05:00
NSURL * url = [ NSURL fileURLWithPath : self . selectedItem . path isDirectory : self . selectedItem . isDirectory ] ;
NSArray * items = [ NSArray arrayWithObject : url ] ;
UIActivityViewController * avc = [ [ UIActivityViewController alloc ] initWithActivityItems : items applicationActivities : nil ] ;
2014-09-20 22:56:41 -04:00
2013-12-16 22:51:00 -05:00
[ self presentViewController : avc animated : YES completion : nil ] ;
}
# endif
2015-01-07 01:18:41 +01:00
else if ( ! strcmp ( action . UTF8String , "Delete" ) )
2013-09-21 19:25:24 -04:00
{
2015-01-07 01:18:41 +01:00
UIAlertView * alertView = [ [ UIAlertView alloc ] initWithTitle : @ "Really delete?" message : @ "" delegate : self cancelButtonTitle : @ "Cancel" otherButtonTitles : @ "OK" , nil ] ;
2013-09-24 19:34:59 -04:00
alertView . tag = FA_DELETE ;
[ alertView show ] ;
}
2015-01-07 01:18:41 +01:00
else if ( ! strcmp ( action . UTF8String , "Cancel" ) ) / * Zip * /
2014-05-03 21:34:13 +02:00
apple_display _alert ( "Action not supported." , "Action Failed" ) ;
2013-07-09 16:51:02 -03:00
}
2013-09-24 19:34:59 -04:00
// Called by various alert views created in this class , the alertView . tag value is the action to take .
- ( void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex
2013-09-21 19:25:24 -04:00
{
2013-09-24 20:35:56 -04:00
if ( buttonIndex ! = alertView . firstOtherButtonIndex )
return ;
2013-09-24 19:34:59 -04:00
if ( alertView . tag = = FA_DELETE )
file_action ( FA_DELETE , nil , self . selectedItem . path ) ;
else
2013-09-21 19:25:24 -04:00
{
2013-09-24 19:34:59 -04:00
NSString * text = [ alertView textFieldAtIndex : 0 ] . text ;
2013-09-24 20:35:56 -04:00
if ( text . length )
2014-09-20 22:56:41 -04:00
file_action ( ( enum file_action ) alertView . tag , self . selectedItem . path , [ self . path stringByAppendingPathComponent : text ] ) ;
2013-09-21 19:25:24 -04:00
}
2014-09-20 22:56:41 -04:00
[ self browseTo : self . path ] ;
2013-07-09 16:51:02 -03:00
}
2013-06-14 00:45:35 -04:00
@ end
2013-11-22 15:30:02 +01:00
@ interface RAFoldersList ( )
@ property ( nonatomic ) NSString * path ;
2013-07-11 23:40:40 -03:00
@ end
2013-09-21 19:25:24 -04:00
@ implementation RAFoldersList
2013-07-11 23:40:40 -03:00
2013-09-21 19:25:24 -04:00
- ( id ) initWithFilePath : ( NSString * ) path
2013-07-11 23:40:40 -03:00
{
2013-11-22 15:30:02 +01:00
if ( ( self = [ super initWithStyle : UITableViewStyleGrouped ] ) )
2013-09-21 19:25:24 -04:00
{
2013-11-22 15:30:02 +01:00
RAFoldersList * __weak weakSelf = self ;
2014-09-20 22:56:41 -04:00
self . path = path ;
2013-07-11 23:40:40 -03:00
2013-11-22 15:30:02 +01:00
// Parent item
2014-09-20 22:56:41 -04:00
NSString * sourceItem = self . path . stringByDeletingLastPathComponent ;
2014-05-12 15:26:46 +02:00
RAMenuItemBasic * parentItem = [ RAMenuItemBasic itemWithDescription : BOXSTRING ( "<Parent>" ) association : sourceItem . stringByDeletingLastPathComponent
2013-11-22 15:30:02 +01:00
action : ^ ( id userdata ) { [ weakSelf moveInto : userdata ] ; } detail : NULL ] ;
2014-05-12 15:26:46 +02:00
[ self . sections addObject : @ [ BOXSTRING ( "" ) , parentItem ] ] ;
2013-11-22 15:30:02 +01:00
2013-09-24 19:34:59 -04:00
// List contents
2015-01-01 18:47:39 +01:00
struct string_list * contents = dir_list _new ( [ self . path stringByDeletingLastPathComponent ] . UTF8String , NULL , true ) ;
2014-05-12 15:26:46 +02:00
NSMutableArray * items = [ NSMutableArray arrayWithObject : BOXSTRING ( "" ) ] ;
2014-09-20 22:56:41 -04:00
2013-09-24 19:34:59 -04:00
if ( contents )
2013-09-21 19:25:24 -04:00
{
2014-09-20 21:38:59 -04:00
size_t i ;
2013-09-24 19:34:59 -04:00
dir_list _sort ( contents , true ) ;
2014-05-12 15:26:46 +02:00
for ( i = 0 ; i < contents -> size ; i + + )
2013-09-21 19:25:24 -04:00
{
2014-09-04 21:46:14 +02:00
if ( contents -> elems [ i ] . attr . i = = RARCH_DIRECTORY )
2013-09-24 19:34:59 -04:00
{
const char * basename = path_basename ( contents -> elems [ i ] . data ) ;
2014-09-20 22:56:41 -04:00
2013-12-12 14:49:18 -05:00
RAMenuItemBasic * item = [ RAMenuItemBasic itemWithDescription : BOXSTRING ( basename ) association : BOXSTRING ( contents -> elems [ i ] . data )
2013-11-22 15:30:02 +01:00
action : ^ ( id userdata ) { [ weakSelf moveInto : userdata ] ; } detail : NULL ] ;
[ items addObject : item ] ;
2013-09-24 19:34:59 -04:00
}
2013-09-21 19:25:24 -04:00
}
2014-09-20 22:56:41 -04:00
2013-09-24 19:34:59 -04:00
dir_list _free ( contents ) ;
}
2014-09-20 22:56:41 -04:00
[ self setTitle : [ BOXSTRING ( "Move " ) stringByAppendingString : self . path . lastPathComponent ] ] ;
2013-09-24 19:34:59 -04:00
[ self . sections addObject : items ] ;
2013-09-21 19:25:24 -04:00
}
2013-07-11 23:40:40 -03:00
2013-09-21 19:25:24 -04:00
return self ;
2013-07-11 23:40:40 -03:00
}
2013-11-22 15:30:02 +01:00
- ( void ) moveInto : ( NSString * ) path
2013-07-11 23:40:40 -03:00
{
2013-11-22 15:30:02 +01:00
NSString * targetPath = [ path stringByAppendingPathComponent : self . path . lastPathComponent ] ;
file_action ( FA_MOVE , self . path , targetPath ) ;
2013-09-24 19:34:59 -04:00
[ self . navigationController popViewControllerAnimated : YES ] ;
2013-07-11 23:40:40 -03:00
}
2013-04-04 07:54:33 +02:00
@ end