Skip to content

Commit

Permalink
Tuned up SampleWithLicensing project
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Jan 29, 2018
1 parent dc21d57 commit a6db31c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 73 deletions.
42 changes: 13 additions & 29 deletions cpp/SampleWithLicensing/SampleWithLicensingPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,6 @@ RHINO_PLUG_IN_UPDATE_URL(L"https://github.com/mcneel/rhino-developer-samples");
// The one and only CSampleWithLicensingPlugIn object
static CSampleWithLicensingPlugIn thePlugIn;

/////////////////////////////////////////////////////////////////////////////
// CSampleWithLicensingPlugIn licensing info

// When prompted for a license, the use interface will use this text
// mask to assist the user in entering the correct code.
static wchar_t* g_text_mask = L"AAAAAAAA-AAA-AAA";

// The UUID used by this plug0in to request a license.
// {FBDC82F8-578C-4DD7-827C-51B8C3DA7BD1}
static const GUID g_license_id =
{ 0xfbdc82f8, 0x578c, 0x4dd7,{ 0x82, 0x7c, 0x51, 0xb8, 0xc3, 0xda, 0x7b, 0xd1 } };

// Our plug-in's license capabilities
static CRhinoPlugIn::license_capabilities g_capabilities = (CRhinoPlugIn::license_capabilities)
(
CRhinoPlugIn::license_capabilities::can_be_evaluated
| CRhinoPlugIn::license_capabilities::can_be_purchased
| CRhinoPlugIn::license_capabilities::can_be_specified
// This sample current does not support Rhino accounts.
//| CRhinoPlugIn::license_capabilities::supports_rhino_accounts
);


/////////////////////////////////////////////////////////////////////////////
// CSampleWithLicensingPlugIn definition

Expand All @@ -77,6 +54,18 @@ CSampleWithLicensingPlugIn& SampleWithLicensingPlugIn()
CSampleWithLicensingPlugIn::CSampleWithLicensingPlugIn()
{
m_plugin_version = RhinoPlugInVersion();

// When prompted for a license, the use interface will use this text
// mask to assist the user in entering the correct code.
m_text_mask = L">S\\AMP\\LE-AAAAAAAAAA";

// Our plug-in's license capabilities
m_capabilities = (CRhinoPlugIn::license_capabilities)
(
CRhinoPlugIn::license_capabilities::can_be_evaluated |
CRhinoPlugIn::license_capabilities::can_be_purchased |
CRhinoPlugIn::license_capabilities::can_be_specified
);
}

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -102,7 +91,7 @@ BOOL CSampleWithLicensingPlugIn::OnLoadPlugIn()
{
// Before requesting a license, we must inform the license
// manager what we are capable of supporting.
SetLicenseCapabilities(g_text_mask, g_capabilities, g_license_id);
SetLicenseCapabilities(m_text_mask, m_capabilities, PlugInID());

// Ask Rhino to get a product license for us.
bool rc = GetLicense();
Expand All @@ -116,8 +105,3 @@ BOOL CSampleWithLicensingPlugIn::OnLoadPlugIn()
void CSampleWithLicensingPlugIn::OnUnloadPlugIn()
{
}

CRhinoPlugIn::plugin_load_time CSampleWithLicensingPlugIn::PlugInLoadTime()
{
return plugin_load_time::load_plugin_at_startup;
}
18 changes: 7 additions & 11 deletions cpp/SampleWithLicensing/SampleWithLicensingPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ class CSampleWithLicensingPlugIn : public CRhinoUtilityPlugIn
~CSampleWithLicensingPlugIn() = default;

// Required overrides
const wchar_t* PlugInName() const;
const wchar_t* PlugInVersion() const;
GUID PlugInID() const;
BOOL OnLoadPlugIn();
void OnUnloadPlugIn();
plugin_load_time PlugInLoadTime();
const wchar_t* PlugInName() const override;
const wchar_t* PlugInVersion() const override;
GUID PlugInID() const override;
BOOL OnLoadPlugIn() override;
void OnUnloadPlugIn() override;

private:
ON_wString m_plugin_version;

// TODO: Add additional class information here
ON_wString m_text_mask;
CRhinoPlugIn::license_capabilities m_capabilities;
};

CSampleWithLicensingPlugIn& SampleWithLicensingPlugIn();



61 changes: 28 additions & 33 deletions cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,54 @@ class CSampleWithLicensingValidator : public CRhinoLicenseValidator
CSampleWithLicensingValidator();
~CSampleWithLicensingValidator() = default;

// Returns the 'build' type of this plug-in
// Returns the build type of this plug-in
CRhinoLicenseValidator::product_build_type ProductBuildType() override;

// This member is obsolete.
CRhinoLicenseValidator::result ValidateProductKey(const wchar_t* product_key) override;

// This member is called by Rhino, from CRhinoPlugIn::GetLicense(), when it
// needs your plug-in to validate your product key or license.
// Called by Rhino when it needs your plug-in to validate your product key or license.
CRhinoLicenseValidator::result VerifyLicenseKey(
const wchar_t* licenseKey,
const wchar_t* validationCode,
const double validationCodeInstalledDate,
bool gracePeriodExpired
) override;

// Called by Rhino, from CRhinoPlugIn::GetLicense(), after a call to VerifyLicenseKey that
// sets m_requires_previous_version_license_verification to true.
// Called by Rhino after a call to VerifyLicenseKey that sets
// CRhinoLicenseValidator::m_requires_previous_version_license_verification to true.
bool VerifyPreviousVersionLicense(
const wchar_t* licenseKey,
const wchar_t* previousVersionLicenseKey
) override;

// When Rhino Accounts gets a new lease, this function is called.
// Called by Rhino when Rhino Accounts gets a new lease, this function is called.
void OnLeaseChanged(CRhinoLeaseChangedEventArgs&) override;

// This member is obsolete.
CRhinoLicenseValidator::result ValidateProductKey(const wchar_t* product_key) override;

private:
bool ValidateSampleLicenseKey(const wchar_t* licenseKey);
};

// The one and only CSampleWithLicensingValidator object
static class CSampleWithLicensingValidator theSampleWithLicensingValidator;

// Class constructor
// Constructor
CSampleWithLicensingValidator::CSampleWithLicensingValidator()
{
m_date_to_expire = 0.0;
m_license_count = 1;
// This sample does not support Rhino accounts.
m_requires_online_validation = false;
// This sample does not require a previous license.
m_requires_previous_version_license_verification = false;
}

// Return the 'build' type of this plug-in
// Returns the build type of this plug-in
CRhinoLicenseValidator::product_build_type CSampleWithLicensingValidator::ProductBuildType()
{
return CRhinoLicenseValidator::release_build;
}

// This member is obsolete.
CRhinoLicenseValidator::result CSampleWithLicensingValidator::ValidateProductKey(const wchar_t* product_key)
{
return CRhinoLicenseValidator::result::error_show_message;
}

// This member is called by Rhino, from CRhinoPlugIn::GetLicense(), when it
// needs your plug-in to validate your product key or license.
CRhinoLicenseValidator::result CSampleWithLicensingValidator::VerifyLicenseKey(
Expand All @@ -87,24 +84,17 @@ CRhinoLicenseValidator::result CSampleWithLicensingValidator::VerifyLicenseKey(
CString license_key(licenseKey);
CString validation_code(validationCode);

// This sample current does not support Rhino accounts.
m_requires_online_validation = false;

m_requires_previous_version_license_verification = false;
bool bEvaluation = false;

// Verify license key (if provided)
// Verify license key
if (license_key.IsEmpty())
{
license_key = "evaluate-111-222";
}
else if (license_key.Left(8).CompareNoCase(L"EVALUATE-") == 0)
{
license_key = L"SAMPLE-EVALUATION";
bEvaluation = true;
}
else if (license_key.Left(8).CompareNoCase(L"UPGRADE*-") == 0)
else if (license_key.Left(8).CompareNoCase(L"EVALUATION") == 0)
{
m_requires_previous_version_license_verification = true;
bEvaluation = true;
}
else if (!ValidateSampleLicenseKey(licenseKey))
{
Expand Down Expand Up @@ -172,12 +162,12 @@ bool CSampleWithLicensingValidator::VerifyPreviousVersionLicense(
const wchar_t* previousVersionLicenseKey
)
{
CString sLicense(licenseKey);
CString sPrevVersionLicense(previousVersionLicenseKey);
CString license_key(licenseKey);
CString previous_version_license(previousVersionLicenseKey);

if (sLicense.IsEmpty())
if (license_key.IsEmpty())
return false;
if (sPrevVersionLicense.IsEmpty())
if (previous_version_license.IsEmpty())
return false;

// For this example, we'll consider any non-empty previous version license to be valid.
Expand All @@ -203,6 +193,12 @@ void CSampleWithLicensingValidator::OnLeaseChanged(CRhinoLeaseChangedEventArgs&
// Verify that pLease->IsExpired() is false
}

// This member is obsolete.
CRhinoLicenseValidator::result CSampleWithLicensingValidator::ValidateProductKey(const wchar_t* product_key)
{
return CRhinoLicenseValidator::result::error_show_message;
}

// Our license key validation code. In this example, we'll accept
// anything but a null or empty string.
bool CSampleWithLicensingValidator::ValidateSampleLicenseKey(const wchar_t* licenseKey)
Expand All @@ -212,7 +208,6 @@ bool CSampleWithLicensingValidator::ValidateSampleLicenseKey(const wchar_t* lice
return true;
}


//
// END SampleWithLicensingValidator license validator
//
Expand Down

0 comments on commit a6db31c

Please sign in to comment.