From 0669bbbe55ed20f171f285224a434fe5b2e5089e Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 4 Feb 2022 23:25:09 +0100 Subject: [PATCH] Added a new open method to the directory class, and changed current_is_directory to current_is_dir. --- core/os/directory.cpp | 18 +++++++++++++++++- core/os/directory.h | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/os/directory.cpp b/core/os/directory.cpp index 82ac4c7..347e5ae 100644 --- a/core/os/directory.cpp +++ b/core/os/directory.cpp @@ -16,6 +16,22 @@ Error Directory::open(const String &path, bool skip_specials) { return OK; } +Error Directory::open(const char *path, bool skip_specials) { + if (_open) { + return ERR_CANT_ACQUIRE_RESOURCE; + } + + _skip_specials = skip_specials; + + if (tinydir_open(&_dir, path) == -1) { + return FAILED; + } + + _open = true; + + return OK; +} + void Directory::close() { if (!_open) { return; @@ -65,7 +81,7 @@ char *Directory::current_get_extension_cstr() { bool Directory::current_is_file() { return !_file.is_dir; } -bool Directory::current_is_directory() { +bool Directory::current_is_dir() { return _file.is_dir; } diff --git a/core/os/directory.h b/core/os/directory.h index ec63776..61fdff4 100644 --- a/core/os/directory.h +++ b/core/os/directory.h @@ -11,6 +11,7 @@ class Directory : public Reference { RCPP_OBJECT(Directory, Reference); public: Error open(const String &path, bool skip_specials = false); + Error open(const char *path, bool skip_specials = false); void close(); bool has_next(); @@ -24,7 +25,7 @@ public: char *current_get_path_cstr(); char *current_get_extension_cstr(); bool current_is_file(); - bool current_is_directory(); + bool current_is_dir(); String read_file(const String &path); void read_file_into(const String &path, String *str);