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:
Bastien Montagne
2023-07-24 14:48:27 +02:00
parent a1d7ec7139
commit 05243a4206
2 changed files with 19 additions and 0 deletions

View File

@@ -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.

View File

@@ -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;
}
/** \} */
/* -------------------------------------------------------------------- */