Skip to content

Commit

Permalink
Refactore RepairApplicabilityCheck logic
Browse files Browse the repository at this point in the history
The commit includes:
- Refactore RepairApplicabilityCheck into
  - ApplicabilityCheckForInstalledPackage
  - ApplicabilityCheckForAvailablePackage
  for better readability
  • Loading branch information
Madhusudhan-MSFT committed Feb 15, 2024
1 parent 97ab9ee commit 416b716
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 38 deletions.
86 changes: 49 additions & 37 deletions src/AppInstallerCLICore/Workflows/RepairFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,62 +90,74 @@ namespace AppInstaller::CLI::Workflow
context.Add<Execution::Data::PackageFamilyNames>(packageFamilyNames);
}

void RepairApplicabilityCheck(Execution::Context& context)
void ApplicabilityCheckForInstalledPackage(Execution::Context& context)
{
// Installed Package repair applicability check
auto installedPackageVersion = context.Get<Execution::Data::InstalledPackageVersion>();

const std::string installerType = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata()[PackageVersionMetadata::InstalledType];
InstallerTypeEnum installerTypeEnum = ConvertToInstallerTypeEnum(installerType);

switch (installerTypeEnum)
if (installerTypeEnum == InstallerTypeEnum::Portable || installerTypeEnum == InstallerTypeEnum::Unknown)
{
context.Reporter.Error() << Resource::String::RepairOperationNotSupported << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED);
}

IPackageVersion::Metadata packageMetadata = installedPackageVersion->GetMetadata();

auto noModifyItr = packageMetadata.find(PackageVersionMetadata::NoModify);
std::string noModifyARPFlag = noModifyItr != packageMetadata.end() ? noModifyItr->second : std::string();

auto noRepairItr = packageMetadata.find(PackageVersionMetadata::NoRepair);
std::string noRepairARPFlag = noRepairItr != packageMetadata.end() ? noRepairItr->second : std::string();

if (Utility::IsDwordFlagSet(noModifyARPFlag) || Utility::IsDwordFlagSet(noRepairARPFlag))
{
case InstallerTypeEnum::Burn:
case InstallerTypeEnum::Exe:
case InstallerTypeEnum::Inno:
case InstallerTypeEnum::Nullsoft:
case InstallerTypeEnum::Msi:
case InstallerTypeEnum::Wix:
{
IPackageVersion::Metadata packageMetadata = installedPackageVersion->GetMetadata();

auto noModifyItr = packageMetadata.find(PackageVersionMetadata::NoModify);
std::string noModifyARPFlag = noModifyItr != packageMetadata.end() ? noModifyItr->second : std::string();

auto noRepairItr = packageMetadata.find(PackageVersionMetadata::NoRepair);
std::string noRepairARPFlag = noRepairItr != packageMetadata.end() ? noRepairItr->second : std::string();

if (Utility::IsDwordFlagSet(noModifyARPFlag) || Utility::IsDwordFlagSet(noRepairARPFlag))
{
context.Reporter.Error() << Resource::String::RepairOperationNotSupported << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED);
}
}
break;
case InstallerTypeEnum::Msix:
case InstallerTypeEnum::MSStore:
return; // No check needed for these types
case InstallerTypeEnum::Portable:
default:
THROW_HR(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));
context.Reporter.Error() << Resource::String::RepairOperationNotSupported << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED);
}
}

void ApplicabilityCheckForAvailablePackage(Execution::Context& context)
{
// Selected Installer repair applicability check
auto const& installerType = context.Get<Execution::Data::Installer>()->EffectiveInstallerType();
auto const& repairBehavior = context.Get<Execution::Data::Installer>()->RepairBehavior;

if (repairBehavior == RepairBehaviorEnum::Unknown)
if (installerType == InstallerTypeEnum::Portable || installerType == InstallerTypeEnum::Unknown)
{
context.Reporter.Error() << Resource::String::NoRepairInfoFound << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_NO_REPAIR_INFO_FOUND);
context.Reporter.Error() << Resource::String::RepairOperationNotSupported << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_REPAIR_NOT_SUPPORTED);
}
else if (repairBehavior == RepairBehaviorEnum::Installer)

// For other installer types, we can skip this check as we expect standard repair support from platform.
if (installerType == InstallerTypeEnum::Burn
|| installerType == InstallerTypeEnum::Inno
|| installerType == InstallerTypeEnum::Nullsoft
|| installerType == InstallerTypeEnum::Exe)
{
context <<
Workflow::EnsureSupportForDownload <<
Workflow::EnsureSupportForInstall;
if (repairBehavior == RepairBehaviorEnum::Unknown)
{
context.Reporter.Error() << Resource::String::NoRepairInfoFound << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_NO_REPAIR_INFO_FOUND);
}
else if (repairBehavior == RepairBehaviorEnum::Installer)
{
context <<
Workflow::EnsureSupportForDownload <<
Workflow::EnsureSupportForInstall;
}
}
}

void RepairApplicabilityCheck(Execution::Context& context)
{
context <<
ApplicabilityCheckForInstalledPackage <<
ApplicabilityCheckForAvailablePackage;
}

void ExecuteRepair(Execution::Context& context)
{
const auto& installer = context.Get<Execution::Data::Installer>();
Expand Down
5 changes: 4 additions & 1 deletion src/AppInstallerCLICore/Workflows/RepairFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

namespace AppInstaller::CLI::Workflow
{
void ApplicabilityCheckForInstalledPackage(Execution::Context& context);

void ApplicabilityCheckForAvailablePackage(Execution::Context& context);

void RepairApplicabilityCheck(Execution::Context& context);

void ExecuteRepair(Execution::Context& context);
Expand All @@ -23,7 +27,6 @@ namespace AppInstaller::CLI::Workflow

void RepairMsixPackage(Execution::Context& context);


// Reports the result of the repair.
// Required Args: None
// Inputs: None
Expand Down

0 comments on commit 416b716

Please sign in to comment.