diff --git a/data/assets/global/localbookmarks.asset b/data/assets/global/localbookmarks.asset index 2aa5833768..f616ff2d76 100644 --- a/data/assets/global/localbookmarks.asset +++ b/data/assets/global/localbookmarks.asset @@ -5,6 +5,11 @@ local bookmarkHelper = asset.require("util/generate_bookmarks") asset.require("scene/solarsystem/planets/earth/earth") local localBookmarks = openspace.absPath("${USER}/bookmarks/localbookmarks.csv") +local bookmarksDirectory = openspace.absPath("${USER}/bookmarks") + +if not openspace.directoryExists(bookmarksDirectory) then + openspace.createDirectory(bookmarksDirectory) +end -- Create bookmarks file if it does not exist if not openspace.fileExists(localBookmarks) then diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 773a4ec609..a7e2e84306 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -646,6 +646,7 @@ void ScriptEngine::addBaseLibrary() { codegen::lua::FileExists, codegen::lua::ReadFile, codegen::lua::DirectoryExists, + codegen::lua::CreateDirectory, codegen::lua::WalkDirectory, codegen::lua::WalkDirectoryFiles, codegen::lua::WalkDirectoryFolders, diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index 135a11ecb5..1d9ca9c630 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -103,12 +103,28 @@ namespace { return contents; } -// Checks whether the provided file exists. +// Checks whether the provided directory exists. [[codegen::luawrap]] bool directoryExists(std::filesystem::path file) { const bool e = std::filesystem::is_directory(absPath(std::move(file))); return e; } +/** + * Creates a directory at the provided path, returns true if directory was newly created + * and false otherwise. If `recursive` flag is set to true, it will automatically create + * any missing parent folder as well + */ +[[codegen::luawrap]] bool createDirectory(std::filesystem::path path, + bool recursive = false) +{ + if (recursive) { + return std::filesystem::create_directories(std::move(path)); + } + else { + return std::filesystem::create_directory(std::move(path)); + } +} + std::vector walkCommon(const std::filesystem::path& path, bool recursive, bool sorted, std::function filter)