Skip to content

Commit

Permalink
Updated repair functions and improved code readability
Browse files Browse the repository at this point in the history
- Updated the `ExecuteRepair` and `GetRepairInfo` functions to handle different installer types more flexibly
- Removed `RepairMsixPackage` function. Updated function declarations in `RepairFlow.h` to reflect these changes.
- Simplified the determination of `repairPackage` in `ReportRepairResult`.
  • Loading branch information
Madhusudhan-MSFT committed Jun 10, 2024
1 parent 0ef11dc commit 6fd832b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
54 changes: 18 additions & 36 deletions src/AppInstallerCLICore/Workflows/RepairFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace AppInstaller::CLI::Workflow

void ExecuteRepair(Execution::Context& context)
{
InstallerTypeEnum installerTypeEnum = GetInstalledType(context);
InstallerTypeEnum installerTypeEnum = context.Contains(Execution::Data::Installer) ? context.Get<Execution::Data::Installer>()->EffectiveInstallerType() : GetInstalledType(context);

Synchronization::CrossProcessInstallLock lock;

Expand Down Expand Up @@ -341,10 +341,16 @@ namespace AppInstaller::CLI::Workflow
}
break;
case InstallerTypeEnum::Msix:
{
context <<
RepairMsixNonStorePackage;
}
break;
case InstallerTypeEnum::MSStore:
{
context <<
RepairMsixPackage;
EnsureStorePolicySatisfied <<
MSStoreRepair;
}
break;
case InstallerTypeEnum::Portable:
Expand All @@ -355,11 +361,11 @@ namespace AppInstaller::CLI::Workflow

void GetRepairInfo(Execution::Context& context)
{
InstallerTypeEnum installerTypeEnum = GetInstalledType(context);
InstallerTypeEnum installerTypeEnum = context.Contains(Execution::Data::Installer) ? context.Get<Execution::Data::Installer>()->BaseInstallerType : GetInstalledType(context);

switch (installerTypeEnum)
{
// Exe based installers, for installed package all gets mapped to exe extension.
// Exe based installers, for installed package all gets mapped to exe extension.
case InstallerTypeEnum::Burn:
case InstallerTypeEnum::Exe:
case InstallerTypeEnum::Inno:
Expand All @@ -377,44 +383,20 @@ namespace AppInstaller::CLI::Workflow
SetProductCodesInContext;
}
break;
// MSIX based installers, msix, msstore.
// MSIX based installers, msix.
case InstallerTypeEnum::Msix:
{
context <<
SetPackageFamilyNamesInContext;
}
case InstallerTypeEnum::MSStore:
break;
break;
case InstallerTypeEnum::Portable:
default:
THROW_HR(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));
}
}

void RepairMsixPackage(Execution::Context& context)
{
const auto& installedPackage = context.Get<Execution::Data::InstalledPackageVersion>();
std::string installedType = installedPackage->GetMetadata()[PackageVersionMetadata::InstalledType];

if (ConvertToInstallerTypeEnum(installedType) == InstallerTypeEnum::Msix)
{
// If the installed package is from Microsoft Store, then we attempt to repair it using MSStoreRepair else do package re-registration.
if (installedPackage->GetSource() == WellKnownSource::MicrosoftStore)
{
context <<
EnsureStorePolicySatisfied <<
MSStoreRepair;
}
else
{
context <<
SetPackageFamilyNamesInContext <<
RepairMsixNonStorePackage;
}
}
else
{
// This should never happen as the installer type should be one of the above.
THROW_HR(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));
}
}

void RepairMsixNonStorePackage(Execution::Context& context)
{
bool isMachineScope = Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope)) == Manifest::ScopeEnum::Machine;
Expand Down Expand Up @@ -473,7 +455,7 @@ namespace AppInstaller::CLI::Workflow
void SelectApplicablePackageVersion(Execution::Context& context)
{
// If the repair flow is initiated with manifest, then we don't need to select the applicable package version.
if(context.Args.Contains(Args::Type::Manifest))
if (context.Args.Contains(Args::Type::Manifest))
{
return;
}
Expand Down Expand Up @@ -527,7 +509,7 @@ namespace AppInstaller::CLI::Workflow

if (repairResult != 0)
{
auto& repairPackage = IsInstallerMappingRequired(context) ?
auto& repairPackage = context.Contains(Execution::Data::PackageVersion) ?
context.Get<Execution::Data::PackageVersion>() :
context.Get<Execution::Data::InstalledPackageVersion>();

Expand Down
6 changes: 0 additions & 6 deletions src/AppInstallerCLICore/Workflows/RepairFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ namespace AppInstaller::CLI::Workflow
// Outputs:RepairString?, ProductCodes?, PackageFamilyNames?
void GetRepairInfo(Execution::Context& context);

// Perform the repair operation for the MSIX package.
// RequiredArgs:None
// Inputs:PackageFamilyNames , InstallScope?
// Outputs:None
void RepairMsixPackage(Execution::Context& context);

// Perform the repair operation for the MSIX NonStore package.
// RequiredArgs:None
// Inputs:PackageFamilyNames , InstallScope?
Expand Down

0 comments on commit 6fd832b

Please sign in to comment.