46#ifndef WIN32_LEAN_AND_MEAN
47#define WIN32_LEAN_AND_MEAN
59#define TOSTRING(x) QUOTESTR(x)
63find_pyzip(
const Filename &maya_location) {
66 Filename dirname(maya_location,
"bin");
68 vector_string results;
70 if (glob.match_files(results, dirname) != 0) {
71 return Filename(dirname, results[0]);
78 const char *ver, *key;
81struct MayaVerInfo maya_versions[] = {
87 {
"MAYA2008",
"2008"},
88 {
"MAYA2009",
"2009"},
89 {
"MAYA2010",
"2010"},
90 {
"MAYA2011",
"2011"},
91 {
"MAYA2012",
"2012"},
92 {
"MAYA2013",
"2013"},
93 {
"MAYA20135",
"2013.5"},
94 {
"MAYA2014",
"2014"},
95 {
"MAYA2015",
"2015"},
96 {
"MAYA2016",
"2016"},
97 {
"MAYA20165",
"2016.5"},
98 {
"MAYA2017",
"2017"},
99 {
"MAYA2018",
"2018"},
100 {
"MAYA2019",
"2019"},
101 {
"MAYA2020",
"2020"},
102 {
"MAYA2022",
"2022"},
107get_version_number(
const char *ver) {
108 for (
int i = 0; maya_versions[i].ver != 0; ++i) {
109 if (strcmp(maya_versions[i].ver, ver) == 0) {
110 return maya_versions[i].key;
117get_openmaya_filename(
const Filename &maya_location) {
123 Filename bin3_openmaya = Filename::dso_filename(maya_location /
"bin3/OpenMaya.so");
125 return bin3_openmaya;
127 return Filename::dso_filename(maya_location /
"bin/OpenMaya.so");
129 return Filename::dso_filename(maya_location /
"MacOS/libOpenMaya.dylib");
131 return Filename::dso_filename(maya_location /
"lib/libOpenMaya.so");
137get_maya_location(
const char *ver,
string &loc) {
139 const char *developer;
142 for (
int dev=0; dev<3; dev++) {
144 case 0: developer=
"Alias|Wavefront";
break;
145 case 1: developer=
"Alias";
break;
146 case 2: developer=
"Autodesk";
break;
148 sprintf(fullkey,
"SOFTWARE\\%s\\Maya\\%s\\Setup\\InstallPath", developer, ver);
149 for (
int hive=0; hive<2; hive++) {
151 res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | (hive ? 256:0), &hkey);
152 if (res == ERROR_SUCCESS) {
155 char result[4096 + 1];
156 res = RegQueryValueEx(hkey,
"MAYA_INSTALL_LOCATION",
nullptr, &dtype, (LPBYTE)result, &size);
157 if ((res == ERROR_SUCCESS)&&(dtype == REG_SZ)) {
167#elif defined(__APPLE__)
169get_maya_location(
const char *ver,
string &loc) {
171 sprintf(mpath,
"/Applications/Autodesk/maya%s/Maya.app/Contents", ver);
173 if(stat(mpath, &st) == 0) {
180get_maya_location(
const char *ver,
string &loc) {
183 sprintf(mpath,
"/usr/autodesk/maya%s-x64", ver);
185 sprintf(mpath,
"/usr/autodesk/maya%s", ver);
188 if(stat(mpath, &st) == 0) {
192 sprintf(mpath,
"/usr/aw/maya%s-x64", ver);
194 sprintf(mpath,
"/usr/aw/maya%s", ver);
196 if(stat(mpath, &st) == 0) {
206main(
int argc,
char *argv[]) {
211 if (command.empty() || command ==
"unknown" || !command.
exists()) {
230 if (!maya_location.empty()) {
240 const char *key = get_version_number(TOSTRING(MAYAVERSION));
241 if (key ==
nullptr) {
242 cerr <<
"Unknown Maya version: " << TOSTRING(MAYAVERSION) <<
"\n";
245 get_maya_location(key, loc);
247 cerr <<
"Cannot locate " << TOSTRING(MAYAVERSION) <<
": it does not appear to be installed.\n";
252 if (!standard_maya_location.empty()) {
263 if (!maya_location.empty()) {
271 if (maya_location.empty()) {
273 maya_location = standard_maya_location;
275 }
else if (maya_location != standard_maya_location) {
278 Filename openmaya_given = get_openmaya_filename(maya_location);
279 Filename openmaya_standard = get_openmaya_filename(standard_maya_location);
281 if (openmaya_given != openmaya_standard) {
285 HashVal hash_given, hash_standard;
286 if (!hash_standard.hash_file(openmaya_standard)) {
290 if (!hash_given.hash_file(openmaya_given)) {
293 maya_location = standard_maya_location;
296 if (hash_standard != hash_given) {
298 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
299 maya_location = standard_maya_location;
307 off_t size_given, size_standard;
309 if (size_standard == 0) {
314 if (size_given == 0) {
317 maya_location = standard_maya_location;
320 if (size_standard != size_given) {
322 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
323 maya_location = standard_maya_location;
336 if (maya_location.empty()) {
337 cerr <<
"$MAYA_LOCATION is not set!\n";
341 cerr <<
"MAYA_LOCATION: " << maya_location.
to_os_specific() << endl;
343 cerr <<
"The directory referred to by $MAYA_LOCATION does not exist!\n";
348 Filename openmaya = get_openmaya_filename(maya_location);
350 cerr <<
"Could not find OpenMaya library in $MAYA_LOCATION!\n";
356 string putenv_str =
"MAYA_LOCATION=" + maya_location.
to_os_specific();
357 char *putenv_cstr = strdup(putenv_str.c_str());
374 char *putenv_cstr = strdup(putenv_str.c_str());
380 Filename pyzip = find_pyzip(maya_location);
381 if (!pyzip.empty() && pyzip.
exists()) {
386 Filename site_packages(python,
"lib/site-packages");
387 if (site_packages.is_directory()) {
389 putenv_str += site_packages.to_os_specific();
392 char *putenv_cstr = strdup(putenv_str.c_str());
404 const char *path = getenv(
"PATH");
405 if (path ==
nullptr) {
408 string putenv_str =
"PATH=";
420 char *putenv_cstr = strdup(putenv_str.c_str());
427 const char *path = getenv(
"DYLD_LIBRARY_PATH");
428 if (path ==
nullptr) {
432 string putenv_str =
"DYLD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
433 char *putenv_cstr = strdup(putenv_str.c_str());
440 const char *path = getenv(
"DYLD_FALLBACK_FRAMEWORK_PATH");
441 if (path ==
nullptr) {
445 string putenv_str =
"DYLD_FALLBACK_FRAMEWORK_PATH=" + fw_dir.
to_os_specific() + sep + path;
446 char *putenv_cstr = strdup(putenv_str.c_str());
450#elif !defined(_WIN32)
453 const char *path = getenv(
"LD_LIBRARY_PATH");
454 if (path ==
nullptr) {
458 string putenv_str =
"LD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
459 char *putenv_cstr = strdup(putenv_str.c_str());
468 putenv((
char *)
"PANDA_INCOMPATIBLE_PYTHON=1");
475 char *command_line = strdup(GetCommandLine());
476 STARTUPINFO startup_info;
477 PROCESS_INFORMATION process_info;
478 GetStartupInfo(&startup_info);
479 BOOL result = CreateProcess(os_command.c_str(),
481 nullptr,
nullptr,
true, 0,
486 WaitForSingleObject(process_info.hProcess, INFINITE);
489 if (GetExitCodeProcess(process_info.hProcess, &exit_code)) {
490 if (exit_code != 0) {
491 cerr <<
"Program exited with status " << exit_code <<
"\n";
495 CloseHandle(process_info.hProcess);
496 CloseHandle(process_info.hThread);
499 cerr <<
"Couldn't execute " << command <<
": " << GetLastError() <<
"\n";
503 execvp(os_command.c_str(), argv);
This class stores a list of directories that can be searched, in order, to locate a particular file.
void append_path(const std::string &path, const std::string &separator=std::string())
Adds all of the directories listed in the search path to the end of the search list.
get_environment_variable
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
get_binary_name
Returns the name of the binary executable that started this program, if it can be determined.
The name of a file, such as a texture file or an Egg file.
bool is_regular_file() const
Returns true if the filename exists on the physical disk and is the name of a regular file (i....
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
bool resolve_filename(const DSearchPath &searchpath, const std::string &default_extension=std::string())
Searches the given search path for the filename.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
static Filename expand_from(const std::string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e....
void set_basename_wo_extension(const std::string &s)
Replaces the basename part of the filename, without the file extension.
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
void set_extension(const std::string &s)
Replaces the file extension.
bool is_directory() const
Returns true if the filename exists on the physical disk and is a directory name, false otherwise.
std::string to_os_long_name() const
This is the opposite of to_os_short_name(): it returns the "long name" of the filename,...
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
bool exists() const
Returns true if the filename exists on the physical disk, false otherwise.
std::streamsize get_file_size() const
Returns the size of the file in bytes, or 0 if there is an error.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.