show cursor on picking and other modes than draw/erase, sanity check on presets file

This commit is contained in:
2019-03-08 12:47:06 +01:00
parent 440abb7049
commit bfe5c3541d
5 changed files with 52 additions and 9 deletions

View File

@@ -429,7 +429,17 @@ void NodePanelBrushPreset::init()
save();
};
restore();
if (Asset::exist(App::I.data_path + "/settings/presets.bin") && !restore())
{
auto mb = App::I.message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
mb->btn_ok->on_click = [mb](Node*) {
Asset::delete_file(App::I.data_path + "/settings/presets.bin");
mb->destroy();
};
mb->btn_cancel->on_click = [mb](Node*) {
mb->destroy();
};
}
}
kEventResult NodePanelBrushPreset::handle_event(Event* e)
@@ -476,12 +486,14 @@ bool NodePanelBrushPreset::save()
{
BinaryStreamWriter sw;
sw.init();
sw.wstring_raw("PPVR");
sw.wu16(0);
sw.wu16(1);
sw.wu32(m_container->m_children.size());
for (int ci = 0; ci < m_container->m_children.size(); ci++)
{
auto bpi = static_cast<NodeBrushPresetItem*>(m_container->get_child_at(ci));
auto& b = bpi->m_brush;
sw << *b;
}
fwrite(sw.m_data.data(), sw.m_data.size(), 1, fp);
@@ -501,15 +513,37 @@ bool NodePanelBrushPreset::restore()
fseek(fp, 0, SEEK_SET);
std::vector<uint8_t> data(sz);
fread(data.data(), 1, sz, fp);
BinaryStreamReader sr;
sr.init(data.data(), sz);
// sanity checks
if (sr.rstring(4) != "PPVR")
{
LOG("PPVR tag not found")
fclose(fp);
return false;
}
auto vmaj = sr.ru16();
auto vmin = sr.ru16();
if (vmaj != 0 && vmin != 1)
{
LOG("unrecognised version %d.$d", vmaj, vmin);
fclose(fp);
return false;
}
auto count = sr.ru32();
for (int k = 0; k < count; k++)
{
auto b = std::make_shared<Brush>();
sr >> *b;
if (!b->read(sr))
{
LOG("error deserializing the brush");
fclose(fp);
return false;
}
if (b->valid())
{