Skip to content

Commit

Permalink
Include directories in gcode file list
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Jan 8, 2024
1 parent d01ac93 commit b5c77d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions FluidNC/src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void Channel::print_msg(MsgLevel level, const char* msg) {
}
}

bool Channel::is_visible(const std::string& stem, const std::string& extension) {
bool Channel::is_visible(const std::string& stem, const std::string& extension, bool isdir) {
if (stem.length() && stem[0] == '.') {
// Exclude hidden files and directories
return false;
Expand All @@ -265,10 +265,13 @@ bool Channel::is_visible(const std::string& stem, const std::string& extension)
// Exclude a common SD card metadata subdirectory
return false;
}
if (isdir) {
return true;
}
std::string_view extensions(_gcode_extensions);
int pos = 0;
while (extensions.length()) {
auto next_pos = extensions.find_first_of('|', pos);
auto next_pos = extensions.find_first_of(' ', pos);
std::string_view next_extension = extensions.substr(0, next_pos);
if (extension == next_extension) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Channel : public Stream {
std::map<int, bool*> _pin_values;

UTF8 _utf8;
std::string _gcode_extensions = ".g|.gc|.gco|.gcode|.nc|.ngc|.ncc|.txt|.cnc|.tap";
std::string _gcode_extensions = ".g .gc .gco .gcode .nc .ngc .ncc .txt .cnc .tap";

public:
Channel(const char* name, bool addCR = false) : _name(name), _linelen(0), _addCR(addCR) {}
Expand Down Expand Up @@ -125,7 +125,7 @@ class Channel : public Stream {

virtual void stopJob() {}

virtual bool is_visible(const std::string& stem, const std::string& extension);
virtual bool is_visible(const std::string& stem, const std::string& extension, bool isdir);

size_t timedReadBytes(uint8_t* buffer, size_t length, TickType_t timeout) { return timedReadBytes((char*)buffer, length, timeout); }

Expand Down
7 changes: 4 additions & 3 deletions FluidNC/src/WebUI/WebSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,12 @@ namespace WebUI {
error = "Bad path";
} else {
for (auto const& dir_entry : iter) {
auto fn = dir_entry.path().filename();
if (out.is_visible(fn.stem(), fn.extension())) {
auto fn = dir_entry.path().filename();
auto is_dir = dir_entry.is_directory();
if (out.is_visible(fn.stem(), fn.extension(), is_dir)) {
j.begin_object();
j.member("name", dir_entry.path().filename());
j.member("size", dir_entry.is_directory() ? -1 : dir_entry.file_size());
j.member("size", is_dir ? -1 : dir_entry.file_size());
j.end_object();
}
}
Expand Down

0 comments on commit b5c77d1

Please sign in to comment.