-
Notifications
You must be signed in to change notification settings - Fork 11
/
RomLister.cpp
62 lines (52 loc) · 1.47 KB
/
RomLister.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <pico/stdlib.h>
#include <string.h>
#include "RomLister.h"
#include "FrensHelpers.h"
#include "tar.h"
inline bool checkNESMagic(const uint8_t *data);
// class to listing directories and .NES files
namespace Frens
{
// Buffer must have sufficient bytes to contain directory contents
RomLister::RomLister(uintptr_t NES_FILE_ADDR, void *buffer, size_t buffersize)
{
entries = (RomEntry *)buffer;
max_entries = buffersize / sizeof(RomEntry);
address = reinterpret_cast<const uint8_t *>(NES_FILE_ADDR);
numberOfEntries = 0;
}
RomLister::~RomLister()
{
}
RomLister::RomEntry *RomLister::GetEntries()
{
return entries;
}
char *RomLister::FolderName()
{
return directoryname;
}
size_t RomLister::Count()
{
return numberOfEntries;
}
// implementation of the compare function for qsort ignore case
int compareRomEntry(const void *a, const void *b)
{
const RomLister::RomEntry *entryA = (const RomLister::RomEntry *)a;
const RomLister::RomEntry *entryB = (const RomLister::RomEntry *)b;
return strcasecmp(entryA->Path, entryB->Path);
}
void RomLister::list( )
{
numberOfEntries = GetValidTAREntries(address, checkNESMagic);
for ( int i=0; i< numberOfEntries; i++) {
entries[i].Index = i;
entries[i].IsDirectory = false;
strcpy(entries[i].Path, extractTAREntryatindex(i, address, checkNESMagic).filename.data());
}
// sort the entries by Path
qsort(entries, numberOfEntries, sizeof(RomEntry), compareRomEntry);
}
}