Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows_font resource causes run to hang if font is already installed #8779

Open
bmiller08 opened this issue Jul 26, 2019 · 2 comments

Comments

@bmiller08
Copy link

commented Jul 26, 2019

Description

When using the windows_font resource the first pass works appropriately, but on the second pass it fails to detect the font is already installed. This causes windows to give a prompt stating

The <name> font is already installed. Do you want to replace it?

Over winrm this causes the run to just hang, but locally you can cancel or accept.

I believe this is the fault of the assumption that all resulting fonts will be in C:\Windows\Fonts, but, at least on Windows 10 1903, the resulting font is installed per user to Local AppData (for example C:\Users\vagrant\AppData\Local\Microsoft\Windows\Fonts).

Chef Version

  • 14.11.13
  • 15.1.36

Platform Version

  • Windows 10 1903

Replication Case

Add a font to your cookbook files then create a resource like this:

windows_font 'SomeExampleFont.ttf' do
  action :install
end

Run the resulting cookbook twice. The first run should succeed and the second hang.

Client Output

It hangs right at the end of this line and does not proceed

         * windows_font[SomeExampleFont.ttf] action install
           * cookbook_file[SomeExampleFont.ttf] action create
             - create new file C:\Users\vagrant\AppData\Local\Temp\SomeExampleFont.ttf
             - update content in file C:\Users\vagrant\AppData\Local\Temp\SomeExampleFont.ttf from none to c30c4f
             (new content is binary, diff output suppressed)

Stacktrace

@tas50

This comment has been minimized.

Copy link
Member

commented Jul 26, 2019

Thanks for the report @bmiller08. That's certainly not the desired behavior.

@bmiller08

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

As a follow up to this @tas50 the resource, as it is currently, works fine on Windows 10 1803 as well as older platforms (like Windows 7, which I know isn't really supported anyway). If my research is correct the behavior of how fonts are installed changed in Windows 10 1809.

As a work around in newer versions of Windows 10 I've been directly adding the font to the system fonts folder and writing the registry entry which goes in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts.

A WIP but, for anyone else with this issue, here is what that looks like:

resource_name :example_font

property :source, String, required: true, name_property: true
property :type, String, default: 'TrueType'

default_action :install

action :install do
  cookbook_file "C:\\Windows\\Fonts\\#{new_resource.source}" do
    source new_resource.source
    action :create
  end

  registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' do
    values [{
      name: "#{::File.basename(new_resource.source, ::File.extname(new_resource.source))} (#{new_resource.type})",
      type: :string,
      data: ::File.basename(new_resource.source)
    }]
    action :create
  end
end

action :remove do
  cookbook_file "C:\\Windows\\Fonts\\#{new_resource.source}" do
    source new_resource.source
    action :create
  end

  registry_key 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' do
    values [{
      name: "#{::File.basename(new_resource.source, ::File.extname(new_resource.source))} (#{new_resource.type})",
      type: :string,
      data: ::File.basename(new_resource.source)
    }]
    action :delete
  end
end

Not 100% certain of the format for the registry string name, but it seems as long as the value points to the correct file that was copied to the system fonts folder then its available to use.

This article was my starting place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.