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

Font Install #5042

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Font Install #5042

wants to merge 12 commits into from

Conversation

ryfu-msft
Copy link
Contributor

@ryfu-msft ryfu-msft commented Dec 5, 2024

Related to: #392, #4842

Changes:
Adds Support for installing a font.

  • Created a FontInstaller that does two things based on the scope. place the file in the fonts directory, and writes the subkey entry in the Fonts Registry based on the title of the file.
  • Added a IsFontSupported function that calls upon the Dwrite Analyze function to determine if the system can support installing the font. In the flow, if this fails, we error out with no way to override.
  • Adds a new font install command but currently only supports installing from a local manifest. This means that the same font manifest will work for regular install.

Tests:

  • Added tests to verify if the installation was successful and if the correct error message is displayed if the font file is invalid.
Microsoft Reviewers: Open in CodeFlow

This comment has been minimized.

This comment has been minimized.

@ryfu-msft ryfu-msft marked this pull request as ready for review December 10, 2024 17:30
@ryfu-msft ryfu-msft requested a review from a team as a code owner December 10, 2024 17:30
void FontInstallCommand::Complete(Execution::Context& context, Args::Type valueType) const
{
UNREFERENCED_PARAMETER(valueType);
context.Reporter.Error() << Resource::String::PendingWorkError << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

Does this still result in PowerShell giving the filesystem as options when tabbing? If not, probably better to just have a comment and not fail.

if (scope == Manifest::ScopeEnum::Machine)
{
m_installLocation = Runtime::GetPathTo(Runtime::PathName::FontsMachineInstallLocation);
m_key = Registry::Key::OpenIfExists(HKEY_LOCAL_MACHINE, std::wstring{ s_FontsPathSubkey }, 0, KEY_WRITE );
Copy link
Member

Choose a reason for hiding this comment

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

I know that the chances of this (and the user scope one) not existing are basically none, but we should still protect ourselves in the case that it does not. At a minimum the code should raise an error, but the proper thing to do would be to create the key so that the install can proceed.

const auto& fileName = filePath.filename();
const auto& destinationPath = m_installLocation / fileName;

AICLI_LOG(CLI, Info, << "Getting Font title");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AICLI_LOG(CLI, Info, << "Getting Font title");
AICLI_LOG(CLI, Verbose, << "Getting Font title");


if (IsTrueTypeFont(fontFile.FileType))
{
title += s_TrueType;
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary, or just following convention?

AICLI_LOG(CLI, Info, << "Creating font subkey with name: " << AppInstaller::Utility::ConvertToUTF8(title));
if (m_scope == Manifest::ScopeEnum::Machine)
{
m_key.SetValue(title, fileName, REG_SZ);
Copy link
Member

Choose a reason for hiding this comment

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

Is it truly always a 1:1 registry value to file?

// This should be extremely common, but just in case fall back to the older name style.
if (filename.has_stem() && ((filename.wstring().size() + installerExtension.size()) < MAX_PATH))
// Default to URI for fonts since fonts can have multiple file extensions.
if (installer->BaseInstallerType != InstallerTypeEnum::Font)
Copy link
Member

Choose a reason for hiding this comment

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

Please create a semantic function rather than a direct comparison. Or instead handle returning an empty value from GetInstallerFileExtension as meaning "don't attempt to add an extension".

}
else
{
AICLI_LOG(CLI, Warning, << "Font file is supported: " << file);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AICLI_LOG(CLI, Warning, << "Font file is supported: " << file);
AICLI_LOG(CLI, Verbose, << "Font file is supported: " << file);


context.Reporter.Info() << Resource::String::InstallFlowStartingPackageInstall << std::endl;

Manifest::ScopeEnum scope = AppInstaller::Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope));
Copy link
Member

Choose a reason for hiding this comment

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

Handle InstallScope not being supplied?

FontInstaller fontInstaller = FontInstaller(scope);

fontInstaller.Install(fontFiles);
context.Add<Execution::Data::OperationReturnCode>(ERROR_SUCCESS);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
context.Add<Execution::Data::OperationReturnCode>(ERROR_SUCCESS);
context.Add<Execution::Data::OperationReturnCode>(S_OK);

HRESULT > Win32 error code

@@ -222,6 +222,8 @@ namespace AppInstaller
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_SFSCLIENT_PACKAGE_NOT_SUPPORTED, "The Microsoft Store package does not support download."),
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_LICENSING_API_FAILED_FORBIDDEN, "Failed to retrieve Microsoft Store package license. The Microsoft Entra Id account does not have the required privilege."),
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_INSTALLER_ZERO_BYTE_FILE, "Downloaded zero byte installer; ensure that your network connection is working properly."),
WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_FONT_INSTALL_FAILED, "Failed to install font package"),
Copy link
Member

Choose a reason for hiding this comment

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

As I have also been told many times, there is also an .md file with the errors.

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.

2 participants