mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 22:13:51 +00:00
ios: Add incomplete code for basic directory list.
This commit is contained in:
parent
7b9490db48
commit
8315a05f5f
@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
9629797716C3CD2400E6DCE0 /* dirlist.m in Sources */ = {isa = PBXBuildFile; fileRef = 9629797616C3CD2400E6DCE0 /* dirlist.m */; };
|
||||
968A572A16C2A06800BE12F8 /* test.img in Resources */ = {isa = PBXBuildFile; fileRef = 968A572816C2A06800BE12F8 /* test.img */; };
|
||||
96AFAE2A16C1D4EA009DE44C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2916C1D4EA009DE44C /* UIKit.framework */; };
|
||||
96AFAE2C16C1D4EA009DE44C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2B16C1D4EA009DE44C /* Foundation.framework */; };
|
||||
@ -76,6 +77,8 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
9629797516C3CD2400E6DCE0 /* dirlist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dirlist.h; sourceTree = "<group>"; };
|
||||
9629797616C3CD2400E6DCE0 /* dirlist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = dirlist.m; sourceTree = "<group>"; };
|
||||
968A572816C2A06800BE12F8 /* test.img */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.img; sourceTree = "<group>"; };
|
||||
96AFAE2516C1D4EA009DE44C /* RetroArch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RetroArch.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
96AFAE2916C1D4EA009DE44C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||
@ -329,6 +332,8 @@
|
||||
96AFAE4F16C1D4EA009DE44C /* ViewController_iPad.xib */,
|
||||
96AFAE3416C1D4EA009DE44C /* Supporting Files */,
|
||||
96CF015B16C2F72900ABF9C9 /* ios_input.c */,
|
||||
9629797516C3CD2400E6DCE0 /* dirlist.h */,
|
||||
9629797616C3CD2400E6DCE0 /* dirlist.m */,
|
||||
);
|
||||
path = RetroArch;
|
||||
sourceTree = "<group>";
|
||||
@ -773,6 +778,7 @@
|
||||
96AFAFDD16C2149A009DE44C /* ioseagl_ctx.m in Sources */,
|
||||
96CF015016C2C0B700ABF9C9 /* overlay.c in Sources */,
|
||||
96CF015C16C2F72900ABF9C9 /* ios_input.c in Sources */,
|
||||
9629797716C3CD2400E6DCE0 /* dirlist.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
12
ios/RetroArch/dirlist.h
Normal file
12
ios/RetroArch/dirlist.h
Normal file
@ -0,0 +1,12 @@
|
||||
//
|
||||
// UIViewController_m.h
|
||||
// RetroArch
|
||||
//
|
||||
// Copyright (c) 2013 RetroArch. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface DirectoryView : UIViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@end
|
140
ios/RetroArch/dirlist.m
Normal file
140
ios/RetroArch/dirlist.m
Normal file
@ -0,0 +1,140 @@
|
||||
//
|
||||
// dirlist.m
|
||||
// RetroArch
|
||||
//
|
||||
// Created by Jason Fetters on 2/7/13.
|
||||
// Copyright (c) 2013 RetroArch. All rights reserved.
|
||||
//
|
||||
|
||||
#include <dirent.h>
|
||||
#import "dirlist.h"
|
||||
|
||||
struct dirent_list
|
||||
{
|
||||
struct dirent_list* next;
|
||||
struct dirent entry;
|
||||
};
|
||||
|
||||
const struct dirent* get_dirent_at_index(struct dirent_list* list, unsigned index)
|
||||
{
|
||||
while (list && index)
|
||||
{
|
||||
list = list->next;
|
||||
index --;
|
||||
}
|
||||
|
||||
return list ? &list->entry : 0;
|
||||
}
|
||||
|
||||
unsigned get_dirent_list_count(struct dirent_list* list)
|
||||
{
|
||||
unsigned result = 0;
|
||||
|
||||
while (list)
|
||||
{
|
||||
result ++;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void free_dirent_list(struct dirent_list* list)
|
||||
{
|
||||
struct dirent_list* next = 0;
|
||||
if (list)
|
||||
{
|
||||
next = list->next;
|
||||
free(list);
|
||||
}
|
||||
|
||||
free_dirent_list(next);
|
||||
}
|
||||
|
||||
struct dirent_list* build_dirent_list(const char* path)
|
||||
{
|
||||
struct dirent_list* result = 0;
|
||||
struct dirent_list* iterate = 0;
|
||||
|
||||
DIR* dir = opendir(path);
|
||||
if (dir)
|
||||
{
|
||||
struct dirent* ent = 0;
|
||||
while ((ent = readdir(dir)))
|
||||
{
|
||||
if (!iterate)
|
||||
{
|
||||
iterate = malloc(sizeof(struct dirent_list));
|
||||
iterate->next = 0;
|
||||
result = iterate;
|
||||
}
|
||||
else
|
||||
{
|
||||
iterate->next = malloc(sizeof(struct dirent_list));
|
||||
iterate = iterate->next;
|
||||
iterate->next = 0;
|
||||
}
|
||||
|
||||
memcpy(&iterate->entry, ent, sizeof(struct dirent));
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@implementation DirectoryView
|
||||
{
|
||||
UITableView* table;
|
||||
struct dirent_list* files;
|
||||
};
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
free_dirent_list(files);
|
||||
files = 0;
|
||||
|
||||
// Do I need to kill table here?
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
files = build_dirent_list([NSTemporaryDirectory() UTF8String]);
|
||||
|
||||
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) style:UITableViewStylePlain];
|
||||
table.dataSource = self;
|
||||
table.delegate = self;
|
||||
|
||||
self.view = table;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
const struct dirent* item = get_dirent_at_index(files, indexPath.row);
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return get_dirent_list_count(files);
|
||||
}
|
||||
|
||||
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:@"path"];
|
||||
cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"path"];
|
||||
|
||||
const struct dirent* item = get_dirent_at_index(files, indexPath.row);
|
||||
|
||||
if (item)
|
||||
{
|
||||
cell.textLabel.text = [[NSString string] initWithUTF8String:item->d_name];
|
||||
cell.accessoryType = (item->d_type & DT_DIR) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user