Added similar python plugin improvements for Windows
parent
d161aa6490
commit
5e151f3bac
|
@ -1,4 +1,5 @@
|
|||
#include <mitsuba/core/fresolver.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
# include <windows.h>
|
||||
|
@ -47,9 +48,10 @@ FileResolver::FileResolver() {
|
|||
|
||||
// There is an error if and only if the function returns 0
|
||||
if (nSize != 0) {
|
||||
prependPath(fs::path(lpFilename).parent_path());
|
||||
}
|
||||
else {
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
# include <dlfcn.h>
|
||||
#elif defined(__OSX__)
|
||||
# include <mach-o/dyld.h>
|
||||
#elif defined(__WINDOWS__)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace mitsuba;
|
||||
|
@ -71,6 +73,25 @@ void initializeFramework() {
|
|||
if (boost::ends_with(imageName, "mitsuba.so"))
|
||||
basePath = fs::path(imageName).parent_path().parent_path().parent_path();
|
||||
}
|
||||
#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
|
||||
|
||||
if (!basePath.empty())
|
||||
|
|
Loading…
Reference in New Issue