diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h index 827b03d46a9..2a9ea2127ed 100644 --- a/source/blender/blenkernel/BKE_blendfile.h +++ b/source/blender/blenkernel/BKE_blendfile.h @@ -48,6 +48,13 @@ bool BKE_blendfile_library_path_explode(const char *path, char **r_group, char **r_name); +/** + * Check whether a given path is actually a Blender-readable, valid .blend file. + * + * \note Currently does attempt to open and read (part of) the given file. + */ +bool BKE_blendfile_is_readable(const char *path, struct ReportList *reports); + /** * Shared setup function that makes the data from `bfd` into the current blend file, * replacing the contents of #G.main. diff --git a/source/blender/blenkernel/intern/blendfile.cc b/source/blender/blenkernel/intern/blendfile.cc index 1eb3c5ff425..148cb3ae78a 100644 --- a/source/blender/blenkernel/intern/blendfile.cc +++ b/source/blender/blenkernel/intern/blendfile.cc @@ -142,6 +142,18 @@ bool BKE_blendfile_library_path_explode(const char *path, return true; } +bool BKE_blendfile_is_readable(const char *path, ReportList *reports) +{ + BlendFileReadReport readfile_reports; + readfile_reports.reports = reports; + BlendHandle *bh = BLO_blendhandle_from_file(path, &readfile_reports); + if (bh != nullptr) { + BLO_blendhandle_close(bh); + return true; + } + return false; +} + /** \} */ /* -------------------------------------------------------------------- */