Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (maint) use case insensitive compare for token
  (GH-769) API - Resolve Merged Assemblies
  • Loading branch information
ferventcoder committed Jun 5, 2016
2 parents 2d66837 + 29de194 commit f3140a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/chocolatey/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey
{
using System.IO;
using System.Linq;
using System.Reflection;
using infrastructure.adapters;

/// <summary>
Expand Down Expand Up @@ -71,7 +72,14 @@ public static string get_public_key_token(this IAssembly assembly)
{
if (assembly == null) return string.Empty;

byte[] publicKeyToken = assembly.GetName().GetPublicKeyToken();
return assembly.GetName().get_public_key_token();
}

public static string get_public_key_token(this AssemblyName assemblyName)
{
if (assemblyName == null) return string.Empty;

byte[] publicKeyToken = assemblyName.GetPublicKeyToken();

if (publicKeyToken == null || publicKeyToken.Length == 0) return string.Empty;

Expand Down
23 changes: 21 additions & 2 deletions src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ namespace chocolatey
{
using System;
using System.Collections.Generic;
using System.Reflection;
using infrastructure.licensing;
using NuGet;
using SimpleInjector;
using infrastructure.adapters;
using infrastructure.app;
using infrastructure.app.builders;
using infrastructure.app.configuration;
Expand All @@ -30,6 +29,7 @@ namespace chocolatey
using infrastructure.logging;
using infrastructure.registration;
using resources;
using Assembly = infrastructure.adapters.Assembly;
using IFileSystem = infrastructure.filesystem.IFileSystem;

// ReSharper disable InconsistentNaming
Expand All @@ -41,8 +41,27 @@ public static class Lets
{
public static GetChocolatey GetChocolatey()
{
add_assembly_resolver();
return new GetChocolatey();
}

private static ResolveEventHandler _handler = null;

private static void add_assembly_resolver()
{
_handler = (sender, args) =>
{
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey))
{
return typeof(Lets).Assembly;
}

return null;
};

AppDomain.CurrentDomain.AssemblyResolve += _handler;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private ICommand find_command(ChocolateyConfiguration config, Container containe
}

var token = Assembly.GetExecutingAssembly().get_public_key_token();
if (string.IsNullOrWhiteSpace(token) || token != ApplicationParameters.OfficialChocolateyPublicKey)
if (string.IsNullOrWhiteSpace(token) || !token.is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey))
{
if (!config.AllowUnofficialBuild)
{
Expand Down

0 comments on commit f3140a8

Please sign in to comment.