Skip to content

Commit

Permalink
Sort overlay list according to their file name
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed May 11, 2022
1 parent df27b52 commit 9b45b9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/libtesla
Submodule libtesla updated 1 files
+60 −51 include/tesla.hpp
16 changes: 12 additions & 4 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ static void rebuildUI() {
renderer->drawString("Place your .ovl files in /switch/.overlays", false, 82, 410, 15, renderer->a(tsl::style::color::ColorDescription));
});

u16 entries = 0;
std::vector<std::filesystem::directory_entry> overlayFiles;

fsdevMountSdmc();
for (const auto &entry : std::filesystem::directory_iterator("sdmc:/switch/.overlays")) {
if (entry.path().filename() == "ovlmenu.ovl")
Expand All @@ -101,13 +102,21 @@ static void rebuildUI() {
if (entry.path().extension() != ".ovl")
continue;

overlayFiles.push_back(entry);
}

std::sort(overlayFiles.begin(), overlayFiles.end(), [](const auto &left, const auto &right) {
return left.path().filename() < right.path().filename();
});

for (const auto &entry : overlayFiles) {
auto [result, name, version] = getOverlayInfo(entry.path());
if (result != ResultSuccess)
continue;

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

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

overlayList->addItem(listEntry);
entries++;
}

rootFrame->setHeader(header);

if (entries == 0) {
if (overlayFiles.empty()) {
rootFrame->setContent(noOverlaysError);
delete overlayList;
} else {
Expand Down

0 comments on commit 9b45b9f

Please sign in to comment.