Add parent dir in non root directory

There is probably a much better way to do this, but this works for now.
This commit is contained in:
Joel16 2019-05-14 12:31:56 -04:00
parent 4a2834ac2b
commit 1d22c961ef
3 changed files with 22 additions and 22 deletions

View File

@ -5,7 +5,7 @@
typedef struct File {
struct File *next; // Next item
int is_dir; // Folder flag
SceBool is_dir; // Folder flag
char name[256]; // File name
char ext[5]; // File extension
} File;

View File

@ -4,7 +4,7 @@
#include <vorbis/vorbisfile.h>
#include "audio.h"
#include "utils.h"
#include "common.h"
static OggVorbis_File ogg;
static SceUID ogg_file = 0;

View File

@ -58,8 +58,10 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {
files = NULL;
file_count = 0;
SceBool parent_dir_set = SCE_FALSE;
if (R_SUCCEEDED(dir = sceIoDopen(cwd))) {
int entryCount = 0, i = 0;
int entryCount = 0;
SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent));
while (sceIoDread(dir, &entries[entryCount]) > 0)
@ -68,28 +70,28 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {
sceIoDclose(dir);
qsort(entries, entryCount, sizeof(SceIoDirent), cmpstringp);
for (i = 0; i < entryCount; i++) {
// Ingore null filename
if (entries[i].d_name[0] == '\0')
continue;
// Ignore "." in all directories
if (!strcmp(entries[i].d_name, "."))
continue;
// Ignore ".." in Root Directory
if ((!strcmp(cwd, ROOT_PATH)) && (!strncmp(entries[i].d_name, "..", 2))) // Ignore ".." in Root Directory
continue;
for (int i = -1; i < entryCount; i++) {
// Allocate Memory
File *item = (File *)malloc(sizeof(File));
memset(item, 0, sizeof(File));
item->is_dir = SCE_S_ISDIR(entries[i].d_stat.st_mode);
if ((strcmp(cwd, ROOT_PATH)) && (i == -1) && (!parent_dir_set)) {
strcpy(item->name, "..");
item->is_dir = SCE_TRUE;
parent_dir_set = SCE_TRUE;
file_count++;
}
else {
if ((i == -1) && (!(strcmp(cwd, ROOT_PATH))))
continue;
// Copy File Name
strcpy(item->name, entries[i].d_name);
strcpy(item->ext, FS_GetFileExt(item->name));
item->is_dir = SCE_S_ISDIR(entries[i].d_stat.st_mode);
// Copy File Name
strcpy(item->name, entries[i].d_name);
strcpy(item->ext, FS_GetFileExt(item->name));
file_count++;
}
// New List
if (files == NULL)
@ -104,8 +106,6 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {
list->next = item;
}
file_count++;
}
free(entries);