diff --git a/sources/Adapters/picoTracker/gui/SerialDebugUI.cpp b/sources/Adapters/picoTracker/gui/SerialDebugUI.cpp index d8327a15..bc98af13 100644 --- a/sources/Adapters/picoTracker/gui/SerialDebugUI.cpp +++ b/sources/Adapters/picoTracker/gui/SerialDebugUI.cpp @@ -54,8 +54,10 @@ void SerialDebugUI::dispatchCmd(char *input) { saveConfig(); } else if (strcmp(cmd, "mkdir") == 0) { mkdir(arg); + } else if (strcmp(cmd, "rmdir") == 0) { + rmdir(arg); } else if (strcmp(cmd, "help") == 0) { - Trace::Log("SERIALDEBUG", "cat, ls, rm, mkdir, help"); + Trace::Log("SERIALDEBUG", "cat, ls, rm, mkdir, rmdir, save, help"); } else { Trace::Log("SERIALDEBUG", "unknown command"); } @@ -120,5 +122,14 @@ void SerialDebugUI::saveConfig() { void SerialDebugUI::mkdir(const char *path) { auto picoFS = PicoFileSystem::GetInstance(); - picoFS->makeDir(path, true); + if (!picoFS->makeDir(path, true)) { + Trace::Error("failed to create dir:%s", path); + } +} + +void SerialDebugUI::rmdir(const char *path) { + auto picoFS = PicoFileSystem::GetInstance(); + if (!picoFS->DeleteDir(path)) { + Trace::Error("failed to remove dir:%s", path); + } } \ No newline at end of file diff --git a/sources/Adapters/picoTracker/gui/SerialDebugUI.h b/sources/Adapters/picoTracker/gui/SerialDebugUI.h index 5639edab..4bf36e19 100644 --- a/sources/Adapters/picoTracker/gui/SerialDebugUI.h +++ b/sources/Adapters/picoTracker/gui/SerialDebugUI.h @@ -13,6 +13,7 @@ class SerialDebugUI { void rmFile(const char *path); void saveConfig(); void mkdir(const char *path); + void rmdir(const char *path); private: int lp_ = 0; diff --git a/sources/Application/Application.cpp b/sources/Application/Application.cpp index f885e34b..8f2388c0 100644 --- a/sources/Application/Application.cpp +++ b/sources/Application/Application.cpp @@ -60,6 +60,15 @@ bool Application::initProject(char *projectName) { if (PersistencyService::GetInstance()->Load(projectName) == PERSIST_LOAD_FAILED) { Trace::Error("failed to load CURRENT proj: %s\n", projectName); + if (strcmp(projectName, UNNAMED_PROJECT_NAME) == 0) { + // untitled project is missing so need to create a new one + if (PersistencyService::GetInstance()->CreateProject() != + PERSIST_SAVED) { + Trace::Log("APPLICATION", "FAILED to create new UNTITLED project !!"); + // TODO: show user some sort of error message and how to recover from + // this? + } + } } return false; } else { diff --git a/sources/System/FileSystem/PicoFileSystem.cpp b/sources/System/FileSystem/PicoFileSystem.cpp index f7ed73fa..1a62fe3b 100644 --- a/sources/System/FileSystem/PicoFileSystem.cpp +++ b/sources/System/FileSystem/PicoFileSystem.cpp @@ -194,9 +194,11 @@ bool PicoFileSystem::DeleteFile(const char *path) { return sd.remove(path); } +// directory has to be empty bool PicoFileSystem::DeleteDir(const char *path) { std::lock_guard lock(mutex); - return sd.rmdir(path); + auto delDir = sd.open(path, O_READ); + return delDir.rmdir(); } bool PicoFileSystem::exists(const char *path) {