Skip to content

Commit

Permalink
(chocolatey#3315) Save software installation location
Browse files Browse the repository at this point in the history
Saves the software installation location into a ".softwareLocation"
file inside the package info directory. This allows Chocolatey CLI
or GUI to later retrieve it and display it to the user when listing
the details of locally installed package(s).
  • Loading branch information
TheCakeIsNaOH authored and gep13 committed Apr 26, 2024
1 parent 2fd17fc commit 929af7b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public ChocolateyPackageInformation(IPackageMetadata package)
public bool HasSilentUninstall { get; set; }
public bool IsPinned { get; set; }
public string ExtraInformation { get; set; }
public string DeploymentLocation { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
private const string ArgsFile = ".arguments";
private const string ExtraFile = ".extra";
private const string VersionOverrideFile = ".version";
private const string DeploymentLocationFile = ".deploymentLocation";

// We need to store the package identifiers we have warned about
// to prevent duplicated outputs.
Expand Down Expand Up @@ -179,6 +180,20 @@ has errored attempting to read it. This file will be renamed to
);
}

var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile);
if (_fileSystem.FileExists(locationFile))
{
FaultTolerance.TryCatchWithLoggingException(
() =>
{
packageInformation.DeploymentLocation = _fileSystem.ReadFile(locationFile);
},
"Unable to read deployment location file",
throwError: false,
logWarningInsteadOfError: true
);
}

return packageInformation;
}

Expand Down Expand Up @@ -280,6 +295,21 @@ public void Save(ChocolateyPackageInformation packageInformation)
{
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, PinFile));
}

if (!string.IsNullOrWhiteSpace(packageInformation.DeploymentLocation))
{
var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile);
if (_fileSystem.FileExists(locationFile))
{
_fileSystem.DeleteFile(locationFile);
}

_fileSystem.WriteFile(locationFile, packageInformation.DeploymentLocation);
}
else
{
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile));
}
}

public void Remove(IPackageMetadata package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
}
}

pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation);

UpdatePackageInformation(pkgInfo);
EnsureBadPackagesPathIsClean(packageResult);
EventManager.Publish(new HandlePackageResultCompletedMessage(packageResult, config, commandName));
Expand Down Expand Up @@ -601,11 +603,10 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC

this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".FormatWith(commandName.ToStringSafe(), packageResult.Name));

var installLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation);
var installerDetected = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallerType);
if (!string.IsNullOrWhiteSpace(installLocation))
if (!string.IsNullOrWhiteSpace(pkgInfo.DeploymentLocation))
{
this.Log().Info(ChocolateyLoggers.Important, " Software installed to '{0}'".FormatWith(installLocation.EscapeCurlyBraces()));
this.Log().Info(ChocolateyLoggers.Important, " Deployed to to '{0}'".FormatWith(pkgInfo.DeploymentLocation.EscapeCurlyBraces()));
}
else if (!string.IsNullOrWhiteSpace(installerDetected))
{
Expand Down

0 comments on commit 929af7b

Please sign in to comment.