From 7c500a096a1e3047852e5ca5b81388041741d58b Mon Sep 17 00:00:00 2001 From: wangqr Date: Fri, 13 Sep 2019 15:49:15 -0400 Subject: [PATCH] Search user fonts in GDI font lister Windows now allow user install fonts without admin. List HKCU for those fonts. https://blogs.windows.com/windowsexperience/2018/06/27/announcing-windows-10-insider-preview-build-17704/ --- src/font_file_lister_gdi.cpp | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/font_file_lister_gdi.cpp b/src/font_file_lister_gdi.cpp index 1e55b7870..690655f10 100644 --- a/src/font_file_lister_gdi.cpp +++ b/src/font_file_lister_gdi.cpp @@ -66,28 +66,30 @@ std::vector get_installed_fonts() { std::vector files; - HKEY key; - auto ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fonts_key_name, 0, KEY_QUERY_VALUE, &key); - if (ret != ERROR_SUCCESS) return files; - BOOST_SCOPE_EXIT_ALL(=) { RegCloseKey(key); }; - - wchar_t fdir[MAX_PATH]; - SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, fdir); - agi::fs::path font_dir(fdir); - - for (DWORD i = 0;; ++i) { - wchar_t font_name[SHRT_MAX], font_filename[MAX_PATH]; - DWORD name_len = sizeof(font_name); - DWORD data_len = sizeof(font_filename); - - ret = RegEnumValueW(key, i, font_name, &name_len, NULL, NULL, reinterpret_cast(font_filename), &data_len); - if (ret == ERROR_NO_MORE_ITEMS) break; + for (HKEY hKey : { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }) { + HKEY key; + auto ret = RegOpenKeyExW(hKey, fonts_key_name, 0, KEY_QUERY_VALUE, &key); if (ret != ERROR_SUCCESS) continue; + BOOST_SCOPE_EXIT_ALL(= ) { RegCloseKey(key); }; - agi::fs::path font_path(font_filename); - if (!agi::fs::FileExists(font_path)) - font_path = font_dir / font_path; - files.push_back(font_path); + wchar_t fdir[MAX_PATH]; + SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, fdir); + agi::fs::path font_dir(fdir); + + for (DWORD i = 0;; ++i) { + wchar_t font_name[SHRT_MAX], font_filename[MAX_PATH]; + DWORD name_len = sizeof(font_name); + DWORD data_len = sizeof(font_filename); + + ret = RegEnumValueW(key, i, font_name, &name_len, NULL, NULL, reinterpret_cast(font_filename), &data_len); + if (ret == ERROR_NO_MORE_ITEMS) break; + if (ret != ERROR_SUCCESS) continue; + + agi::fs::path font_path(font_filename); + if (!agi::fs::FileExists(font_path) && agi::fs::FileExists(font_dir / font_path)) + font_path = font_dir / font_path; + files.push_back(font_path); + } } return files;