Skip to content

Fix user mode fonts to install & add repair support - #6619

Open
David Bennett (dkbennett) wants to merge 10 commits into
microsoft:masterfrom
dkbennett:user/dkbennett/userfonts
Open

David Bennett (dkbennett) wants to merge 10 commits into
microsoft:masterfrom
dkbennett:user/dkbennett/userfonts

Conversation

@dkbennett

@dkbennett David Bennett (dkbennett) commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

📖 Description

Align user-scope font installation with the machine-scope model to address fonts missing from Windows discovery after sign-out or restart.

  • Install user fonts directly into %LOCALAPPDATA%\Microsoft\Windows\Fonts and register their absolute paths under HKCU\Software\Microsoft\Windows NT\CurrentVersion\Fonts.
  • Track original filenames separately from collision-renamed installed files using the same package inventory mapping strategy for both scopes.
  • Add font repair using installed package metadata. Repair migrates existing nested user installations to the flat layout and restores discovery registrations without downloading fonts.
  • Update validation, inventory, and uninstall to handle both layouts. Remove only mapped files and matching registrations, preserving unrelated files and the shared Fonts directory.

Machine-scope discovery registrations retain their relative filename values. Migration rollback is per-file and best effort.

🔗 References

Addresses #6535.

🔍 Validation

Automated coverage checks exact inventory filenames, flat installation paths, REG_SZ discovery values, scope isolation, filename collisions, repair migration, failure handling, and uninstall cleanup.

AppInstallerCLITests.exe '[fonts],[FontHelper],[RepairFlow]'
Passed: 334 assertions in 29 test cases.
wingetdev font list --details --disable-interactivity: passed against the locally deployed dev build with fonts enabled.

Did manual validation of corrupt fonts and font repair with Microsoft.FluentFonts and ryanoasis.CaskaydiaCove fonts being installed in the user scope. I installed these using existing Winget, confirmed after reboot that the fonts stopped working. Then ran the repair using the updated winget cli winget repair FONT\User\Microsoft.FluentFonts
The repair was successful, the detailed font list no longer showed as corrupt, and the fonts were showing up in the font list again. After reboot I confirmed the repaired user fonts are still available in the font list, which confirms the bug, successful repair, and that the new user install works.

✅ Checklist

🤖 AI Assistance

  • AI assistance was used and has been disclosed in this PR
  • No AI assistance was used

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

@github-actions

This comment has been minimized.

Preserve font and pre-indexed source test hooks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a9e21d38-9ab1-4358-963d-9aadad897ad0
@github-actions

This comment has been minimized.

Add a regression for volatile shared test keys and acknowledge fontlayout in the spelling dictionary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a9e21d38-9ab1-4358-963d-9aadad897ad0

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved font-path collisions and overly restrictive filename validation can block valid installs, repairs, and uninstalls, while malformed inventory mappings can truncate font listings.

3 open issues
What changed in this PR

This PR addresses user fonts disappearing after sign-out or restart by aligning their installation layout with machine-scope fonts. It also adds repair support using installed metadata, without downloading fonts.

Changes:

  • Install user fonts directly in the shared Fonts directory with absolute-path discovery registrations.
  • Add repair to migrate legacy nested installations and restore registrations.
  • Update inventory, validation, uninstall, and tests for both layouts and filename collisions.
File Description
src/​AppInstallerCommonCore/​Public/​winget/​Fonts.h Declares the font repair API.
src/​AppInstallerCommonCore/​Fonts.cpp Implements flat installation, repair migration, mapping validation, and cleanup.
src/​AppInstallerCLITests/​TestHooks.h Adds registry and session-isolation test hooks.
src/​AppInstallerCLITests/​RepairFlow.cpp Tests font repair dispatch and elevation restrictions.
src/​AppInstallerCLITests/​Fonts.cpp Covers layouts, collisions, migration, failures, and uninstall.
src/​AppInstallerCLIE2ETests/​Helpers/​TestCommon.cs Verifies exact inventory filenames and discovery registrations.
src/​AppInstallerCLIE2ETests/​FontCommand.cs Updates installation checks and adds user-font repair coverage.
src/​AppInstallerCLICore/​Workflows/​RepairFlow.cpp Routes font packages through the repair workflow.
src/​AppInstallerCLICore/​Workflows/​FontFlow.h Declares the font repair workflow.
src/​AppInstallerCLICore/​Workflows/​FontFlow.cpp Repairs fonts from installed metadata with scope checks.
.github/​actions/​spelling/​expect.txt Adds the font-layout test tag to spelling expectations.

Review effort: Balanced

Comment thread src/AppInstallerCommonCore/Fonts.cpp Resolved
Comment thread src/AppInstallerCommonCore/Fonts.cpp Resolved
Comment thread src/AppInstallerCommonCore/Fonts.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Font filename collisions can block installation or repair at the 255-character boundary, while repeated per-font mapping scans introduce quadratic overhead in font listings and installed-source population.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Suffix collisions can exceed the filesystem filename limit

src/​AppInstallerCommonCore/​Fonts.cpp:241

When a 255-character ASCII font filename collides, appending the first numeric suffix produces a 256-character name that exceeds the filesystem component limit and fails IsFontFileNameSafe. This prevents a second user-scope package with that filename from installing, and prevents legacy repair when the destination name is occupied. Reserve space for the suffix and extension using a Unicode-safe truncation or hashing strategy, and add a collision test at the 255-character boundary.

Medium severity Repeated mapping scans make package font enumeration quadratic

src/​AppInstallerCommonCore/​Fonts.cpp:621

GetRegisteredFontInstallPath now reads and validates every package mapping for each font, so enumerating a package with N fonts performs N² mapping reads and validations. This affects both detailed font listings and installed-source population through FontHelper::PopulateIndex, where installed paths previously bypassed the mapping scan. Load and validate the mappings once per package version and reuse them across its files in both inventory paths.

3 resolved since last review

Review effort: Balanced

Preserve font repair tests alongside the shared elevation guards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b3c6193f-8e2d-414a-8976-01c6c2566738
@JohnMcPMS

Copy link
Copy Markdown
Member

I don't know why, but the last review brought up some missed items and then didn't make them specific comments. Maybe people don't like the never-ending churn of feedback.

The one about making the lookup N^2 seems bad though. The max path one less so, but if you are going to push an update...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A malformed font mapping in one package version aborts enumeration of all remaining versions, causing valid legacy user fonts to disappear from the detailed inventory.

1 open issue

Review effort: Balanced

Comment thread src/AppInstallerCommonCore/Fonts.cpp Resolved
@dkbennett

Copy link
Copy Markdown
Member Author

I don't know why, but the last review brought up some missed items and then didn't make them specific comments. Maybe people don't like the never-ending churn of feedback.

The one about making the lookup N^2 seems bad though. The max path one less so, but if you are going to push an update...

Yes that was no bueno; I fixed the quadratic issue in the previous push after seeing the obscured finding. A little annoying that something like that doesn't bubble up to a meaningful comment but a comment typo is urgent!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Repeated scans of the shared font registry can cause quadratic work during package enumeration and routine source indexing, warranting human assessment of the performance impact.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the font installation and repair changes.

No open issues 🎉

Review effort: Balanced

Comment thread src/AppInstallerCommonCore/Fonts.cpp Resolved

@ranm-msft ranm-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concrete follow-up from the current diff.


std::string GetFontPathKey(const std::filesystem::path& path)
{
return FoldCase(static_cast<std::string_view>(path.lexically_normal().u8string()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use Windows-compatible filename identity instead of full Unicode case folding? For example, ß.ttf and ss.ttf are distinct Windows filenames but FoldCase maps both paths to the same key. GetFontRegistrations then selects both registrations, so uninstalling one font deletes the other font's discovery registration as well. Please add a cross-package regression showing that uninstalling ß.ttf preserves the registration for ss.ttf.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the key needs to map uniqueness onto the file system, we would probably need to find a Windows API to canonicalize (it is possible that the existing normalized string can do it the way the filesystem does). For direct path comparison, it is probably better to use std::filesystem::equivalent than case folded comparison. But that doesn't allow for a sort and thus a map container.

A middle ground would be to use case-folded strings for the initial hash map, then a vector of items containing the original path and linear std::filesystem::equivalent search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants