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");
|
auto dir = SdMan.open("/sleep");
|
||||||
if (dir && dir.isDirectory()) {
|
if (dir && dir.isDirectory()) {
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
char name[128];
|
char name[500];
|
||||||
// collect all valid BMP files
|
// collect all valid BMP files
|
||||||
for (auto file = dir.openNextFile(); file; file = dir.openNextFile()) {
|
for (auto file = dir.openNextFile(); file; file = dir.openNextFile()) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void FileSelectionActivity::loadFiles() {
|
|||||||
|
|
||||||
root.rewindDirectory();
|
root.rewindDirectory();
|
||||||
|
|
||||||
char name[128];
|
char name[500];
|
||||||
for (auto file = root.openNextFile(); file; file = root.openNextFile()) {
|
for (auto file = root.openNextFile(); file; file = root.openNextFile()) {
|
||||||
file.getName(name, sizeof(name));
|
file.getName(name, sizeof(name));
|
||||||
if (name[0] == '.' || strcmp(name, "System Volume Information") == 0) {
|
if (name[0] == '.' || strcmp(name, "System Volume Information") == 0) {
|
||||||
@@ -123,6 +123,7 @@ void FileSelectionActivity::loop() {
|
|||||||
if (files[selectorIndex].back() == '/') {
|
if (files[selectorIndex].back() == '/') {
|
||||||
basepath += files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
basepath += files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
||||||
loadFiles();
|
loadFiles();
|
||||||
|
selectorIndex = 0;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else {
|
} else {
|
||||||
onSelect(basepath + files[selectorIndex]);
|
onSelect(basepath + files[selectorIndex]);
|
||||||
@@ -137,8 +138,8 @@ void FileSelectionActivity::loop() {
|
|||||||
if (basepath.empty()) basepath = "/";
|
if (basepath.empty()) basepath = "/";
|
||||||
loadFiles();
|
loadFiles();
|
||||||
|
|
||||||
auto pos = oldPath.find_last_of('/');
|
const auto pos = oldPath.find_last_of('/');
|
||||||
std::string dirName = oldPath.substr(pos + 1) + "/";
|
const std::string dirName = oldPath.substr(pos + 1) + "/";
|
||||||
selectorIndex = findEntry(dirName);
|
selectorIndex = findEntry(dirName);
|
||||||
|
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@@ -193,7 +194,7 @@ void FileSelectionActivity::render() const {
|
|||||||
|
|
||||||
const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS;
|
const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS;
|
||||||
renderer.fillRect(0, 60 + (selectorIndex % PAGE_ITEMS) * 30 - 2, pageWidth - 1, 30);
|
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);
|
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);
|
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();
|
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++)
|
for (size_t i = 0; i < files.size(); i++)
|
||||||
if (files[i] == name) return i;
|
if (files[i] == name) return i;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class FileSelectionActivity final : public Activity {
|
|||||||
SemaphoreHandle_t renderingMutex = nullptr;
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||||||
std::string basepath = "/";
|
std::string basepath = "/";
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
int selectorIndex = 0;
|
size_t selectorIndex = 0;
|
||||||
bool updateRequired = false;
|
bool updateRequired = false;
|
||||||
const std::function<void(const std::string&)> onSelect;
|
const std::function<void(const std::string&)> onSelect;
|
||||||
const std::function<void()> onGoHome;
|
const std::function<void()> onGoHome;
|
||||||
@@ -23,7 +23,8 @@ class FileSelectionActivity final : public Activity {
|
|||||||
[[noreturn]] void displayTaskLoop();
|
[[noreturn]] void displayTaskLoop();
|
||||||
void render() const;
|
void render() const;
|
||||||
void loadFiles();
|
void loadFiles();
|
||||||
int findEntry(const std::string& name) const;
|
|
||||||
|
size_t findEntry(const std::string& name) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
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);
|
Serial.printf("[%lu] [WEB] Scanning files in: %s\n", millis(), path);
|
||||||
|
|
||||||
FsFile file = root.openNextFile();
|
FsFile file = root.openNextFile();
|
||||||
char name[128];
|
char name[500];
|
||||||
while (file) {
|
while (file) {
|
||||||
file.getName(name, sizeof(name));
|
file.getName(name, sizeof(name));
|
||||||
auto fileName = String(name);
|
auto fileName = String(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user