Exemple #1
0
        public ChocolateyPackageInformation get_package_information(IPackage package)
        {
            var packageInformation = new ChocolateyPackageInformation(package);

            if (package == null)
            {
                this.Log().Debug("No package information as package is null.");
                return(packageInformation);
            }

            var pkgStorePath = _fileSystem.combine_paths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".format_with(package.Id, package.Version.to_string()));

            if (!_fileSystem.directory_exists(pkgStorePath))
            {
                return(packageInformation);
            }

            var deserializationErrorMessage = @"
A corrupt .registry file exists at {0}.
 Open this file in a text editor, and remove/escape any characters that
 are regarded as illegal within XML strings not surrounded by CData. 
 These are typically the characters &, `<`, and `>`. Again, this
 is an XML document, so you will see many < and > characters, so just
 focus exclusively in the string values not surrounded by CData. Once 
 these have been corrected, rename the .registry.bad file to .registry.
 Once saved, try running the same Chocolatey command that was just 
 executed, so verify problem is fixed.
 NOTE: It will not be possible to rename the file in Windows Explorer.
 Instead, you can use the following PowerShell command:
 Move-Item .\.registry.bad .\.registry
".format_with(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_BAD_FILE));

            try
            {
                if (_fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_BAD_FILE)))
                {
                    this.Log().Warn(deserializationErrorMessage);
                }
                else
                {
                    packageInformation.RegistrySnapshot = _registryService.read_from_file(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE));
                }
            }
            catch (Exception)
            {
                FaultTolerance.try_catch_with_logging_exception(
                    () =>
                {
                    this.Log().Warn(deserializationErrorMessage);

                    // rename the bad registry file so that it isn't processed again
                    _fileSystem.move_file(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE), _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_BAD_FILE));
                },
                    "Unable to read registry snapshot file for {0} (located at {1})".format_with(package.Id, _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE)),
                    throwError: false,
                    logWarningInsteadOfError: true,
                    isSilent: 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,
                isSilent: 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));
            var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE);

            if (_fileSystem.file_exists(argsFile))
            {
                packageInformation.Arguments = _fileSystem.read_file(argsFile);
            }
            var extraInfoFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE);

            if (_fileSystem.file_exists(extraInfoFile))
            {
                packageInformation.ExtraInformation = _fileSystem.read_file(extraInfoFile);
            }

            var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE);

            if (_fileSystem.file_exists(versionOverrideFile))
            {
                FaultTolerance.try_catch_with_logging_exception(
                    () =>
                {
                    packageInformation.VersionOverride = new SemanticVersion(_fileSystem.read_file(versionOverrideFile).trim_safe());
                },
                    "Unable to read version override file",
                    throwError: false,
                    logWarningInsteadOfError: true
                    );
            }

            return(packageInformation);
        }