public static IContainer RegisterAutoFac(string chocolateyGuiAssemblySimpleName, string licensedGuiAssemblyLocation) { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(System.Reflection.Assembly.GetCallingAssembly()); var license = License.validate_license(); if (license.IsValid) { if (File.Exists(licensedGuiAssemblyLocation)) { var licensedGuiAssembly = AssemblyResolution.resolve_or_load_assembly( chocolateyGuiAssemblySimpleName, chocolatey.infrastructure.app.ApplicationParameters.OfficialChocolateyPublicKey, licensedGuiAssemblyLocation); if (licensedGuiAssembly != null) { license.AssemblyLoaded = true; license.Assembly = licensedGuiAssembly; license.Version = VersionInformation.get_current_informational_version(licensedGuiAssembly); builder.RegisterAssemblyModules(licensedGuiAssembly.UnderlyingType); } } } return(builder.Build()); }
public static ChocolateyLicense validate_license() { var license = LicenseValidation.validate(); if (license.is_licensed_version()) { try { var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.OfficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation); #if !FORCE_CHOCOLATEY_OFFICIAL_KEY if (licensedAssembly == null) { licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.UnofficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation); } #endif if (licensedAssembly == null) { throw new ApplicationException("Unable to load licensed assembly."); } license.AssemblyLoaded = true; license.Assembly = licensedAssembly; license.Version = VersionInformation.get_current_informational_version(licensedAssembly); Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true); SimpleInjectorContainer.add_component_registry_class(licensedComponent); } catch (Exception ex) { "chocolatey".Log().Error( @"Error when attempting to load chocolatey licensed assembly. Ensure that chocolatey.licensed.dll exists at '{0}'. The error message itself may be helpful:{1} {2}".format_with( ApplicationParameters.LicensedAssemblyLocation, Environment.NewLine, ex.Message )); "chocolatey".Log().Warn(ChocolateyLoggers.Important, @" Install the Chocolatey Licensed Extension package with `choco install chocolatey.extension` to remove this license warning. TRIALS: If you have a trial license, you cannot use the above command as is and be successful. You need to download nupkgs from the links in the trial email as your license will not be registered on the licensed repository. Please reference https://chocolatey.org/docs/installation-licensed#how-do-i-install-the-trial-edition for specific instructions."); } } return(license); }
private static void add_assembly_resolver() { _handler = (sender, args) => { var requestedAssembly = new AssemblyName(args.Name); // There are things that are ILMerged into Chocolatey. Anything with // the right public key except licensed should use the choco/chocolatey assembly if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey) #if !FORCE_CHOCOLATEY_OFFICIAL_KEY || requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey) #endif ) && !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName) && !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) { return(typeof(ConsoleApplication).Assembly); } try { if ((requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey) #if !FORCE_CHOCOLATEY_OFFICIAL_KEY || requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.UnofficialChocolateyPublicKey) #endif ) && requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)) { "chocolatey".Log().Debug(() => "Resolving reference to chocolatey.licensed..."); return(AssemblyResolution.resolve_or_load_assembly( ApplicationParameters.LicensedChocolateyAssemblySimpleName, requestedAssembly.get_public_key_token(), ApplicationParameters.LicensedAssemblyLocation).UnderlyingType); } } catch (Exception ex) { "chocolatey".Log().Warn("Unable to load chocolatey.licensed assembly. {0}".format_with(ex.Message)); } return(null); }; AppDomain.CurrentDomain.AssemblyResolve += _handler; }
public App() { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var requestedAssembly = new AssemblyName(args.Name); #if FORCE_CHOCOLATEY_OFFICIAL_KEY var chocolateyGuiPublicKey = Bootstrapper.OfficialChocolateyPublicKey; #else var chocolateyGuiPublicKey = Bootstrapper.UnofficialChocolateyPublicKey; #endif try { if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey) && requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonAssemblySimpleName)) { return(AssemblyResolution.resolve_or_load_assembly( Bootstrapper.ChocolateyGuiCommonAssemblySimpleName, requestedAssembly.get_public_key_token(), Bootstrapper.ChocolateyGuiCommonAssemblyLocation).UnderlyingType); } if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey) && requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName)) { return(AssemblyResolution.resolve_or_load_assembly( Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName, requestedAssembly.get_public_key_token(), Bootstrapper.ChocolateyGuiCommonWindowsAssemblyLocation).UnderlyingType); } } catch (Exception ex) { var errorMessage = string.Format("Unable to load Chocolatey GUI assembly. {0}", ex.Message); MessageBox.Show(errorMessage); throw new ApplicationException(errorMessage); } return(null); }; InitializeComponent(); }
private static void AddAssemblyResolver() { _handler = (sender, args) => { var requestedAssembly = new AssemblyName(args.Name); #if FORCE_CHOCOLATEY_OFFICIAL_KEY var chocolateyGuiPublicKey = Bootstrapper.OfficialChocolateyPublicKey; #else var chocolateyGuiPublicKey = Bootstrapper.UnofficialChocolateyPublicKey; #endif try { if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey) && requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonAssemblySimpleName)) { return(AssemblyResolution.resolve_or_load_assembly( Bootstrapper.ChocolateyGuiCommonAssemblySimpleName, requestedAssembly.get_public_key_token(), Bootstrapper.ChocolateyGuiCommonAssemblyLocation).UnderlyingType); } if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyGuiPublicKey) && requestedAssembly.Name.is_equal_to(Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName)) { return(AssemblyResolution.resolve_or_load_assembly( Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName, requestedAssembly.get_public_key_token(), Bootstrapper.ChocolateyGuiCommonWindowsAssemblyLocation).UnderlyingType); } } catch (Exception ex) { Bootstrapper.Logger.Warning("Unable to load Chocolatey GUI assembly. {0}".format_with(ex.Message)); } return(null); }; AppDomain.CurrentDomain.AssemblyResolve += _handler; }
public static ChocolateyLicense validate_license() { var license = LicenseValidation.validate(); if (license.is_licensed_version()) { try { #if FORCE_CHOCOLATEY_OFFICIAL_KEY var chocolateyPublicKey = ApplicationParameters.OfficialChocolateyPublicKey; #else var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey; #endif var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, chocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation); if (licensedAssembly == null) { throw new ApplicationException("Unable to load licensed assembly."); } license.AssemblyLoaded = true; license.Assembly = licensedAssembly; license.Version = VersionInformation.get_current_informational_version(licensedAssembly); // The licensed assembly is installed, check its supported Chocolatey versions and/or the assembly // version so we can attempt to determine whether it's compatible with this version of Chocolatey. var minimumChocolateyVersionString = VersionInformation.get_minimum_chocolatey_version(licensedAssembly); "chocolatey".Log().Debug("Minimum Chocolatey Version: '{0}'".format_with(minimumChocolateyVersionString)); var currentChocolateyVersionString = VersionInformation.get_current_assembly_version(); "chocolatey".Log().Debug("Current Chocolatey Version: '{0}'".format_with(currentChocolateyVersionString)); var currentChocolateyLicensedVersionString = VersionInformation.get_current_assembly_version(licensedAssembly); "chocolatey".Log().Debug("Current Chocolatey Licensed Version: '{0}'".format_with(currentChocolateyLicensedVersionString)); var minimumChocolateyVersion = new Version(minimumChocolateyVersionString); var currentChocolateyVersion = new Version(currentChocolateyVersionString); var currentChocolateyLicensedVersion = new Version(currentChocolateyLicensedVersionString); license.IsCompatible = true; if (currentChocolateyVersion < minimumChocolateyVersion || (minimumChocolateyVersion == Version.Parse("1.0.0") && currentChocolateyLicensedVersion.Major < 4)) { license.IsCompatible = false; } Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true); SimpleInjectorContainer.add_component_registry_class(licensedComponent); } catch (Exception ex) { "chocolatey".Log().Error( @"A valid Chocolatey license was found, but the chocolatey.licensed.dll assembly could not be loaded: {0} Ensure that the chocolatey.licensed.dll exists at the following path: '{1}'".format_with(ex.Message, ApplicationParameters.LicensedAssemblyLocation)); "chocolatey".Log().Warn( ChocolateyLoggers.Important, @"To resolve this, install the Chocolatey Licensed Extension package with `choco install chocolatey.extension`"); } } return(license); }