Skip to content

Commit

Permalink
(chocolateyGH-121) PkgInfoService files service interaction
Browse files Browse the repository at this point in the history
Add the interaction to the package information service to read the
files file and save to the files file.
  • Loading branch information
ferventcoder committed May 3, 2015
1 parent 148bf26 commit f60ce80
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ internal class ChocolateyPackageInformationService : IChocolateyPackageInformati
{
private readonly IFileSystem _fileSystem;
private readonly IRegistryService _registryService;
private readonly IFilesService _filesService;
private const string REGISTRY_SNAPSHOT_FILE = ".registry";
private const string FILES_SNAPSHOT_FILE = ".files";
private const string SILENT_UNINSTALLER_FILE = ".silentUninstaller";
private const string SIDE_BY_SIDE_FILE = ".sxs";
private const string PIN_FILE = ".pin";

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService)
public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService)
{
_fileSystem = fileSystem;
_registryService = registryService;
_filesService = filesService;
}

public ChocolateyPackageInformation get_package_information(IPackage package)
Expand Down Expand Up @@ -63,6 +66,16 @@ public ChocolateyPackageInformation get_package_information(IPackage package)
logWarningInsteadOfError: true
);

FaultTolerance.try_catch_with_logging_exception(
() =>
{
packageInformation.FilesSnapshot = _filesService.read_from_file(_fileSystem.combine_paths(pkgStorePath, FILES_SNAPSHOT_FILE));
},
"Unable to read files snapshot file",
throwError: false,
logWarningInsteadOfError: true
);

packageInformation.HasSilentUninstall = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE));
packageInformation.IsSideBySide = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE));
packageInformation.IsPinned = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, PIN_FILE));
Expand All @@ -89,6 +102,11 @@ public void save_package_information(ChocolateyPackageInformation packageInforma
_registryService.save_to_file(packageInformation.RegistrySnapshot, _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE));
}

if (packageInformation.FilesSnapshot != null)
{
_filesService.save_to_file(packageInformation.FilesSnapshot, _fileSystem.combine_paths(pkgStorePath, FILES_SNAPSHOT_FILE));
}

if (packageInformation.HasSilentUninstall)
{
_fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII);
Expand Down

0 comments on commit f60ce80

Please sign in to comment.