Determine in code if plugin is installed?

Is it possible to test if MBS is installed? Like

#if CurlsMBS.installed then // use MBS code #else // use other code #end if

I came across https://forum.xojo.com/4398-conditional-compilation/0 so I wonder …

Markus

P.S. If you wonder where that would be useful: think for example sharing code, open-source projects, etc.

You can check if the plugin file exists. It can be done on Windows, not sure about Mac and Linux. Also maybe a pre-build IDE script?

[quote=202956:@Markus Winter]Is it possible to test if MBS is installed? Like

#if CurlsMBS.installed then // use MBS code #else // use other code #end if

I came across https://forum.xojo.com/4398-conditional-compilation/0 so I wonder …

Markus

P.S. If you wonder where that would be useful: think for example sharing code, open-source projects, etc.[/quote]

As Ashot said, you can check the presence of plugin files. It works the same in the three platform. Where it becomes more of an issue is that conditional compilation requires a constant. Then I do not quite see how to implement it in the program. Maybe through an IDE Script that checks for the plugins, and sets the constant before compiling ?

You can’t do this automatically. What I’ve seen others do is create a module with useMBS constant and then leave it up to the user to set it to true.

There are at least a few issues I can think of off the top of my head with such a request

  1. whether the plugin uses the same name from one release to another
    For instance , if in one release it’s CurlMBS and in another its Curl_mbs
    Most authors would not do this but it’s possible and your code would break
    This is however unlikely with most authors

  2. the version of the plugin required (say you have version 10 but the code expects version 15)
    The plugin api doesn’t REQUIRE providing a version number at all - only what SDK it uses

  3. the #if syntax requires a constant or constant expression - no calls to methods, subs etc since this is evaluated at compile time not runtime
    So you could have #if true and false (a constant expression) but not #if CurlsMBS.isPresent :stuck_out_tongue:
    It’d have to be … something else … which could conflict with a method in the plugin etc

  4. we’d have to scan ALL your code to find all the #if’s and see if any of them used whatever special name we came up with to know what to set consts TO
    They’d HAVE to exist somewhere (whether the IDE automagically inserted them or you did)
    You will get compile errors if they dont (so something has to create them somewhere along the line)

For the sake of sharing code (open source, etc.) I believe this is not an issue.
Since you are providing the code, you can just let the developer to decide if he wants to use MBS or not.
After all, is not said that if a developer has MBS plugins he wants to use them in all cases.

If you really want to make the life easier to a developer, just put conditional compilation for MBS and native code and define a constant the developer can set to change the behavior.

Hi.

Is this still the case? I wanted to publish code that uses the MBS plugin if exists but if it doesn’t I want to provide a fallback solution.

In my case I don’t want to run a build step that copies support files if MBS is present, but I’m not sure how to handle that (even if there is a “useMBS” module constant.

See MBS module in our plugins.

So you can write

#if MBS.HasCURLPlugin then MsgBox "CURL Plugin is installed." #endif

And check if a certain MBS Plugin is installed.

[quote=402749:@Christian Schmitz]See MBS module in our plugins.

So you can write

#if MBS.HasCURLPlugin then MsgBox "CURL Plugin is installed." #endif

And check if a certain MBS Plugin is installed.[/quote]

Ah. It’s great that MBS has this. I guess this means the individual plugin has to have the routines, but there isn’t something in Xojo itself that can be used for any other plugin. Ok.

Can this be used in build scripts as well to not include some resources if the plug in is installed?

and check feedback cases: <https://xojo.com/issue/6284> and <https://xojo.com/issue/9018>

Would be great if someone has an hour to add something to preprocessor to check if identifiers exist.
Or if needed, just include condition as text in intermediate representation and later kick the code segment out if conditions turns out false.

Thanks, Christian. I agree wholeheartedly.