From a6db31c492c9da60d15f52f79cc6dac517f16eb3 Mon Sep 17 00:00:00 2001 From: Dale Fugier Date: Mon, 29 Jan 2018 13:49:19 -0800 Subject: [PATCH] Tuned up SampleWithLicensing project --- .../SampleWithLicensingPlugIn.cpp | 42 ++++--------- .../SampleWithLicensingPlugIn.h | 18 +++--- .../SampleWithLicensingValidator.cpp | 61 +++++++++---------- 3 files changed, 48 insertions(+), 73 deletions(-) diff --git a/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.cpp b/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.cpp index 925ddfae..0441f14c 100644 --- a/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.cpp +++ b/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.cpp @@ -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 @@ -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 + ); } ///////////////////////////////////////////////////////////////////////////// @@ -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(); @@ -116,8 +105,3 @@ BOOL CSampleWithLicensingPlugIn::OnLoadPlugIn() void CSampleWithLicensingPlugIn::OnUnloadPlugIn() { } - -CRhinoPlugIn::plugin_load_time CSampleWithLicensingPlugIn::PlugInLoadTime() -{ - return plugin_load_time::load_plugin_at_startup; -} diff --git a/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.h b/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.h index c440d920..0d70b075 100644 --- a/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.h +++ b/cpp/SampleWithLicensing/SampleWithLicensingPlugIn.h @@ -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(); - - - diff --git a/cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp b/cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp index 312a588a..a8546331 100644 --- a/cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp +++ b/cpp/SampleWithLicensing/SampleWithLicensingValidator.cpp @@ -14,14 +14,10 @@ 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, @@ -29,16 +25,19 @@ class CSampleWithLicensingValidator : public CRhinoLicenseValidator 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); }; @@ -46,25 +45,23 @@ class CSampleWithLicensingValidator : public CRhinoLicenseValidator // 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( @@ -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)) { @@ -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. @@ -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) @@ -212,7 +208,6 @@ bool CSampleWithLicensingValidator::ValidateSampleLicenseKey(const wchar_t* lice return true; } - // // END SampleWithLicensingValidator license validator //