Support up to 500 character file names (#275)
## Summary - Support up to 500 character file names ## Additional Context - Fixes #265
This commit is contained in:
@@ -49,7 +49,7 @@ void SleepActivity::renderCustomSleepScreen() const {
|
||||
auto dir = SdMan.open("/sleep");
|
||||
if (dir && dir.isDirectory()) {
|
||||
std::vector<std::string> files;
|
||||
char name[128];
|
||||
char name[500];
|
||||
// collect all valid BMP files
|
||||
for (auto file = dir.openNextFile(); file; file = dir.openNextFile()) {
|
||||
if (file.isDirectory()) {
|
||||
|
||||
@@ -39,7 +39,7 @@ void FileSelectionActivity::loadFiles() {
|
||||
|
||||
root.rewindDirectory();
|
||||
|
||||
char name[128];
|
||||
char name[500];
|
||||
for (auto file = root.openNextFile(); file; file = root.openNextFile()) {
|
||||
file.getName(name, sizeof(name));
|
||||
if (name[0] == '.' || strcmp(name, "System Volume Information") == 0) {
|
||||
@@ -123,6 +123,7 @@ void FileSelectionActivity::loop() {
|
||||
if (files[selectorIndex].back() == '/') {
|
||||
basepath += files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
||||
loadFiles();
|
||||
selectorIndex = 0;
|
||||
updateRequired = true;
|
||||
} else {
|
||||
onSelect(basepath + files[selectorIndex]);
|
||||
@@ -137,8 +138,8 @@ void FileSelectionActivity::loop() {
|
||||
if (basepath.empty()) basepath = "/";
|
||||
loadFiles();
|
||||
|
||||
auto pos = oldPath.find_last_of('/');
|
||||
std::string dirName = oldPath.substr(pos + 1) + "/";
|
||||
const auto pos = oldPath.find_last_of('/');
|
||||
const std::string dirName = oldPath.substr(pos + 1) + "/";
|
||||
selectorIndex = findEntry(dirName);
|
||||
|
||||
updateRequired = true;
|
||||
@@ -193,7 +194,7 @@ void FileSelectionActivity::render() const {
|
||||
|
||||
const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS;
|
||||
renderer.fillRect(0, 60 + (selectorIndex % PAGE_ITEMS) * 30 - 2, pageWidth - 1, 30);
|
||||
for (int i = pageStartIndex; i < files.size() && i < pageStartIndex + PAGE_ITEMS; i++) {
|
||||
for (size_t i = pageStartIndex; i < files.size() && i < pageStartIndex + PAGE_ITEMS; i++) {
|
||||
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(), renderer.getScreenWidth() - 40);
|
||||
renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % PAGE_ITEMS) * 30, item.c_str(), i != selectorIndex);
|
||||
}
|
||||
@@ -201,7 +202,7 @@ void FileSelectionActivity::render() const {
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
|
||||
int FileSelectionActivity::findEntry(const std::string& name) const {
|
||||
size_t FileSelectionActivity::findEntry(const std::string& name) const {
|
||||
for (size_t i = 0; i < files.size(); i++)
|
||||
if (files[i] == name) return i;
|
||||
return 0;
|
||||
|
||||
@@ -14,7 +14,7 @@ class FileSelectionActivity final : public Activity {
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
std::string basepath = "/";
|
||||
std::vector<std::string> files;
|
||||
int selectorIndex = 0;
|
||||
size_t selectorIndex = 0;
|
||||
bool updateRequired = false;
|
||||
const std::function<void(const std::string&)> onSelect;
|
||||
const std::function<void()> onGoHome;
|
||||
@@ -23,7 +23,8 @@ class FileSelectionActivity final : public Activity {
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
void render() const;
|
||||
void loadFiles();
|
||||
int findEntry(const std::string& name) const;
|
||||
|
||||
size_t findEntry(const std::string& name) const;
|
||||
|
||||
public:
|
||||
explicit FileSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||
|
||||
@@ -194,7 +194,7 @@ void CrossPointWebServer::scanFiles(const char* path, const std::function<void(F
|
||||
Serial.printf("[%lu] [WEB] Scanning files in: %s\n", millis(), path);
|
||||
|
||||
FsFile file = root.openNextFile();
|
||||
char name[128];
|
||||
char name[500];
|
||||
while (file) {
|
||||
file.getName(name, sizeof(name));
|
||||
auto fileName = String(name);
|
||||
|
||||
Reference in New Issue
Block a user