Skip to content

Commit

Permalink
create untitled project when it doesnt exist...
Browse files Browse the repository at this point in the history
and is being loaded either as the entry in .current or because user
chose to create a new project
  • Loading branch information
maks committed Feb 14, 2025
1 parent f969f45 commit 0ab23ba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
15 changes: 13 additions & 2 deletions sources/Adapters/picoTracker/gui/SerialDebugUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions sources/Adapters/picoTracker/gui/SerialDebugUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions sources/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion sources/System/FileSystem/PicoFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex> lock(mutex);
return sd.rmdir(path);
auto delDir = sd.open(path, O_READ);
return delDir.rmdir();
}

bool PicoFileSystem::exists(const char *path) {
Expand Down

0 comments on commit 0ab23ba

Please sign in to comment.