38 #include "dtoolbase.h" 40 #include "globPattern.h" 41 #include "dSearchPath.h" 42 #include "executionEnvironment.h" 47 #define WIN32_LEAN_AND_MEAN 57 #define QUOTESTR(x) #x 58 #define TOSTRING(x) QUOTESTR(x) 62 static const Filename openmaya_filename =
"bin/OpenMaya.so";
64 static const Filename openmaya_filename =
"MacOS/libOpenMaya.dylib";
66 static const Filename openmaya_filename =
"lib/libOpenMaya.so";
71 find_pyzip(
const Filename &maya_location) {
74 Filename dirname(maya_location,
"bin");
76 vector_string results;
78 if (glob.match_files(results, dirname) != 0) {
79 return Filename(dirname, results[0]);
86 const char *ver, *key;
95 {
"MAYA2008",
"2008"},
96 {
"MAYA2009",
"2009"},
97 {
"MAYA2010",
"2010"},
98 {
"MAYA2011",
"2011"},
99 {
"MAYA2012",
"2012"},
100 {
"MAYA2013",
"2013"},
101 {
"MAYA20135",
"2013.5"},
102 {
"MAYA2014",
"2014"},
103 {
"MAYA2015",
"2015"},
104 {
"MAYA2016",
"2016"},
105 {
"MAYA20165",
"2016.5"},
110 get_version_number(
const char *ver) {
111 for (
int i = 0; maya_versions[i].ver != 0; ++i) {
112 if (strcmp(maya_versions[i].ver, ver) == 0) {
113 return maya_versions[i].key;
121 get_maya_location(
const char *ver,
string &loc) {
123 const char *developer;
126 for (
int dev=0; dev<3; dev++) {
128 case 0: developer=
"Alias|Wavefront";
break;
129 case 1: developer=
"Alias";
break;
130 case 2: developer=
"Autodesk";
break;
132 sprintf(fullkey,
"SOFTWARE\\%s\\Maya\\%s\\Setup\\InstallPath", developer, ver);
133 for (
int hive=0; hive<2; hive++) {
135 res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | (hive ? 256:0), &hkey);
136 if (res == ERROR_SUCCESS) {
139 char result[4096 + 1];
140 res = RegQueryValueEx(hkey,
"MAYA_INSTALL_LOCATION", NULL, &dtype, (LPBYTE)result, &size);
141 if ((res == ERROR_SUCCESS)&&(dtype == REG_SZ)) {
151 #elif defined(__APPLE__) 153 get_maya_location(
const char *ver,
string &loc) {
155 sprintf(mpath,
"/Applications/Autodesk/maya%s/Maya.app/Contents", ver);
157 if(stat(mpath, &st) == 0) {
164 get_maya_location(
const char *ver,
string &loc) {
167 sprintf(mpath,
"/usr/autodesk/maya%s-x64", ver);
169 sprintf(mpath,
"/usr/autodesk/maya%s", ver);
172 if(stat(mpath, &st) == 0) {
176 sprintf(mpath,
"/usr/aw/maya%s-x64", ver);
178 sprintf(mpath,
"/usr/aw/maya%s", ver);
180 if(stat(mpath, &st) == 0) {
190 main(
int argc,
char *argv[]) {
223 if (!maya_location.empty()) {
234 const char *key = get_version_number(TOSTRING(MAYAVERSION));
236 cerr <<
"Unknown Maya version: " << TOSTRING(MAYAVERSION) <<
"\n";
239 get_maya_location(key, loc);
241 cerr <<
"Cannot locate " << TOSTRING(MAYAVERSION) <<
": it does not appear to be installed.\n";
246 if (!standard_maya_location.empty()) {
252 #endif // MAYAVERSION 257 if (!maya_location.empty()) {
261 maya_location.make_canonical();
265 if (maya_location.empty()) {
267 maya_location = standard_maya_location;
269 }
else if (maya_location != standard_maya_location) {
272 Filename openmaya_given = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
273 Filename openmaya_standard = Filename::dso_filename(
Filename(standard_maya_location, openmaya_filename));
275 if (openmaya_given != openmaya_standard) {
279 HashVal hash_given, hash_standard;
280 if (!hash_standard.hash_file(openmaya_standard)) {
284 if (!hash_given.hash_file(openmaya_given)) {
287 maya_location = standard_maya_location;
290 if (hash_standard != hash_given) {
292 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
293 maya_location = standard_maya_location;
299 #else // HAVE_OPENSSL 301 off_t size_given, size_standard;
303 if (size_standard == 0) {
308 if (size_given == 0) {
311 maya_location = standard_maya_location;
314 if (size_standard != size_given) {
316 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
317 maya_location = standard_maya_location;
325 #endif // HAVE_OPENSSL 330 if (maya_location.empty()) {
331 cerr <<
"$MAYA_LOCATION is not set!\n";
335 cerr <<
"MAYA_LOCATION: " << maya_location.
to_os_specific() << endl;
337 cerr <<
"The directory referred to by $MAYA_LOCATION does not exist!\n";
342 Filename openmaya = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
344 cerr <<
"Could not find $MAYA_LOCATION/" << Filename::dso_filename(openmaya_filename).
to_os_specific() <<
"!\n";
350 string putenv_str =
"MAYA_LOCATION=" + maya_location.
to_os_specific();
351 char *putenv_cstr = strdup(putenv_str.c_str());
368 char *putenv_cstr = strdup(putenv_str.c_str());
374 Filename pyzip = find_pyzip(maya_location);
375 if (!pyzip.empty() && pyzip.
exists()) {
380 Filename site_packages(python,
"lib/site-packages");
386 char *putenv_cstr = strdup(putenv_str.c_str());
398 const char *path = getenv(
"PATH");
403 char *putenv_cstr = strdup(putenv_str.c_str());
410 const char *path = getenv(
"DYLD_LIBRARY_PATH");
415 string putenv_str =
"DYLD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
416 char *putenv_cstr = strdup(putenv_str.c_str());
423 const char *path = getenv(
"DYLD_FALLBACK_FRAMEWORK_PATH");
428 string putenv_str =
"DYLD_FALLBACK_FRAMEWORK_PATH=" + fw_dir.
to_os_specific() + sep + path;
429 char *putenv_cstr = strdup(putenv_str.c_str());
433 #elif !defined(_WIN32) 436 const char *path = getenv(
"LD_LIBRARY_PATH");
441 string putenv_str =
"LD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
442 char *putenv_cstr = strdup(putenv_str.c_str());
451 putenv((
char *)
"PANDA_INCOMPATIBLE_PYTHON=1");
458 char *command_line = strdup(GetCommandLine());
459 STARTUPINFO startup_info;
460 PROCESS_INFORMATION process_info;
461 GetStartupInfo(&startup_info);
462 BOOL result = CreateProcess(os_command.c_str(),
469 WaitForSingleObject(process_info.hProcess, INFINITE);
472 if (GetExitCodeProcess(process_info.hProcess, &exit_code)) {
473 if (exit_code != 0) {
474 cerr <<
"Program exited with status " << exit_code <<
"\n";
478 CloseHandle(process_info.hProcess);
479 CloseHandle(process_info.hThread);
482 cerr <<
"Couldn't execute " << command <<
": " << GetLastError() <<
"\n";
486 execvp(os_command.c_str(), argv);
void set_extension(const string &s)
Replaces the file extension.
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
streamsize get_file_size() const
Returns the size of the file in bytes, or 0 if there is an error.
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer...
static Filename expand_from(const string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e...
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
string get_extension() const
Returns the file extension.
void append_path(const string &path, const string &separator=string())
Adds all of the directories listed in the search path to the end of the search list.
bool resolve_filename(const DSearchPath &searchpath, const string &default_extension=string())
Searches the given search path for the filename.
The name of a file, such as a texture file or an Egg file.
string to_os_long_name() const
This is the opposite of to_os_short_name(): it returns the "long name" of the filename, if the filename exists.
static string get_environment_variable(const string &var)
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
bool is_regular_file() const
Returns true if the filename exists and is the name of a regular file (i.e.
bool is_directory() const
Returns true if the filename exists and is a directory name, false otherwise.
This class stores a list of directories that can be searched, in order, to locate a particular file...
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).