ios: Fix symlinks in the file browser; remove the top entry of the path instead of appending '..' when going back a directory.
This commit is contained in:
parent
5f5be7c4dc
commit
80c0d35f58
|
@ -6,6 +6,7 @@
|
||||||
// Copyright (c) 2013 RetroArch. All rights reserved.
|
// Copyright (c) 2013 RetroArch. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#import "dirlist.h"
|
#import "dirlist.h"
|
||||||
#import "gameview.h"
|
#import "gameview.h"
|
||||||
|
@ -39,10 +40,8 @@ static int compare_dirent(const void *left, const void *right)
|
||||||
const struct dirent* r = (const struct dirent*) right;
|
const struct dirent* r = (const struct dirent*) right;
|
||||||
|
|
||||||
// Directories first
|
// Directories first
|
||||||
if ((l->d_type & DT_DIR) != (r->d_type & DT_DIR))
|
if (l->d_type != r->d_type)
|
||||||
{
|
return (l->d_type) ? -1 : 1;
|
||||||
return (l->d_type & DT_DIR) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
return strcmp(l->d_name, r->d_name);
|
return strcmp(l->d_name, r->d_name);
|
||||||
|
@ -65,6 +64,11 @@ struct dirent_list* build_dirent_list(const char* path)
|
||||||
}
|
}
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
|
|
||||||
|
// String buffer for 'stat'ing
|
||||||
|
char* stat_path = malloc(strlen(path) + sizeof(ent->d_name));
|
||||||
|
strcpy(stat_path, path);
|
||||||
|
uint32_t last_index = strlen(stat_path);
|
||||||
|
|
||||||
// Build and fill the result
|
// Build and fill the result
|
||||||
result = malloc(sizeof(struct dirent_list));
|
result = malloc(sizeof(struct dirent_list));
|
||||||
result->count = count;
|
result->count = count;
|
||||||
|
@ -74,10 +78,21 @@ struct dirent_list* build_dirent_list(const char* path)
|
||||||
while ((ent = readdir(dir)))
|
while ((ent = readdir(dir)))
|
||||||
{
|
{
|
||||||
if (strcmp(ent->d_name, ".") == 0) continue;
|
if (strcmp(ent->d_name, ".") == 0) continue;
|
||||||
memcpy(&result->entries[index ++], ent, sizeof(struct dirent));
|
memcpy(&result->entries[index], ent, sizeof(struct dirent));
|
||||||
|
|
||||||
|
// Chage dirent.d_type to a boolean indication if it is a directory
|
||||||
|
struct stat stat_buf;
|
||||||
|
strcat(stat_path, "/");
|
||||||
|
strcat(stat_path, ent->d_name);
|
||||||
|
stat(stat_path, &stat_buf);
|
||||||
|
result->entries[index].d_type = S_ISDIR(stat_buf.st_mode) ? 1 : 0;
|
||||||
|
stat_path[last_index] = 0;
|
||||||
|
|
||||||
|
index ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
free(stat_path);
|
||||||
|
|
||||||
qsort(result->entries, result->count, sizeof(struct dirent), &compare_dirent);
|
qsort(result->entries, result->count, sizeof(struct dirent), &compare_dirent);
|
||||||
}
|
}
|
||||||
|
@ -124,11 +139,21 @@ struct dirent_list* build_dirent_list(const char* path)
|
||||||
|
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
strcat(path, item->d_name);
|
if (item->d_type)
|
||||||
|
{
|
||||||
if (item->d_type & DT_DIR)
|
if (strcmp(item->d_name, "..") == 0)
|
||||||
|
{
|
||||||
|
char* last_slash = strrchr(path, '/');
|
||||||
|
if (last_slash) *last_slash = 0;
|
||||||
|
path[0] = (path[0] == 0) ? '/' : path[0];
|
||||||
|
printf("%s\n", path);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
strcat(path, "/");
|
strcat(path, "/");
|
||||||
|
strcat(path, item->d_name);
|
||||||
|
}
|
||||||
|
|
||||||
free_dirent_list(files);
|
free_dirent_list(files);
|
||||||
files = build_dirent_list(path);
|
files = build_dirent_list(path);
|
||||||
[table reloadData];
|
[table reloadData];
|
||||||
|
@ -142,6 +167,9 @@ struct dirent_list* build_dirent_list(const char* path)
|
||||||
else
|
else
|
||||||
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
|
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
|
||||||
|
|
||||||
|
strcat(path, "/");
|
||||||
|
strcat(path, item->d_name);
|
||||||
|
|
||||||
extern void ios_load_game(const char*);
|
extern void ios_load_game(const char*);
|
||||||
ios_load_game(path);
|
ios_load_game(path);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +191,7 @@ struct dirent_list* build_dirent_list(const char* path)
|
||||||
{
|
{
|
||||||
cell.textLabel.text = [[NSString string] initWithUTF8String:item->d_name];
|
cell.textLabel.text = [[NSString string] initWithUTF8String:item->d_name];
|
||||||
|
|
||||||
if (item->d_type & DT_DIR)
|
if (item->d_type)
|
||||||
{
|
{
|
||||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||||
cell.imageView.image = folder_icon;
|
cell.imageView.image = folder_icon;
|
||||||
|
|
Loading…
Reference in New Issue