// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 // Check the version of a third-party product against a database of // supported versions. // // Returns: // // 1 - The specified version of the product is supported. // 0 - The specified version of the product is not supported. // -1 - An error occurred. // // $product - user-friendly name of third-party product // // $version - version of the product to be checked // // $db - path to a text file containing a database of supported versions // of the product. Each line of the file is of the form: // // mayaVersion: start end build // // where 'start' is the start of a range of supported versions, // 'end' is the end of the range, and 'build' is the version we // use when building the plugin which handles that range of // versions. // // Each of 'start', 'end' and 'build' may contain a '/' followed by // arbitrary text. The text is ignored by this procedure but will // be passed to $cmpProc if present. This text is often used to // indicate the corresponding versions of related SDKs. For // example Shave's support for the Arnold renderer uses the mtoa // plugin version as the the 'start', 'end' and 'build' values, // then includes their corresponding Arnold SDK versions after the // '/'. E.g: // // 2018: 3.1.0.0/5.2.0.0 3.1.9.9/5.2.9.9 3.1.0.0/5.2.0.0 // // The text after the '/' must not contain any whitespace. // // $cmpProc - name of a global MEL procedure which takes two version strings // and compares them, returning -1 if the first version is earlier // than the second, 1 if the first version is later than the // second, or 0 if the versions are the same. // // If the versions in $db include a '/' then it and any text which // follows it (up to the next whitespace) will be included in the // strings passed to $cmpProc, so the procedure must be capable // of dealing with the additional text. // // $error - array to receive the error/warning message if the version is // not supported, or if an error occurs. In the case of the version // not being supported, the message will include a list of // supported versions. If the versions in $db contain '/' followed // by optional text only the portion before the '/' will be // included in the message. // global proc int shaveCheckVersion(string $product, string $version, string $db, string $cmpProc, string $error[]) { global string $gShaveMayaVersionStr; clear $error; string $result; string $shaveVersion = `shaveInfo -v`; // Let's see if we can read the database. // int $fid = `fopen $db "r"`; if ($fid == 0) { $error[0] = "Shave and a Haircut cannot read '" + $db + "'."; $error[1] = "Please reinstall Shave and a Haircut for Maya " + $gShaveMayaVersionStr + "."; $error[2] = "If the problem persists, contact shave-haircut-support@epicgames.com."; return -1; } int $lineNumber = 0; string $supportedVersions = ""; string $minVersions[]; string $maxVersions[]; string $buildVersions[]; clear $minVersions; clear $maxVersions; clear $buildVersions; // Search for entries for this version of Maya. // string $key = $gShaveMayaVersionStr + ":"; while (!`feof $fid`) { string $line = strip(`fgetline $fid`); $lineNumber++; if (startsWith($line, $key)) { string $range = strip(substring($line, size($key)+1, size($line))); string $parts[]; tokenize($range, $parts); if (size($parts) != 3) { warning("Shave: invalid syntax in line " + $lineNumber + " of " + $db); } else { $minVersions[size($minVersions)] = $parts[0]; $maxVersions[size($maxVersions)] = $parts[1]; $buildVersions[size($buildVersions)] = $parts[2]; } } } fclose $fid; if (size($minVersions) == 0) { $error[0] = "Shave " + $shaveVersion + " does not support " + $product + " in Maya " + $gShaveMayaVersionStr + "."; $error[1] = "Please contact shave-haircut-support@epicgames.com to find out if or when such support will be available."; } else { // Check whether any of the entries includes $version. // int $i; for ($i = 0; $i < size($minVersions); $i++) { if ((eval($cmpProc + " \"" + $version + "\" \"" + $minVersions[$i] + "\"") >=0) && (eval($cmpProc + " \"" + $version + "\" \"" + $maxVersions[$i] + "\"") <=0)) { return 1; } } // $version was not found. Return an error message listing the // supported versions. // $error[0] = "Shave " + $shaveVersion + " does not support " + $product + " version " + $version + " in Maya " + $gShaveMayaVersionStr + "."; string $versionList; for ($i = 0; $i < size($minVersions); $i++) { if ($i > 0) { $versionList += ","; } // Strip any trailing /text from version strings. // string $minVersion = match("^[^/]*", $minVersions[$i]); string $maxVersion = match("^[^/]*", $maxVersions[$i]); if ($minVersion == $maxVersion) { $versionList += " " + $minVersion; } else { $versionList += " " + $minVersion + " to " + $maxVersion; } } $error[1] = "Supported versions are:" + $versionList; } return 0; }