46 #ifndef WIN32_LEAN_AND_MEAN
47 #define WIN32_LEAN_AND_MEAN
58 #define QUOTESTR(x) #x
59 #define TOSTRING(x) QUOTESTR(x)
63 static const Filename openmaya_filename =
"bin/OpenMaya.so";
65 static const Filename openmaya_filename =
"MacOS/libOpenMaya.dylib";
67 static const Filename openmaya_filename =
"lib/libOpenMaya.so";
72 find_pyzip(
const Filename &maya_location) {
75 Filename dirname(maya_location,
"bin");
77 vector_string results;
79 if (glob.match_files(results, dirname) != 0) {
80 return Filename(dirname, results[0]);
87 const char *ver, *key;
90 struct MayaVerInfo maya_versions[] = {
96 {
"MAYA2008",
"2008"},
97 {
"MAYA2009",
"2009"},
98 {
"MAYA2010",
"2010"},
99 {
"MAYA2011",
"2011"},
100 {
"MAYA2012",
"2012"},
101 {
"MAYA2013",
"2013"},
102 {
"MAYA20135",
"2013.5"},
103 {
"MAYA2014",
"2014"},
104 {
"MAYA2015",
"2015"},
105 {
"MAYA2016",
"2016"},
106 {
"MAYA20165",
"2016.5"},
107 {
"MAYA2017",
"2017"},
108 {
"MAYA2018",
"2018"},
109 {
"MAYA2019",
"2019"},
110 {
"MAYA2020",
"2020"},
115 get_version_number(
const char *ver) {
116 for (
int i = 0; maya_versions[i].ver != 0; ++i) {
117 if (strcmp(maya_versions[i].ver, ver) == 0) {
118 return maya_versions[i].key;
126 get_maya_location(
const char *ver,
string &loc) {
128 const char *developer;
131 for (
int dev=0; dev<3; dev++) {
133 case 0: developer=
"Alias|Wavefront";
break;
134 case 1: developer=
"Alias";
break;
135 case 2: developer=
"Autodesk";
break;
137 sprintf(fullkey,
"SOFTWARE\\%s\\Maya\\%s\\Setup\\InstallPath", developer, ver);
138 for (
int hive=0; hive<2; hive++) {
140 res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | (hive ? 256:0), &hkey);
141 if (res == ERROR_SUCCESS) {
144 char result[4096 + 1];
145 res = RegQueryValueEx(hkey,
"MAYA_INSTALL_LOCATION",
nullptr, &dtype, (LPBYTE)result, &size);
146 if ((res == ERROR_SUCCESS)&&(dtype == REG_SZ)) {
156 #elif defined(__APPLE__)
158 get_maya_location(
const char *ver,
string &loc) {
160 sprintf(mpath,
"/Applications/Autodesk/maya%s/Maya.app/Contents", ver);
162 if(stat(mpath, &st) == 0) {
169 get_maya_location(
const char *ver,
string &loc) {
172 sprintf(mpath,
"/usr/autodesk/maya%s-x64", ver);
174 sprintf(mpath,
"/usr/autodesk/maya%s", ver);
177 if(stat(mpath, &st) == 0) {
181 sprintf(mpath,
"/usr/aw/maya%s-x64", ver);
183 sprintf(mpath,
"/usr/aw/maya%s", ver);
185 if(stat(mpath, &st) == 0) {
195 main(
int argc,
char *argv[]) {
200 if (command.empty() || command ==
"unknown" || !command.
exists()) {
219 if (!maya_location.empty()) {
229 const char *key = get_version_number(TOSTRING(MAYAVERSION));
230 if (key ==
nullptr) {
231 cerr <<
"Unknown Maya version: " << TOSTRING(MAYAVERSION) <<
"\n";
234 get_maya_location(key, loc);
236 cerr <<
"Cannot locate " << TOSTRING(MAYAVERSION) <<
": it does not appear to be installed.\n";
241 if (!standard_maya_location.empty()) {
247 #endif // MAYAVERSION
252 if (!maya_location.empty()) {
260 if (maya_location.empty()) {
262 maya_location = standard_maya_location;
264 }
else if (maya_location != standard_maya_location) {
267 Filename openmaya_given = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
268 Filename openmaya_standard = Filename::dso_filename(
Filename(standard_maya_location, openmaya_filename));
270 if (openmaya_given != openmaya_standard) {
274 HashVal hash_given, hash_standard;
275 if (!hash_standard.hash_file(openmaya_standard)) {
279 if (!hash_given.hash_file(openmaya_given)) {
282 maya_location = standard_maya_location;
285 if (hash_standard != hash_given) {
287 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
288 maya_location = standard_maya_location;
294 #else // HAVE_OPENSSL
296 off_t size_given, size_standard;
298 if (size_standard == 0) {
303 if (size_given == 0) {
306 maya_location = standard_maya_location;
309 if (size_standard != size_given) {
311 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
312 maya_location = standard_maya_location;
320 #endif // HAVE_OPENSSL
325 if (maya_location.empty()) {
326 cerr <<
"$MAYA_LOCATION is not set!\n";
330 cerr <<
"MAYA_LOCATION: " << maya_location.
to_os_specific() << endl;
332 cerr <<
"The directory referred to by $MAYA_LOCATION does not exist!\n";
337 Filename openmaya = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
339 cerr <<
"Could not find $MAYA_LOCATION/" << Filename::dso_filename(openmaya_filename).
to_os_specific() <<
"!\n";
345 string putenv_str =
"MAYA_LOCATION=" + maya_location.
to_os_specific();
346 char *putenv_cstr = strdup(putenv_str.c_str());
363 char *putenv_cstr = strdup(putenv_str.c_str());
369 Filename pyzip = find_pyzip(maya_location);
370 if (!pyzip.empty() && pyzip.
exists()) {
375 Filename site_packages(python,
"lib/site-packages");
376 if (site_packages.is_directory()) {
378 putenv_str += site_packages.to_os_specific();
381 char *putenv_cstr = strdup(putenv_str.c_str());
393 const char *path = getenv(
"PATH");
394 if (path ==
nullptr) {
398 char *putenv_cstr = strdup(putenv_str.c_str());
405 const char *path = getenv(
"DYLD_LIBRARY_PATH");
406 if (path ==
nullptr) {
410 string putenv_str =
"DYLD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
411 char *putenv_cstr = strdup(putenv_str.c_str());
418 const char *path = getenv(
"DYLD_FALLBACK_FRAMEWORK_PATH");
419 if (path ==
nullptr) {
423 string putenv_str =
"DYLD_FALLBACK_FRAMEWORK_PATH=" + fw_dir.
to_os_specific() + sep + path;
424 char *putenv_cstr = strdup(putenv_str.c_str());
428 #elif !defined(_WIN32)
431 const char *path = getenv(
"LD_LIBRARY_PATH");
432 if (path ==
nullptr) {
436 string putenv_str =
"LD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
437 char *putenv_cstr = strdup(putenv_str.c_str());
446 putenv((
char *)
"PANDA_INCOMPATIBLE_PYTHON=1");
453 char *command_line = strdup(GetCommandLine());
454 STARTUPINFO startup_info;
455 PROCESS_INFORMATION process_info;
456 GetStartupInfo(&startup_info);
457 BOOL result = CreateProcess(os_command.c_str(),
459 nullptr,
nullptr,
true, 0,
464 WaitForSingleObject(process_info.hProcess, INFINITE);
467 if (GetExitCodeProcess(process_info.hProcess, &exit_code)) {
468 if (exit_code != 0) {
469 cerr <<
"Program exited with status " << exit_code <<
"\n";
473 CloseHandle(process_info.hProcess);
474 CloseHandle(process_info.hThread);
477 cerr <<
"Couldn't execute " << command <<
": " << GetLastError() <<
"\n";
481 execvp(os_command.c_str(), argv);