From bb3e0de728cb004a01edca7c16ae850b6b7fb5df Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 9 Jan 2016 08:38:41 -0800 Subject: [PATCH] Handle i/o errors when indexing fonts for GDI --- src/font_file_lister_gdi.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/font_file_lister_gdi.cpp b/src/font_file_lister_gdi.cpp index ff33ef8e5..94e699d5b 100644 --- a/src/font_file_lister_gdi.cpp +++ b/src/font_file_lister_gdi.cpp @@ -16,6 +16,8 @@ #include "font_file_lister.h" +#include "compat.h" + #include #include #include @@ -91,15 +93,20 @@ std::vector get_installed_fonts() { using font_index = std::unordered_multimap; -font_index index_fonts() { +font_index index_fonts(FontCollectorStatusCallback &cb) { font_index hash_to_path; auto fonts = get_installed_fonts(); std::unique_ptr buffer(new char[1024]); for (auto const& path : fonts) { - auto stream = agi::io::Open(path, true); - stream->read(&buffer[0], 1024); - auto hash = murmur3(&buffer[0], stream->tellg()); - hash_to_path.emplace(hash, path); + try { + auto stream = agi::io::Open(path, true); + stream->read(&buffer[0], 1024); + auto hash = murmur3(&buffer[0], stream->tellg()); + hash_to_path.emplace(hash, path); + } + catch (agi::Exception const& e) { + cb(to_wx(e.GetMessage() + "\n"), 3); + } } return hash_to_path; } @@ -126,7 +133,7 @@ GdiFontFileLister::GdiFontFileLister(FontCollectorStatusCallback &cb) : dc(CreateCompatibleDC(nullptr), [](HDC dc) { DeleteDC(dc); }) { cb(_("Updating font cache\n"), 0); - index = index_fonts(); + index = index_fonts(cb); } CollectionResult GdiFontFileLister::GetFontPaths(std::string const& facename, int bold, bool italic, std::vector const& characters) {