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"},
109 get_version_number(
const char *ver) {
110 for (
int i = 0; maya_versions[i].ver != 0; ++i) {
111 if (strcmp(maya_versions[i].ver, ver) == 0) {
112 return maya_versions[i].key;
120 get_maya_location(
const char *ver,
string &loc) {
122 const char *developer;
125 for (
int dev=0; dev<3; dev++) {
127 case 0: developer=
"Alias|Wavefront";
break;
128 case 1: developer=
"Alias";
break;
129 case 2: developer=
"Autodesk";
break;
131 sprintf(fullkey,
"SOFTWARE\\%s\\Maya\\%s\\Setup\\InstallPath", developer, ver);
132 for (
int hive=0; hive<2; hive++) {
134 res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | (hive ? 256:0), &hkey);
135 if (res == ERROR_SUCCESS) {
138 char result[4096 + 1];
139 res = RegQueryValueEx(hkey,
"MAYA_INSTALL_LOCATION", NULL, &dtype, (LPBYTE)result, &size);
140 if ((res == ERROR_SUCCESS)&&(dtype == REG_SZ)) {
150 #elif defined(__APPLE__)
152 get_maya_location(
const char *ver,
string &loc) {
154 sprintf(mpath,
"/Applications/Autodesk/maya%s/Maya.app/Contents", ver);
156 if(stat(mpath, &st) == 0) {
163 get_maya_location(
const char *ver,
string &loc) {
166 sprintf(mpath,
"/usr/autodesk/maya%s-x64", ver);
168 sprintf(mpath,
"/usr/autodesk/maya%s", ver);
171 if(stat(mpath, &st) == 0) {
175 sprintf(mpath,
"/usr/aw/maya%s-x64", ver);
177 sprintf(mpath,
"/usr/aw/maya%s", ver);
179 if(stat(mpath, &st) == 0) {
189 main(
int argc,
char *argv[]) {
222 if (!maya_location.empty()) {
233 const char *key = get_version_number(TOSTRING(MAYAVERSION));
235 cerr <<
"Unknown Maya version: " << TOSTRING(MAYAVERSION) <<
"\n";
238 get_maya_location(key, loc);
240 cerr <<
"Cannot locate " << TOSTRING(MAYAVERSION) <<
": it does not appear to be installed.\n";
245 if (!standard_maya_location.empty()) {
251 #endif // MAYAVERSION
256 if (!maya_location.empty()) {
264 if (maya_location.empty()) {
266 maya_location = standard_maya_location;
268 }
else if (maya_location != standard_maya_location) {
271 Filename openmaya_given = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
272 Filename openmaya_standard = Filename::dso_filename(
Filename(standard_maya_location, openmaya_filename));
274 if (openmaya_given != openmaya_standard) {
278 HashVal hash_given, hash_standard;
279 if (!hash_standard.hash_file(openmaya_standard)) {
283 if (!hash_given.hash_file(openmaya_given)) {
286 maya_location = standard_maya_location;
289 if (hash_standard != hash_given) {
291 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
292 maya_location = standard_maya_location;
298 #else // HAVE_OPENSSL
300 off_t size_given, size_standard;
302 if (size_standard == 0) {
307 if (size_given == 0) {
310 maya_location = standard_maya_location;
313 if (size_standard != size_given) {
315 cerr <<
"$MAYA_LOCATION points to wrong version; using standard location instead.\n";
316 maya_location = standard_maya_location;
324 #endif // HAVE_OPENSSL
329 if (maya_location.empty()) {
330 cerr <<
"$MAYA_LOCATION is not set!\n";
334 cerr <<
"MAYA_LOCATION: " << maya_location.
to_os_specific() << endl;
336 cerr <<
"The directory referred to by $MAYA_LOCATION does not exist!\n";
341 Filename openmaya = Filename::dso_filename(
Filename(maya_location, openmaya_filename));
343 cerr <<
"Could not find $MAYA_LOCATION/" << Filename::dso_filename(openmaya_filename).
to_os_specific() <<
"!\n";
349 string putenv_str =
"MAYA_LOCATION=" + maya_location.
to_os_specific();
350 char *putenv_cstr = strdup(putenv_str.c_str());
367 char *putenv_cstr = strdup(putenv_str.c_str());
373 Filename pyzip = find_pyzip(maya_location);
374 if (!pyzip.empty() && pyzip.
exists()) {
379 Filename site_packages(python,
"lib/site-packages");
380 if (site_packages.is_directory()) {
382 putenv_str += site_packages.to_os_specific();
385 char *putenv_cstr = strdup(putenv_str.c_str());
397 const char *path = getenv(
"PATH");
402 char *putenv_cstr = strdup(putenv_str.c_str());
409 const char *path = getenv(
"DYLD_LIBRARY_PATH");
414 string putenv_str =
"DYLD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
415 char *putenv_cstr = strdup(putenv_str.c_str());
422 const char *path = getenv(
"DYLD_FALLBACK_FRAMEWORK_PATH");
427 string putenv_str =
"DYLD_FALLBACK_FRAMEWORK_PATH=" + fw_dir.
to_os_specific() + sep + path;
428 char *putenv_cstr = strdup(putenv_str.c_str());
432 #elif !defined(_WIN32)
435 const char *path = getenv(
"LD_LIBRARY_PATH");
440 string putenv_str =
"LD_LIBRARY_PATH=" + bin.
to_os_specific() + sep + path;
441 char *putenv_cstr = strdup(putenv_str.c_str());
450 putenv((
char *)
"PANDA_INCOMPATIBLE_PYTHON=1");
457 char *command_line = strdup(GetCommandLine());
458 STARTUPINFO startup_info;
459 PROCESS_INFORMATION process_info;
460 GetStartupInfo(&startup_info);
461 BOOL result = CreateProcess(os_command.c_str(),
468 WaitForSingleObject(process_info.hProcess, INFINITE);
471 if (GetExitCodeProcess(process_info.hProcess, &exit_code)) {
472 if (exit_code != 0) {
473 cerr <<
"Program exited with status " << exit_code <<
"\n";
477 CloseHandle(process_info.hProcess);
478 CloseHandle(process_info.hThread);
481 cerr <<
"Couldn't execute " << command <<
": " << GetLastError() <<
"\n";
485 execvp(os_command.c_str(), argv);
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
void set_extension(const string &s)
Replaces the file extension.
bool is_directory() const
Returns true if the filename exists and is a directory name, false otherwise.
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...
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
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...
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.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
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 exists() const
Returns true if the filename exists on the disk, false otherwise.
streamsize get_file_size() const
Returns the size of the file in bytes, or 0 if there is an error.
This class stores a list of directories that can be searched, in order, to locate a particular file...
bool is_regular_file() const
Returns true if the filename exists and is the name of a regular file (i.e.
string get_extension() const
Returns the file extension.
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).