forked from mia/Aegisub
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/
This commit is contained in:
parent
bd4c7789cf
commit
7c500a096a
1 changed files with 22 additions and 20 deletions
|
@ -66,28 +66,30 @@ std::vector<agi::fs::path> get_installed_fonts() {
|
|||
|
||||
std::vector<agi::fs::path> 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<BYTE *>(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<BYTE*>(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;
|
||||
|
|
Loading…
Reference in a new issue