From ea070fc1c4ad34fbc97f1ba1b19cef819ca9026b Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 19 Sep 2021 20:46:53 -0600 Subject: [PATCH 1/2] Switched to asset gui using filesystemaccess constructor without path filtering --- .../ext/launcher/include/filesystemaccess.h | 17 ++++++++++++ .../ext/launcher/src/filesystemaccess.cpp | 27 +++++++++++++------ .../launcher/src/profile/assettreemodel.cpp | 3 --- ext/ghoul | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/filesystemaccess.h b/apps/OpenSpace/ext/launcher/include/filesystemaccess.h index 6acdbb1c87..a3b9571a8f 100644 --- a/apps/OpenSpace/ext/launcher/include/filesystemaccess.h +++ b/apps/OpenSpace/ext/launcher/include/filesystemaccess.h @@ -34,6 +34,22 @@ public: * * \param fileExtension string that defines the filter used to find files. Only * files with this extension will be recognized (e.g. '.xml') + * \param hideFileExtensions if true then file extensions will be removed from the + * listed files in the output + * \param useCheckboxes if true then the text output format will contain a '0' as + * the first character in the line (this first character is + * used to represent checked ('1'), uncheck ('0') or doesn't + * exist in filesystem ('x') states. + */ + FileSystemAccess(std::string fileExtension, bool hideFileExtensions, + bool useCheckboxes); + + /** + * Constructor for filesystemAccess class which will find files that are only in the + * provided approved paths + * + * \param fileExtension string that defines the filter used to find files. Only + * files with this extension will be recognized (e.g. '.xml') * \param approvedPaths vector or strings containing directory names to be included * in the search. These are directories at the base level of * the starting point of the search. Any sub-directories within @@ -67,6 +83,7 @@ private: QFileSystemModel _filesystemModel; QDir::Filters _fileFilterOptions = QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot; std::string _fileExtension; + bool _useOnlyApprovedPaths = false; std::vector _approvedPaths; bool _hideFileExtensions = true; bool _useCheckboxes = false; diff --git a/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp b/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp index 9912c3bead..4e5b0b1cfd 100644 --- a/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp +++ b/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp @@ -25,10 +25,18 @@ #include "filesystemaccess.h" FileSystemAccess::FileSystemAccess(std::string fileExtension, - std::vector approvedPaths, bool hideFileExtensions, bool useCheckboxes) : _fileExtension(std::move(fileExtension)) + , _hideFileExtensions(hideFileExtensions) + , _useCheckboxes(useCheckboxes) +{} + +FileSystemAccess::FileSystemAccess(std::string fileExtension, + std::vector approvedPaths, + bool hideFileExtensions, bool useCheckboxes) + : _fileExtension(std::move(fileExtension)) , _approvedPaths(std::move(approvedPaths)) + , _useOnlyApprovedPaths(true) , _hideFileExtensions(hideFileExtensions) , _useCheckboxes(useCheckboxes) {} @@ -78,16 +86,19 @@ void FileSystemAccess::parseChildDirElements(QFileInfo fileInfo, std::string spa } bool FileSystemAccess::isApprovedPath(std::string path) { - bool approvedMatch = false; path.erase(0, path.find_first_not_of(" ")); - for (const std::string& p : _approvedPaths) { - if (path.substr(0, p.length()).compare(p) == 0) { - approvedMatch = true; - break; - } + if (!_useOnlyApprovedPaths) { + return true; + } + else { + for (const std::string& p : _approvedPaths) { + if (path.substr(0, p.length()).compare(p) == 0) { + return true; + } + } + return false; } - return approvedMatch; } void FileSystemAccess::parseChildFile(std::string filename, bool& hasDirHeaderBeenAdded, diff --git a/apps/OpenSpace/ext/launcher/src/profile/assettreemodel.cpp b/apps/OpenSpace/ext/launcher/src/profile/assettreemodel.cpp index 53521995f6..e588b103bd 100644 --- a/apps/OpenSpace/ext/launcher/src/profile/assettreemodel.cpp +++ b/apps/OpenSpace/ext/launcher/src/profile/assettreemodel.cpp @@ -149,9 +149,6 @@ void AssetTreeModel::importModelData(const std::string& assetBasePath, const std::string& userAssetBasePath) { FileSystemAccess assets( ".asset", - // @TODO (abock, 2021-03-24) We need some better solution for this; what is the - // problem of just including all subfolders instead? - { "scene", "global", "customization", "dashboard", "examples", "util" }, true, true ); diff --git a/ext/ghoul b/ext/ghoul index c7f7c61026..4b64684acd 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c7f7c6102609eadb8f8d4c45ab6dc8193740f809 +Subproject commit 4b64684acd728069e80948f9a4767b30baf268a3 From 3572de551b96c3750c60f623ab48c63466c09964 Mon Sep 17 00:00:00 2001 From: GPayne Date: Mon, 20 Sep 2021 15:38:21 -0600 Subject: [PATCH 2/2] Removed all filtering of approved paths in asset selection GUI --- .../ext/launcher/include/filesystemaccess.h | 26 +----------- .../ext/launcher/src/filesystemaccess.cpp | 41 ++++--------------- 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/filesystemaccess.h b/apps/OpenSpace/ext/launcher/include/filesystemaccess.h index a3b9571a8f..945fcb113d 100644 --- a/apps/OpenSpace/ext/launcher/include/filesystemaccess.h +++ b/apps/OpenSpace/ext/launcher/include/filesystemaccess.h @@ -44,33 +44,13 @@ public: FileSystemAccess(std::string fileExtension, bool hideFileExtensions, bool useCheckboxes); - /** - * Constructor for filesystemAccess class which will find files that are only in the - * provided approved paths - * - * \param fileExtension string that defines the filter used to find files. Only - * files with this extension will be recognized (e.g. '.xml') - * \param approvedPaths vector or strings containing directory names to be included - * in the search. These are directories at the base level of - * the starting point of the search. Any sub-directories within - * these directories will be included. - * \param hideFileExtensions if true then file extensions will be removed from the - * listed files in the output - * \param useCheckboxes if true then the text output format will contain a '0' as - * the first character in the line (this first character is - * used to represent checked ('1'), uncheck ('0') or doesn't - * exist in filesystem ('x') states. - */ - FileSystemAccess(std::string fileExtension, - std::vector approvedPaths, bool hideFileExtensions, - bool useCheckboxes); - /** * Function that uses the #QtFileSystemModel class to search the given directory * * \param dir The directory from which to start the search from */ - std::string useQtFileSystemModelToTraverseDir(std::string dir, bool usersAssets = false); + std::string useQtFileSystemModelToTraverseDir(std::string dir, + bool usersAssets = false); private: void parseChildDirElements(QFileInfo item, std::string space, int level, @@ -78,12 +58,10 @@ private: bool userAssets); void parseChildFile(std::string res, bool& hasDirHeaderBeenAdded, std::vector& dirNames, std::vector& output); - bool isApprovedPath(std::string path); QFileSystemModel _filesystemModel; QDir::Filters _fileFilterOptions = QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot; std::string _fileExtension; - bool _useOnlyApprovedPaths = false; std::vector _approvedPaths; bool _hideFileExtensions = true; bool _useCheckboxes = false; diff --git a/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp b/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp index 4e5b0b1cfd..f58665913d 100644 --- a/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp +++ b/apps/OpenSpace/ext/launcher/src/filesystemaccess.cpp @@ -31,17 +31,8 @@ FileSystemAccess::FileSystemAccess(std::string fileExtension, , _useCheckboxes(useCheckboxes) {} -FileSystemAccess::FileSystemAccess(std::string fileExtension, - std::vector approvedPaths, - bool hideFileExtensions, bool useCheckboxes) - : _fileExtension(std::move(fileExtension)) - , _approvedPaths(std::move(approvedPaths)) - , _useOnlyApprovedPaths(true) - , _hideFileExtensions(hideFileExtensions) - , _useCheckboxes(useCheckboxes) -{} - -std::string FileSystemAccess::useQtFileSystemModelToTraverseDir(std::string dir, bool userAssets) { +std::string FileSystemAccess::useQtFileSystemModelToTraverseDir(std::string dir, + bool userAssets) { _filesystemModel.setRootPath(QString::fromStdString(dir)); QModelIndex index = _filesystemModel.index(_filesystemModel.rootPath()); QFileInfo fileInfo = _filesystemModel.fileInfo(index); @@ -56,8 +47,10 @@ std::string FileSystemAccess::useQtFileSystemModelToTraverseDir(std::string dir, } void FileSystemAccess::parseChildDirElements(QFileInfo fileInfo, std::string space, - int level, std::vector& dirNames, - std::vector& output, bool userAssets) + int level, + std::vector& dirNames, + std::vector& output, + bool userAssets) { QDir dir(fileInfo.filePath()); bool hasDirHeaderBeenAdded = false; @@ -70,10 +63,8 @@ void FileSystemAccess::parseChildDirElements(QFileInfo fileInfo, std::string spa res = "${USER_ASSETS}/" + res; } if (fi.isDir()) { - if (level != 0 || (level == 0 && (isApprovedPath(res) || userAssets))) { - dirNames.push_back(res); - parseChildDirElements(fi, (space + " "), level + 1, dirNames, output, userAssets); - } + dirNames.push_back(res); + parseChildDirElements(fi, (space + " "), level + 1, dirNames, output, userAssets); } else { parseChildFile(res, hasDirHeaderBeenAdded, dirNames, output); @@ -85,22 +76,6 @@ void FileSystemAccess::parseChildDirElements(QFileInfo fileInfo, std::string spa } } -bool FileSystemAccess::isApprovedPath(std::string path) { - path.erase(0, path.find_first_not_of(" ")); - - if (!_useOnlyApprovedPaths) { - return true; - } - else { - for (const std::string& p : _approvedPaths) { - if (path.substr(0, p.length()).compare(p) == 0) { - return true; - } - } - return false; - } -} - void FileSystemAccess::parseChildFile(std::string filename, bool& hasDirHeaderBeenAdded, std::vector& dirNames, std::vector& output)