mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 10:40:09 -06:00
Automatically create bookmarks folder for user (#3262)
* Automatically creates user bookmarks folder if it does not exist
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user