# HG changeset patch # User Sebastien Jodogne # Date 1477481522 -7200 # Node ID d5c29fd74ffa5838e13446986c7bef78af3b9136 # Parent 68510b1c2433956cd3e10caeae5d689de2ebfc30 OrthancPlugins::CheckMinimalOrthancVersion diff -r 68510b1c2433 -r d5c29fd74ffa Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Sat Oct 22 18:22:18 2016 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Oct 26 13:32:02 2016 +0200 @@ -906,5 +906,97 @@ throw PluginException(error); } } + + + static void ReportIncompatibleVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision) + { + char buf[128]; + sprintf(buf, "Your version of the Orthanc core (%s) is too old to run this plugin (%d.%d.%d is required)", + context->orthancVersion, major, minor, revision); + OrthancPluginLogError(context, buf); + } + + + bool CheckMinimalOrthancVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision) + { + if (context == NULL) + { + OrthancPluginLogError(context, "Bad Orthanc context in the plugin"); + return false; + } + + if (!strcmp(context->orthancVersion, "mainline")) + { + // Assume compatibility with the mainline + return true; + } + + // Parse the version of the Orthanc core + int aa, bb, cc; + if ( +#ifdef _MSC_VER + sscanf_s +#else + sscanf +#endif + (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || + aa < 0 || + bb < 0 || + cc < 0) + { + throw false; + } + + unsigned int a = static_cast(aa); + unsigned int b = static_cast(bb); + unsigned int c = static_cast(cc); + + // Check the major version number + + if (a > major) + { + return true; + } + + if (a < major) + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + + + // Check the minor version number + assert(a == major); + + if (b > minor) + { + return true; + } + + if (b < minor) + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + + // Check the patch level version number + assert(a == major && b == minor); + + if (c >= revision) + { + return true; + } + else + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + } } diff -r 68510b1c2433 -r d5c29fd74ffa Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Sat Oct 22 18:22:18 2016 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Oct 26 13:32:02 2016 +0200 @@ -388,6 +388,11 @@ } } + bool CheckMinimalOrthancVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision); + namespace Internals {