[Bf-blender-cvs] [d6e9b0ce5d6] asset-system-filelist: Mostly finish regular file reading & general improvements

Julian Eisel noreply at git.blender.org
Thu May 27 00:22:15 CEST 2021


Commit: d6e9b0ce5d61f64a3879459c9d39a151aabdea81
Author: Julian Eisel
Date:   Thu May 27 00:20:02 2021 +0200
Branches: asset-system-filelist
https://developer.blender.org/rBd6e9b0ce5d61f64a3879459c9d39a151aabdea81

Mostly finish regular file reading & general improvements

Main thing that's missing for regular file reading is supporting symbolic
links. Most work for them is already done though.

===================================================================

M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/filelist/CMakeLists.txt
M	source/blender/editors/filelist/file_list.cc
M	source/blender/editors/filelist/file_list.hh
M	source/blender/editors/filelist/file_list_entry.cc
M	source/blender/editors/filelist/file_list_entry.hh
M	source/blender/editors/filelist/file_list_reader.cc
M	source/blender/editors/filelist/file_list_reader.hh

===================================================================

diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index 4b6583ae323..d04d396c579 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -240,7 +240,7 @@ void AssetList::setup(const AssetFilterSettings *filter_settings)
   /* -------------------------------------------------------------------- */
 
   ed::filelist::FileListReadParams read_params(path);
-  cpp_filelist_ = std::make_unique<ed::filelist::FileList>(read_params);
+  cpp_filelist_ = std::make_unique<ed::filelist::FileList>(std::move(read_params));
 }
 
 void AssetList::fetch(const bContext &C)
diff --git a/source/blender/editors/filelist/CMakeLists.txt b/source/blender/editors/filelist/CMakeLists.txt
index 51976e06840..1fadf550e81 100644
--- a/source/blender/editors/filelist/CMakeLists.txt
+++ b/source/blender/editors/filelist/CMakeLists.txt
@@ -19,6 +19,8 @@
 set(INC
     ../include
     ../../blenlib
+    ../../blenkernel
+    ../../blenloader
     ../../makesdna
     ../../../../intern/guardedalloc
 )
diff --git a/source/blender/editors/filelist/file_list.cc b/source/blender/editors/filelist/file_list.cc
index ffc5d4483ae..e35ebcce584 100644
--- a/source/blender/editors/filelist/file_list.cc
+++ b/source/blender/editors/filelist/file_list.cc
@@ -29,12 +29,24 @@
 
 namespace blender::ed::filelist {
 
+/**
+ * \param max_recursion_level: If not set, recursion is unlimited.
+ */
+FileListReadParams::FileListReadParams(std::string path,
+                                       std::optional<RecursionSettings> recursion_settings)
+    : path_(path), recursion_settings_(recursion_settings)
+{
+}
+
 FileList::FileList(const FileListReadParams &read_params) : read_params_(read_params)
 {
 }
 
-void print_dir(FileTree &file_list)
+void print_dir(FileEntires &file_list)
 {
+  if (file_list.is_empty()) {
+    return;
+  }
   for (const auto &file : file_list) {
     std::cout << file->relative_file_path() << std::endl;
     if (DirectoryEntry *dir = dynamic_cast<DirectoryEntry *>(file.get())) {
@@ -53,9 +65,42 @@ void FileList::fetch()
   int64_t tot_files = reader.peekAndCountFiles();
   std::cout << tot_files << std::endl;
 
-  reader.read(file_tree_);
+  reader.read(file_entries_);
+
+  print_dir(file_entries_);
+}
+
+StringRef FileList::rootPath() const
+{
+  return read_params_.path_;
+}
+
+/**
+ * The full file-path to \a file, excluding the file name.
+ */
+std::string FileList::fullPathToFile(const AbstractFileEntry &file) const
+{
+  StringRef root = rootPath();
+  std::string rel_file_path = file.relative_path();
+
+  char path[PATH_MAX];
+  BLI_path_join(path, sizeof(path), root.data(), rel_file_path.data(), NULL);
+
+  return path;
+}
+
+/**
+ * The full file-path to \a file, including the file name.
+ */
+std::string FileList::fullFilePathToFile(const AbstractFileEntry &file) const
+{
+  StringRef root = rootPath();
+  std::string rel_file_path = file.relative_file_path();
+
+  char path[PATH_MAX];
+  BLI_path_join(path, sizeof(path), root.data(), rel_file_path.data(), NULL);
 
-  print_dir(file_tree_);
+  return path;
 }
 
 }  // namespace blender::ed::filelist
diff --git a/source/blender/editors/filelist/file_list.hh b/source/blender/editors/filelist/file_list.hh
index 68d6e274444..2ce95128183 100644
--- a/source/blender/editors/filelist/file_list.hh
+++ b/source/blender/editors/filelist/file_list.hh
@@ -30,19 +30,19 @@
 
 namespace blender::ed::filelist {
 
-class AbstractFileListEntry;
+class AbstractFileEntry;
 
 struct FileListReadParams {
-  /**
-   * \param max_recursion_level: If not set, recursion is unlimited.
-   */
-  FileListReadParams(std::string path, std::optional<int> max_recursion_level = std::nullopt)
-      : path_(path), max_recursion_level_(max_recursion_level)
-  {
-  }
+  struct RecursionSettings {
+    int max_recursion_level_ = 0;
+    bool recurse_into_blends_ = false;
+  };
+
+  FileListReadParams(std::string path,
+                     std::optional<RecursionSettings> recursion_settings = std::nullopt);
 
   std::string path_;
-  std::optional<int> max_recursion_level_;
+  std::optional<RecursionSettings> recursion_settings_;
   /* Hidden files? */
   bool skip_current_and_parent_ = true;
 };
@@ -55,16 +55,22 @@ class AbstractFileList {
   virtual void fetch() = 0;
 };
 
-using FileTree = blender::Vector<std::unique_ptr<AbstractFileListEntry>>;
+/* Note that each entry may have child entries. */
+using FileEntires = blender::Vector<std::unique_ptr<AbstractFileEntry>>;
 
 class FileList final : public AbstractFileList {
   FileListReadParams read_params_;
 
-  FileTree file_tree_;
+  FileEntires file_entries_;
 
  public:
   FileList(const FileListReadParams &read_params);
+
   void fetch() override;
+
+  StringRef rootPath() const;
+  std::string fullPathToFile(const AbstractFileEntry &file) const;
+  std::string fullFilePathToFile(const AbstractFileEntry &file) const;
 };
 
 }  // namespace blender::ed::filelist
diff --git a/source/blender/editors/filelist/file_list_entry.cc b/source/blender/editors/filelist/file_list_entry.cc
index 8cf6fe0b614..8f5f918e82f 100644
--- a/source/blender/editors/filelist/file_list_entry.cc
+++ b/source/blender/editors/filelist/file_list_entry.cc
@@ -14,16 +14,22 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "BKE_main.h"
+
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
 
+#include "DNA_space_types.h"
+
+#include "ED_fileselect.h"
+
 #include "file_list_entry.hh"
 
 namespace blender::ed::filelist {
 
-AbstractFileListEntry::AbstractFileListEntry(const bli_direntry &direntry,
-                                             const eFileAttributes attributes,
-                                             const AbstractFileListEntry *parent)
+AbstractFileEntry::AbstractFileEntry(const bli_direntry &direntry,
+                                     const eFileAttributes attributes,
+                                     const AbstractFileEntry *parent)
     : name_(direntry.relname),
       /* Could get the attributes via `BLI_file_attributes(direntry.path)` here, but it's needed
          earlier already and it's not too cheap (bunch of file system queries). */
@@ -31,40 +37,49 @@ AbstractFileListEntry::AbstractFileListEntry(const bli_direntry &direntry,
       stat_(direntry.s),
       parent_(parent)
 {
+  BLI_assert(name_.back() != SEP);
 }
 
-void AbstractFileListEntry::hide()
+void AbstractFileEntry::setAlias(const FileAliasInfo &)
+{
+}
+
+void AbstractFileEntry::hide()
 {
   attributes_ |= FILE_ATTR_HIDDEN;
 }
-bool AbstractFileListEntry::isHidden() const
+bool AbstractFileEntry::isHidden() const
 {
   return attributes_ & FILE_ATTR_HIDDEN;
 }
 
-StringRef AbstractFileListEntry::name() const
+const AbstractFileEntry *AbstractFileEntry::parent() const
+{
+  return parent_;
+}
+
+StringRef AbstractFileEntry::name() const
 {
   return name_;
 }
 
-eFileAttributes AbstractFileListEntry::attributes() const
+eFileAttributes AbstractFileEntry::attributes() const
 {
   return attributes_;
 }
 
-const BLI_stat_t &AbstractFileListEntry::stat() const
+const BLI_stat_t &AbstractFileEntry::stat() const
 {
   return stat_;
 }
 
-void AbstractFileListEntry::relative_path(char *path, size_t maxsize) const
+void AbstractFileEntry::relative_path(char *path, size_t maxsize) const
 {
   BLI_assert(maxsize > 0);
   path[0] = 0;
 
   Vector<const char *, 10> path_vec;
-  for (const AbstractFileListEntry *parent = parent_; parent != nullptr;
-       parent = parent->parent_) {
+  for (const AbstractFileEntry *parent = parent_; parent != nullptr; parent = parent->parent_) {
     path_vec.append(parent->name_.data());
   }
 
@@ -73,14 +88,14 @@ void AbstractFileListEntry::relative_path(char *path, size_t maxsize) const
   }
 }
 
-std::string AbstractFileListEntry::relative_path() const
+std::string AbstractFileEntry::relative_path() const
 {
   char path[PATH_MAX];
   relative_path(path, sizeof(path));
   return path;
 }
 
-std::string AbstractFileListEntry::relative_file_path() const
+std::string AbstractFileEntry::relative_file_path() const
 {
   char path[PATH_MAX];
   relative_path(path, sizeof(path));
@@ -90,25 +105,83 @@ std::string AbstractFileListEntry::relative_file_path() const
 
 FileEntry::FileEntry(const bli_direntry &direntry,
                      const eFileAttributes attributes,
-                     const AbstractFileListEntry *parent)
-    : AbstractFileListEntry(direntry, attributes, parent)
-{
+                     const AbstractFileEntry *parent)
+    : AbstractFileEntry(direntry, attributes, parent)
+{
+  eFileSel_File_Types filesel_type = static_cast<eFileSel_File_Types>(
+      ED_path_extension_type(isAlias() ? redirect_path_->data() : name_.data()));
+  type_ = filesel_type_to_file_entry_type(filesel_type);
+}
+
+FileEntry::Type FileEntry::filesel_type_to_file_entry_type(eFileSel_File_Types type)
+{
+  switch (type) {
+    case FILE_TYPE_BLENDER:
+      return Type::Blend;
+    case FILE_TYPE_BLENDER_BACKUP:
+      return Type::BlendBackup;
+    case FILE_TYPE_IMAGE:
+      return Type::Image;
+    case FILE_TYPE_MOVIE:
+      return Type::Movie;
+    case FILE_TYPE_PYSCRIPT:
+      return Type::PyScript;
+    case FILE_TYPE_FTFONT:
+      return Type::FTFont;
+    case FILE_TYPE_SOUND:
+      return Type::Sound;
+    case FILE_TYPE_TEXT:
+      return Type::Text;
+    case FILE_TYPE_ARCHIVE:
+      return Type::Archive;
+    case FILE_TYPE_BTX:
+      return Type::BTX;
+    case FILE_TYPE_COLLADA:
+      return Type::Collada;
+    case FILE_TYPE_OPERATOR:
+      /* TODO */
+      throw std::exception();
+    case FILE_TYPE_APPLICATIONBUNDLE:
+      return Type::ApplicationBundle;
+    case FILE_TYPE_ALEMBIC:
+      return Type::Alembic;
+    case FILE_TYPE_OBJECT_IO:
+      return Type::ObjectIO;
+    case FILE_TYPE_USD:
+      return Type::USD;
+    case FILE_TYPE_VOLUME:
+      return Type::Volume;
+      /* These types shouldn't use #FileEntry, they have dedicated classes. */
+    case FILE_TYPE_FOLDER:
+    case FILE_TYPE_ASSET:
+    case FILE_TYPE_DIR:
+    case FILE_TYPE_BLENDERLIB:
+      throw std::exception();
+  }
 }
 
 void FileEntry::setAlias(const FileAli

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list