From aeab6472ed8dcd8ab68b13091146ef3588cf6d24 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 5 Dec 2024 13:10:18 -0800 Subject: [PATCH] minor fixes --- .../Workflows/DownloadFlow.cpp | 35 +++++++++++-------- src/AppInstallerSharedLib/Errors.cpp | 2 ++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp b/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp index cf483626ed..219be19126 100644 --- a/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp @@ -57,8 +57,6 @@ namespace AppInstaller::CLI::Workflow return L".msix"sv; case InstallerTypeEnum::Zip: return L".zip"sv; - case InstallerTypeEnum::Font: - return L".ttf"sv; default: THROW_HR(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); } @@ -73,23 +71,30 @@ namespace AppInstaller::CLI::Workflow // Gets the file name that can be used to ShellExecute the file. std::filesystem::path GetInstallerPostHashValidationFileName(Execution::Context& context) { + const auto& installer = context.Get(); + // Get file name from download URI - std::filesystem::path filename = GetFileNameFromURI(context.Get()->Url); - std::wstring_view installerExtension = GetInstallerFileExtension(context); + std::filesystem::path filename = GetFileNameFromURI(installer->Url); - // Assuming that we find a safe stem value in the URI, use it. - // 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) { - filename = filename.stem(); - } - else - { - const auto& manifest = context.Get(); - filename = Utility::ConvertToUTF16(manifest.Id + '.' + manifest.Version); - } + std::wstring_view installerExtension = GetInstallerFileExtension(context); - filename += installerExtension; + // Assuming that we find a safe stem value in the URI, use it. + // 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)) + { + filename = filename.stem(); + } + else + { + const auto& manifest = context.Get(); + filename = Utility::ConvertToUTF16(manifest.Id + '.' + manifest.Version); + } + + filename += installerExtension; + } // Make file name suitable for file system path filename = Utility::ConvertToUTF16(Utility::MakeSuitablePathPart(filename.u8string())); diff --git a/src/AppInstallerSharedLib/Errors.cpp b/src/AppInstallerSharedLib/Errors.cpp index 73e81ef12e..58392ad0a4 100644 --- a/src/AppInstallerSharedLib/Errors.cpp +++ b/src/AppInstallerSharedLib/Errors.cpp @@ -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"), + WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_FONT_FILE_NOT_SUPPORTED, "Font file is not supported and cannot be installed."), // Install errors. WINGET_HRESULT_INFO(APPINSTALLER_CLI_ERROR_INSTALL_PACKAGE_IN_USE, "Application is currently running. Exit the application then try again."),