mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Various fixes to p3dWrapper
This commit is contained in:
parent
f4a06bca9f
commit
b1866def94
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
/* p3dWrapper is a small wrapper executable that locates a .p3d file
|
/* p3dWrapper is a small wrapper executable that locates a .p3d file
|
||||||
on the PATH that has the same basename as the executable, and runs
|
on the PATH that has the same basename as the executable, and runs
|
||||||
it with panda3d.exe that is also located on the PATH. */
|
it with panda3d(.exe) that is also located on the PATH. */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -28,16 +28,33 @@ const char delims[] = ":";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main (int argc, char* argv[]) {
|
int main (int argc, char* argv[]) {
|
||||||
|
char havep3dfile = 0;
|
||||||
|
char havepanda3d = 0;
|
||||||
char* p3dname = strdup (argv [0]);
|
char* p3dname = strdup (argv [0]);
|
||||||
strcat (p3dname, ".p3d");
|
strcat (p3dname, ".p3d");
|
||||||
|
if (access (p3dname, R_OK) == 0) {
|
||||||
|
havep3dfile = 1;
|
||||||
|
} else {
|
||||||
|
// Make sure that p3dname contains a basename only.
|
||||||
|
int c;
|
||||||
|
for (c = strlen(p3dname) - 1; c >= 0; --c) {
|
||||||
|
if (p3dname[c] == '/' || p3dname[c] == '\\') {
|
||||||
|
p3dname += c + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char* p3dfile = NULL;
|
char* p3dfile = NULL;
|
||||||
char* panda3d = NULL;
|
char* panda3d = NULL;
|
||||||
char* path = getenv ("PATH");
|
char* path = getenv ("PATH");
|
||||||
if (path) {
|
if (path) {
|
||||||
// Locate the .p3d file and panda3d(.exe) on PATH.
|
// Locate the .p3d file and panda3d(.exe) on PATH.
|
||||||
char* pathtok = strtok(path, delims);
|
char* pathtok = NULL;
|
||||||
|
pathtok = strtok (path, delims);
|
||||||
while (pathtok != NULL) {
|
while (pathtok != NULL) {
|
||||||
|
// Check if the p3d file is in this directory.
|
||||||
|
if (!havep3dfile) {
|
||||||
p3dfile = strdup (pathtok);
|
p3dfile = strdup (pathtok);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
strcat (p3dfile, "\\");
|
strcat (p3dfile, "\\");
|
||||||
@ -46,10 +63,11 @@ int main (int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
strcat (p3dfile, p3dname);
|
strcat (p3dfile, p3dname);
|
||||||
if (access (p3dfile, R_OK) == 0) {
|
if (access (p3dfile, R_OK) == 0) {
|
||||||
break;
|
havep3dfile = 1;
|
||||||
} else {
|
|
||||||
p3dfile = NULL;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Check if panda3d(.exe) is in this directory.
|
||||||
|
if (!havepanda3d) {
|
||||||
panda3d = strdup (pathtok);
|
panda3d = strdup (pathtok);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
strcat (panda3d, "\\panda3d.exe");
|
strcat (panda3d, "\\panda3d.exe");
|
||||||
@ -57,17 +75,19 @@ int main (int argc, char* argv[]) {
|
|||||||
strcat (panda3d, "/panda3d");
|
strcat (panda3d, "/panda3d");
|
||||||
#endif
|
#endif
|
||||||
if (access (panda3d, X_OK) == 0) {
|
if (access (panda3d, X_OK) == 0) {
|
||||||
|
havepanda3d = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (havep3dfile && havepanda3d) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
panda3d = NULL;
|
|
||||||
}
|
}
|
||||||
pathtok = strtok(NULL, delims);
|
pathtok = strtok(NULL, delims);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p3dfile == NULL) {
|
if (havep3dfile == 0 || p3dfile == NULL) {
|
||||||
p3dfile = p3dname;
|
p3dfile = p3dname;
|
||||||
}
|
}
|
||||||
if (panda3d == NULL) {
|
if (havepanda3d == 0 || panda3d == NULL) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
panda3d = "panda3d.exe";
|
panda3d = "panda3d.exe";
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user