Automatically create bookmarks folder for user (#3262)

* Automatically creates user bookmarks folder if it does not exist
This commit is contained in:
Andreas Engberg
2024-05-20 17:08:57 +02:00
committed by GitHub
parent 944e345d2e
commit 666135d56f
3 changed files with 23 additions and 1 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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<std::filesystem::path> walkCommon(const std::filesystem::path& path,
bool recursive, bool sorted,
std::function<bool(const std::filesystem::path&)> filter)