Mercurial > hg > orthanc-wsi
comparison Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 5:77b76c1a213f
check the version of the Orthanc core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Oct 2016 13:34:49 +0200 |
parents | dc730d11b101 |
children | d10ff48e47ff |
comparison
equal
deleted
inserted
replaced
4:e49aaf9127ca | 5:77b76c1a213f |
---|---|
904 else | 904 else |
905 { | 905 { |
906 throw PluginException(error); | 906 throw PluginException(error); |
907 } | 907 } |
908 } | 908 } |
909 | |
910 | |
911 static void ReportIncompatibleVersion(OrthancPluginContext* context, | |
912 unsigned int major, | |
913 unsigned int minor, | |
914 unsigned int revision) | |
915 { | |
916 char buf[128]; | |
917 sprintf(buf, "Your version of the Orthanc core (%s) is too old to run this plugin (%d.%d.%d is required)", | |
918 context->orthancVersion, major, minor, revision); | |
919 OrthancPluginLogError(context, buf); | |
920 } | |
921 | |
922 | |
923 bool CheckMinimalOrthancVersion(OrthancPluginContext* context, | |
924 unsigned int major, | |
925 unsigned int minor, | |
926 unsigned int revision) | |
927 { | |
928 if (context == NULL) | |
929 { | |
930 OrthancPluginLogError(context, "Bad Orthanc context in the plugin"); | |
931 return false; | |
932 } | |
933 | |
934 if (!strcmp(context->orthancVersion, "mainline")) | |
935 { | |
936 // Assume compatibility with the mainline | |
937 return true; | |
938 } | |
939 | |
940 // Parse the version of the Orthanc core | |
941 int aa, bb, cc; | |
942 if ( | |
943 #ifdef _MSC_VER | |
944 sscanf_s | |
945 #else | |
946 sscanf | |
947 #endif | |
948 (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || | |
949 aa < 0 || | |
950 bb < 0 || | |
951 cc < 0) | |
952 { | |
953 throw false; | |
954 } | |
955 | |
956 unsigned int a = static_cast<unsigned int>(aa); | |
957 unsigned int b = static_cast<unsigned int>(bb); | |
958 unsigned int c = static_cast<unsigned int>(cc); | |
959 | |
960 // Check the major version number | |
961 | |
962 if (a > major) | |
963 { | |
964 return true; | |
965 } | |
966 | |
967 if (a < major) | |
968 { | |
969 ReportIncompatibleVersion(context, major, minor, revision); | |
970 return false; | |
971 } | |
972 | |
973 | |
974 // Check the minor version number | |
975 assert(a == major); | |
976 | |
977 if (b > minor) | |
978 { | |
979 return true; | |
980 } | |
981 | |
982 if (b < minor) | |
983 { | |
984 ReportIncompatibleVersion(context, major, minor, revision); | |
985 return false; | |
986 } | |
987 | |
988 // Check the patch level version number | |
989 assert(a == major && b == minor); | |
990 | |
991 if (c >= revision) | |
992 { | |
993 return true; | |
994 } | |
995 else | |
996 { | |
997 ReportIncompatibleVersion(context, major, minor, revision); | |
998 return false; | |
999 } | |
1000 } | |
909 } | 1001 } |
910 | 1002 |