Skip to content

Commit

Permalink
(GH-606) Check for License in User Profile
Browse files Browse the repository at this point in the history
Check first the user profile for the license. If one is found there,
use it instead of a system set license file.
  • Loading branch information
ferventcoder committed Feb 12, 2016
1 parent cca5f77 commit 968f130
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class ApplicationParameters
public static readonly string ChocolateyConfigFileResource = @"chocolatey.infrastructure.app.configuration.chocolatey.config";
public static readonly string GlobalConfigFileLocation = _fileSystem.combine_paths(InstallLocation, "config", "chocolatey.config");
public static readonly string LicenseFileLocation = _fileSystem.combine_paths(InstallLocation, "license", "chocolatey.license.xml");
public static readonly string UserLicenseFileLocation = _fileSystem.combine_paths(System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile, System.Environment.SpecialFolderOption.DoNotVerify), "chocolatey.license.xml");
public static readonly string LicensedAssemblyLocation = _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
public static readonly string LicensedComponentRegistry = @"chocolatey.licensed.infrastructure.app.registration.ContainerBinding";
public static readonly string LicensedConfigurationBuilder = @"chocolatey.licensed.infrastructure.app.builders.ConfigurationBuilder";
Expand Down
12 changes: 11 additions & 1 deletion src/chocolatey/infrastructure/licensing/LicenseValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public static ChocolateyLicense validate()
};

string licenseFile = ApplicationParameters.LicenseFileLocation;
//no file system at this point
var userLicenseFile = ApplicationParameters.UserLicenseFileLocation;
if (File.Exists(userLicenseFile)) licenseFile = userLicenseFile;

//no IFileSystem at this point
if (File.Exists(licenseFile))
{
var license = new LicenseValidator(PUBLIC_KEY, licenseFile);
Expand All @@ -43,6 +46,13 @@ public static ChocolateyLicense validate()
license.AssertValidLicense();
chocolateyLicense.IsValid = true;
}
catch (LicenseFileNotFoundException e)
{
chocolateyLicense.IsValid = false;
chocolateyLicense.InvalidReason = e.Message;
"chocolatey".Log().Error("A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
"A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation)));
}
catch (Exception e)
{
//license may be invalid
Expand Down

0 comments on commit 968f130

Please sign in to comment.