Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bdring committed Feb 23, 2024
1 parent 82116d8 commit dcde3bb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
5 changes: 5 additions & 0 deletions FluidNC/src/FluidPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "FluidPath.h"
#include "Driver/sdspi.h"
#include "Machine/MachineConfig.h"
#include "Config.h"
#include "Error.h"
#include "HashFS.h"
Expand All @@ -13,6 +14,10 @@ FluidPath::FluidPath(const char* name, const char* fs, std::error_code* ecptr) :
auto mount = *(++begin()); // Use the path iterator to get the first component
_isSD = mount == "sd";

if (_isSD && !config->_sdCard->config_ok) {
throw stdfs::filesystem_error { "SD card is not configured", std::error_code() };
}

if (_isSD) {
if (_refcnt == 0) {
std::error_code ec = sd_mount();
Expand Down
71 changes: 38 additions & 33 deletions FluidNC/src/WebUI/WebSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,43 +492,48 @@ namespace WebUI {
static Error listFilesystem(const char* fs, const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
std::error_code ec;

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}
// if (fs == sdName && !config->_sdCard->is_configured(out)) {
//
// }

FluidPath fpath { value, fs, ec };
if (ec) {
log_string(out, "No SD card");
return Error::FsFailedMount;
}
try {
//try {
FluidPath fpath { value, fs, ec };

auto iter = stdfs::recursive_directory_iterator { fpath, ec };
if (ec) {
log_stream(out, "Error: " << ec.message());
return Error::FsFailedMount;
}
for (auto const& dir_entry : iter) {
if (dir_entry.is_directory()) {
log_stream(out, "[DIR:" << std::string(iter.depth(), ' ').c_str() << dir_entry.path().filename());
} else {
log_stream(out,
"[FILE: " << std::string(iter.depth(), ' ').c_str() << dir_entry.path().filename()
<< "|SIZE:" << dir_entry.file_size());
if (ec) {
log_string(out, "No SD card");
return Error::FsFailedMount;
}
}
auto space = stdfs::space(fpath, ec);
if (ec) {
log_stream(out, "Error " << ec.value() << " " << ec.message());
return Error::FsFailedMount;
}

auto totalBytes = space.capacity;
auto freeBytes = space.available;
auto usedBytes = totalBytes - freeBytes;
log_stream(out,
"[" << fpath.c_str() << " Free:" << formatBytes(freeBytes) << " Used:" << formatBytes(usedBytes)
<< " Total:" << formatBytes(totalBytes));
return Error::Ok;
auto iter = stdfs::recursive_directory_iterator { fpath, ec };
if (ec) {
log_stream(out, "Error: " << ec.message());
return Error::FsFailedMount;
}
for (auto const& dir_entry : iter) {
if (dir_entry.is_directory()) {
log_stream(out, "[DIR:" << std::string(iter.depth(), ' ').c_str() << dir_entry.path().filename());
} else {
log_stream(out,
"[FILE: " << std::string(iter.depth(), ' ').c_str() << dir_entry.path().filename()
<< "|SIZE:" << dir_entry.file_size());
}
}
auto space = stdfs::space(fpath, ec);
if (ec) {
log_stream(out, "Error " << ec.value() << " " << ec.message());
return Error::FsFailedMount;
}

auto totalBytes = space.capacity;
auto freeBytes = space.available;
auto usedBytes = totalBytes - freeBytes;
log_stream(out,
"[" << fpath.c_str() << " Free:" << formatBytes(freeBytes) << " Used:" << formatBytes(usedBytes)
<< " Total:" << formatBytes(totalBytes));
return Error::Ok;

} catch (...) { return Error::InvalidStatement; }
}

static Error listSDFiles(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP210
Expand Down

0 comments on commit dcde3bb

Please sign in to comment.