Skip to content

Commit

Permalink
(GH-487) Registry Snapshot Enhancements / Fixes
Browse files Browse the repository at this point in the history
- Same some values coming from the registry as CData, in case they have
   values that are not legal in XML when serialized.
- Remove the null terminator in bad registry keys, if found.
- Report where failing key is located, when unable to read a snapshot
   file.
  • Loading branch information
ferventcoder committed Jun 12, 2016
1 parent c0c2520 commit 590bad6
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="infrastructure.app\domain\installers\SquirrelInstaller.cs" />
<Compile Include="infrastructure.app\domain\installers\WiseInstaller.cs" />
<Compile Include="infrastructure.app\domain\RegistryHiveType.cs" />
<Compile Include="infrastructure.app\domain\RegistryValueExtensions.cs" />
<Compile Include="infrastructure.app\domain\RegistryValueKindType.cs" />
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
<Compile Include="infrastructure.app\services\FileTypeDetectorService.cs" />
Expand Down Expand Up @@ -285,6 +286,7 @@
<Compile Include="infrastructure\tokens\TokenReplacer.cs" />
<Compile Include="ILogExtensions.cs" />
<Compile Include="infrastructure\tolerance\FaultTolerance.cs" />
<Compile Include="infrastructure\xml\XmlCData.cs" />
<Compile Include="LogExtensions.cs" />
<Compile Include="ObjectExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
19 changes: 10 additions & 9 deletions src/chocolatey/infrastructure.app/domain/RegistryApplicationKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chocolatey.infrastructure.app.domain
using System;
using System.Xml.Serialization;
using Microsoft.Win32;
using xml;

[Serializable]
[XmlType("key")]
Expand All @@ -35,14 +36,14 @@ public class RegistryApplicationKey : IEquatable<RegistryApplicationKey>
[XmlAttribute(AttributeName = "displayName")]
public string DisplayName { get; set; }

public string InstallLocation { get; set; }
public string UninstallString { get; set; }
public XmlCData InstallLocation { get; set; }
public XmlCData UninstallString { get; set; }
public bool HasQuietUninstall { get; set; }

// informational
public string Publisher { get; set; }
public XmlCData Publisher { get; set; }
public string InstallDate { get; set; }
public string InstallSource { get; set; }
public XmlCData InstallSource { get; set; }
public string Language { get; set; } //uint

// version stuff
Expand All @@ -63,7 +64,7 @@ public class RegistryApplicationKey : IEquatable<RegistryApplicationKey>
public bool NoRepair { get; set; }
public string ReleaseType { get; set; } //hotfix, securityupdate, update rollup, servicepack
public string ParentKeyName { get; set; }
public string LocalPackage { get; set; }
public XmlCData LocalPackage { get; set; }

/// <summary>
/// Is an application listed in ARP (Programs and Features)?
Expand All @@ -75,7 +76,7 @@ public class RegistryApplicationKey : IEquatable<RegistryApplicationKey>
public bool is_in_programs_and_features()
{
return !string.IsNullOrWhiteSpace(DisplayName)
&& !string.IsNullOrWhiteSpace(UninstallString)
&& !string.IsNullOrWhiteSpace(UninstallString.to_string())
&& InstallerType != InstallerType.HotfixOrSecurityUpdate
&& InstallerType != InstallerType.ServicePack
&& string.IsNullOrWhiteSpace(ParentKeyName)
Expand All @@ -99,7 +100,7 @@ public override int GetHashCode()
{
return DisplayName.GetHashCode()
& DisplayVersion.GetHashCode()
& UninstallString.GetHashCode()
& UninstallString.to_string().GetHashCode()
& KeyPath.GetHashCode();
}

Expand All @@ -114,9 +115,9 @@ bool IEquatable<RegistryApplicationKey>.Equals(RegistryApplicationKey other)
{
if (ReferenceEquals(other, null)) return false;

return DisplayName.is_equal_to(other.DisplayName)
return DisplayName.to_string().is_equal_to(other.DisplayName)
&& DisplayVersion.is_equal_to(other.DisplayVersion)
&& UninstallString.is_equal_to(other.UninstallString)
&& UninstallString.to_string().is_equal_to(other.UninstallString.to_string())
&& KeyPath.is_equal_to(other.KeyPath)
;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.domain
{
using Microsoft.Win32;

public static class RegistryValueExtensions
{
public static string get_value_as_string(this RegistryKey key, string name)
{
if (key == null) return string.Empty;

return key.GetValue(name).to_string().Replace("\0", string.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)

foreach (var key in registryKeys.or_empty_list_if_null())
{
this.Log().Debug(() => " Preparing uninstall key '{0}'".format_with(key.UninstallString.escape_curly_braces()));
this.Log().Debug(() => " Preparing uninstall key '{0}'".format_with(key.UninstallString.to_string().escape_curly_braces()));

if ((!string.IsNullOrWhiteSpace(key.InstallLocation) && !_fileSystem.directory_exists(key.InstallLocation)) || !_registryService.installer_value_exists(key.KeyPath, ApplicationParameters.RegistryValueInstallLocation))
{
this.Log().Info(" Skipping auto uninstaller - The application appears to have been uninstalled already by other means.");
this.Log().Debug(() => " Searched for install path '{0}' - found? {1}".format_with(key.InstallLocation.escape_curly_braces(), _fileSystem.directory_exists(key.InstallLocation)));
this.Log().Debug(() => " Searched for install path '{0}' - found? {1}".format_with(key.InstallLocation.to_string().escape_curly_braces(), _fileSystem.directory_exists(key.InstallLocation)));
this.Log().Debug(() => " Searched for registry key '{0}' value '{1}' - found? {2}".format_with(key.KeyPath.escape_curly_braces(), ApplicationParameters.RegistryValueInstallLocation, _registryService.installer_value_exists(key.KeyPath, ApplicationParameters.RegistryValueInstallLocation)));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ChocolateyPackageInformation get_package_information(IPackage package)
{
packageInformation.RegistrySnapshot = _registryService.read_from_file(_fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE));
},
"Unable to read registry snapshot 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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private IEnumerable<PackageResult> report_registry_programs(ChocolateyConfigurat
if (config.RegularOutput)
{
this.Log().Info("{0}|{1}".format_with(key.DisplayName, key.DisplayVersion));
if (config.Verbose) this.Log().Info(" InstallLocation: {0}{1} Uninstall:{2}".format_with(key.InstallLocation.escape_curly_braces(), Environment.NewLine, key.UninstallString.escape_curly_braces()));
if (config.Verbose) this.Log().Info(" InstallLocation: {0}{1} Uninstall:{2}".format_with(key.InstallLocation.to_string().escape_curly_braces(), Environment.NewLine, key.UninstallString.to_string().escape_curly_braces()));
}
count++;

Expand Down
Loading

0 comments on commit 590bad6

Please sign in to comment.