Skip to content

Commit 9b45b9f

Browse files
committed
Sort overlay list according to their file name
1 parent df27b52 commit 9b45b9f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

libs/libtesla

source/main.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ static void rebuildUI() {
9292
renderer->drawString("Place your .ovl files in /switch/.overlays", false, 82, 410, 15, renderer->a(tsl::style::color::ColorDescription));
9393
});
9494

95-
u16 entries = 0;
95+
std::vector<std::filesystem::directory_entry> overlayFiles;
96+
9697
fsdevMountSdmc();
9798
for (const auto &entry : std::filesystem::directory_iterator("sdmc:/switch/.overlays")) {
9899
if (entry.path().filename() == "ovlmenu.ovl")
@@ -101,13 +102,21 @@ static void rebuildUI() {
101102
if (entry.path().extension() != ".ovl")
102103
continue;
103104

105+
overlayFiles.push_back(entry);
106+
}
107+
108+
std::sort(overlayFiles.begin(), overlayFiles.end(), [](const auto &left, const auto &right) {
109+
return left.path().filename() < right.path().filename();
110+
});
111+
112+
for (const auto &entry : overlayFiles) {
104113
auto [result, name, version] = getOverlayInfo(entry.path());
105114
if (result != ResultSuccess)
106115
continue;
107116

108117
auto *listEntry = new tsl::elm::ListItem(name);
109118
listEntry->setValue(version, true);
110-
listEntry->setClickListener([entry, entries](s64 key) {
119+
listEntry->setClickListener([entry](s64 key) {
111120
if (key & HidNpadButton_A) {
112121
tsl::setNextOverlay(entry.path());
113122

@@ -119,12 +128,11 @@ static void rebuildUI() {
119128
});
120129

121130
overlayList->addItem(listEntry);
122-
entries++;
123131
}
124132

125133
rootFrame->setHeader(header);
126134

127-
if (entries == 0) {
135+
if (overlayFiles.empty()) {
128136
rootFrame->setContent(noOverlaysError);
129137
delete overlayList;
130138
} else {

0 commit comments

Comments
 (0)