1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// 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 [email protected].";
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 [email protected] 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;
}
|