BKE_file: Add util to check if a given blend file is readable.
`BKE_blendfile_is_readable` attempts to open the given file path, and return `true` on success, `false` on failure. Part of #109151 (PR !110109).
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user