moved FileResolver initialization from libpython to libcore -- yet to be tested on Windows and Linux
parent
e97081619b
commit
a8f3d76b78
|
@ -1,11 +1,20 @@
|
|||
#include <mitsuba/core/fresolver.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#if defined(__LINUX__)
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include <dlfcn.h>
|
||||
#elif defined(__OSX__)
|
||||
# include <mach-o/dyld.h>
|
||||
#elif defined(__WINDOWS__)
|
||||
# include <windows.h>
|
||||
# include <vector>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
MTS_NAMESPACE_BEGIN
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
|
@ -16,8 +25,6 @@ void dummyModuleFunc() {}
|
|||
#endif
|
||||
|
||||
FileResolver::FileResolver() {
|
||||
m_paths.push_back(fs::current_path());
|
||||
|
||||
/* Try to detect the base path of the Mitsuba installation */
|
||||
fs::path basePath;
|
||||
#if defined(__LINUX__)
|
||||
|
@ -45,6 +52,8 @@ FileResolver::FileResolver() {
|
|||
}
|
||||
}
|
||||
MTS_AUTORELEASE_END()
|
||||
if (basePath.empty())
|
||||
Log(EError, "Could not detect the executable path!");
|
||||
#elif defined(__WINDOWS__)
|
||||
std::vector<WCHAR> lpFilename(MAX_PATH);
|
||||
|
||||
|
@ -67,17 +76,13 @@ FileResolver::FileResolver() {
|
|||
}
|
||||
|
||||
// There is an error if and only if the function returns 0
|
||||
if (nSize != 0) {
|
||||
fs::path path(lpFilename);
|
||||
if (boost::to_lower_copy(path.filename().string()).find("python") == std::string::npos)
|
||||
prependPath(path.parent_path());
|
||||
} else {
|
||||
const std::string msg(lastErrorText());
|
||||
Log(EError, "Could not detect the executable path! (%s)", msg.c_str());
|
||||
}
|
||||
if (nSize != 0)
|
||||
basePath = fs::path(lpFilename);
|
||||
else
|
||||
Log(EError, "Could not detect the executable path! (%s)", lastErrorText().c_str());
|
||||
#endif
|
||||
Thread::getThread()->getFileResolver()->prependPath(basePath);
|
||||
|
||||
m_paths.push_back(fs::canonical(basePath));
|
||||
m_paths.push_back(fs::current_path());
|
||||
}
|
||||
|
||||
FileResolver *FileResolver::clone() const {
|
||||
|
|
|
@ -21,17 +21,6 @@
|
|||
#include <mitsuba/render/scene.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#if defined(__LINUX__)
|
||||
# if !defined(_GNU_SOURCE)
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include <dlfcn.h>
|
||||
#elif defined(__OSX__)
|
||||
# include <mach-o/dyld.h>
|
||||
#elif defined(__WINDOWS__)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace mitsuba;
|
||||
|
||||
void initializeFramework() {
|
||||
|
@ -48,31 +37,6 @@ void initializeFramework() {
|
|||
Scheduler::staticInitialization();
|
||||
SHVector::staticInitialization();
|
||||
SceneHandler::staticInitialization();
|
||||
|
||||
|
||||
#if defined(__LINUX__)
|
||||
#elif defined(__OSX__)
|
||||
#elif defined(__WINDOWS__)
|
||||
HMODULE hm;
|
||||
std::vector<WCHAR> lpFilename(MAX_PATH);
|
||||
if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &initializeFramework, &hm)) {
|
||||
std::vector<WCHAR> lpFilename(MAX_PATH);
|
||||
|
||||
// Try to get the path with the default MAX_PATH length (260 chars)
|
||||
DWORD nSize = GetModuleFileNameW(hm, &lpFilename[0], MAX_PATH);
|
||||
|
||||
// Adjust the buffer size in case if was too short
|
||||
while (nSize == lpFilename.size()) {
|
||||
lpFilename.resize(nSize * 2);
|
||||
nSize = GetModuleFileNameW(hm, &lpFilename[0], nSize);
|
||||
}
|
||||
|
||||
if (nSize)
|
||||
basePath = fs::path(lpFilename).parent_path().parent_path().parent_path();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void shutdownFramework() {
|
||||
|
|
Loading…
Reference in New Issue