2016-12-10 15:32:03 +01:00
|
|
|
#include "fsdir.h"
|
2016-11-15 23:06:01 +01:00
|
|
|
|
|
|
|
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
|
|
|
|
memcpy(dest, orig, sizeof(DirEntry));
|
|
|
|
dest->name = dest->path + (orig->name - orig->path);
|
|
|
|
}
|
|
|
|
|
2018-09-13 17:47:48 +09:00
|
|
|
int compDirEntry(const void* e1, const void* e2) {
|
|
|
|
const DirEntry* entry1 = (const DirEntry*) e1;
|
|
|
|
const DirEntry* entry2 = (const DirEntry*) e2;
|
|
|
|
if (entry1->type == T_DOTDOT) return -1;
|
|
|
|
if (entry2->type == T_DOTDOT) return 1;
|
|
|
|
if (entry1->type != entry2->type)
|
|
|
|
return entry1->type - entry2->type;
|
|
|
|
return strncasecmp(entry1->path, entry2->path, 256);
|
|
|
|
}
|
|
|
|
|
2016-11-15 23:06:01 +01:00
|
|
|
void SortDirStruct(DirStruct* contents) {
|
2018-09-13 17:47:48 +09:00
|
|
|
qsort(contents->entry, contents->n_entries, sizeof(DirEntry), compDirEntry);
|
2018-09-18 01:30:10 +02:00
|
|
|
// fix entry->names after qsort
|
2018-09-13 17:47:48 +09:00
|
|
|
for (int i = 0; i < (int)contents->n_entries; i++) {
|
|
|
|
DirEntry* entry = &(contents->entry[i]);
|
2018-09-18 01:30:10 +02:00
|
|
|
if ((entry->type == T_DIR) || (entry->type == T_FILE)) {
|
2018-09-13 17:47:48 +09:00
|
|
|
char* slash = strrchr(entry->path, '/');
|
|
|
|
entry->name = slash ? slash + 1 : entry->path;
|
2018-09-18 01:30:10 +02:00
|
|
|
} else {
|
|
|
|
// somewhat hacky, applies to T_DOTDOT and T_ROOT (see fsdrive.c)
|
|
|
|
entry->name = entry->path + 4;
|
2016-11-15 23:06:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|