Support loading backgrounds from the sd

This commit is contained in:
Edoardo Lolletti 2024-07-28 12:01:02 +02:00
parent 001442fd8a
commit 8c77633767

View File

@ -2,6 +2,7 @@
#include "main.h" #include "main.h"
#include "menu.h" #include "menu.h"
#include <algorithm>
#include <nds.h> #include <nds.h>
#include <dirent.h> #include <dirent.h>
#include <string> #include <string>
@ -11,9 +12,10 @@ static const auto& getBackgroundList()
{ {
static auto bgs = []{ static auto bgs = []{
std::vector<std::pair<std::string,std::string>> bgs; std::vector<std::pair<std::string,std::string>> bgs;
static const std::string bgstr{"nitro:/backgrounds/"};
auto* pdir = opendir("nitro:/backgrounds"); for(const auto* bgstr : {"nitro:/backgrounds/", "sd:/backgrounds/"}) {
if(!pdir) return bgs; auto* pdir = opendir(bgstr);
if(!pdir) continue;
dirent* pent; dirent* pent;
while((pent = readdir(pdir))) { while((pent = readdir(pdir))) {
if(pent->d_type == DT_DIR) if(pent->d_type == DT_DIR)
@ -24,6 +26,14 @@ static const auto& getBackgroundList()
bgs.emplace_back(name.substr(0, name.size() - 4), bgstr + name); bgs.emplace_back(name.substr(0, name.size() - 4), bgstr + name);
} }
closedir(pdir); closedir(pdir);
}
std::sort(bgs.begin(), bgs.end(), [](const auto& lhs, const auto& rhs){
const auto& [lhs_name, lhs_fullpath] = lhs;
const auto& [rhs_name, rhs_fullpath] = rhs;
if(lhs_fullpath[0] != rhs_fullpath[0])
return lhs_fullpath[0] < rhs_fullpath[0];
return lhs_name < rhs_name;
});
return bgs; return bgs;
}(); }();
return bgs; return bgs;