Extract PPBR package path validation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_panel_brush.h"
|
||||
#include "assets/brush_package.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "legacy_brush_ui_services.h"
|
||||
#include "asset.h"
|
||||
@@ -679,26 +680,27 @@ void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
|
||||
|
||||
bool NodePanelBrushPreset::export_ppbr(const std::string& path_in, const PPBRInfo& info_data)
|
||||
{
|
||||
std::string path = path_in;
|
||||
if (path_in.find(".ppbr") == std::string::npos)
|
||||
path += ".ppbr";
|
||||
const auto export_paths = pp::assets::plan_ppbr_export_paths(
|
||||
path_in,
|
||||
info_data.dest_path,
|
||||
info_data.export_data,
|
||||
#if __OSX__
|
||||
pp::assets::PpbrDataDirectoryPolicy::override_directory
|
||||
#else
|
||||
pp::assets::PpbrDataDirectoryPolicy::next_to_package
|
||||
#endif
|
||||
);
|
||||
if (!export_paths) {
|
||||
LOG("export_ppbr invalid path: %s", export_paths.status().message);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& path = export_paths.value().package_path;
|
||||
LOG("export ppbr to: %s", path.c_str());
|
||||
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)?$)");
|
||||
std::smatch m;
|
||||
if (!std::regex_search(path, m, r))
|
||||
return false;
|
||||
auto base = m[1].str();
|
||||
auto name = m[2].str();
|
||||
auto ext = m[3].str();
|
||||
const auto& out_path = export_paths.value().data_directory;
|
||||
|
||||
#if __OSX__
|
||||
std::string out_path = info_data.dest_path + "/" + name + "_data";
|
||||
#else
|
||||
std::string out_path = base + "/" + name + "_data";
|
||||
#endif
|
||||
|
||||
bool path_created = info_data.export_data && !out_path.empty() ? Asset::create_dir(out_path) : false;
|
||||
bool path_created = export_paths.value().data_directory_enabled ? Asset::create_dir(out_path) : false;
|
||||
|
||||
std::ofstream f(path, std::ios::binary);
|
||||
if (f.good())
|
||||
@@ -826,16 +828,12 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
||||
|
||||
// sanity checks
|
||||
auto magic = sr.rstring(4);
|
||||
if (magic != "PPBR")
|
||||
{
|
||||
LOG("PPBR tag not found")
|
||||
return false;
|
||||
}
|
||||
auto vmaj = sr.ru16();
|
||||
auto vmin = sr.ru16();
|
||||
if (vmaj != 0 && vmin != 1)
|
||||
const auto header_status = pp::assets::validate_ppbr_header(magic, vmaj, vmin);
|
||||
if (!header_status.ok())
|
||||
{
|
||||
LOG("unrecognised version %d.%d", vmaj, vmin);
|
||||
LOG("PPBR header rejected: %s (%d.%d)", header_status.message, vmaj, vmin);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user