Working in c#. I would like to check the user license from within the plugin derived class - if they don’t have a license I want to unload the plugin/prevent them from using the commands.
What’s the best way to do this? License check is fine - it’s the “preventing them from using the plugin” that I’m trying to work out the best solution for.
You could load the plugin at startup, and override the OnLoad method. You can choose to return an error in that method if you do not want the plugin to load or return success if all goes to plan.
You don’t even need to force loading at start up. The return code from OnLoad will be respected. If you return ErrorShowDialog or ErrorNoDialog, then your plug-in will not be executed.
To elaborate on what Luis and Steve mentioned, you can do something like this:
/// <summary>
/// Is called when the plug-in is being loaded.
/// </summary>
/// If a load error is returned and this string is set. This string is the
/// error message that will be reported back to the user.
/// <returns>An appropriate load return code.</returns>
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
if (!HaveValidLicense())
{
errorMessage = string.Format("Unable to load {0} plug-in. No valid license found.", this.Name);
return LoadReturnCode.ErrorShowDialog;
}
return LoadReturnCode.Success;
}
Or, you could popup your own UI, giving the customer directions on how to purchase a license, and just return LoadReturnCode.ErrorNoDialog.
public class Plugin : Rhino.PlugIns.RenderPlugIn,…
and when loading the plugin, if some predefined MDL folder does not exist, user can chose to avoid loading the plugin.
We then return ErrorShowDialog code:
Now, the plugin is not loaded but the Iray renderer is still listed in the list of viewport renderers.
When user chose Iray, the viewport freezes, when user chose wireframe, Rhino crashes.
Is there something to do in addition to returning ErrorShowDialog ?
To unregister the viewport renderer? @andy?
@nvp, I have created a pull request that should fix this problem. As part of the non-loading all custom render content and other extensions registered by the plug-in are also unloaded.
With the next WIP please test this and report whether it works or not. (It does in my own tests )