Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryfu-msft committed Dec 5, 2024
1 parent 4efa09f commit aeab647
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/AppInstallerCLICore/Workflows/DownloadFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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<Execution::Data::Installer>();

// Get file name from download URI
std::filesystem::path filename = GetFileNameFromURI(context.Get<Execution::Data::Installer>()->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<Execution::Data::Manifest>();
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<Execution::Data::Manifest>();
filename = Utility::ConvertToUTF16(manifest.Id + '.' + manifest.Version);
}

filename += installerExtension;
}

// Make file name suitable for file system path
filename = Utility::ConvertToUTF16(Utility::MakeSuitablePathPart(filename.u8string()));
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerSharedLib/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down

0 comments on commit aeab647

Please sign in to comment.