mirror of https://github.com/AxioDL/metaforce.git
Add hecl::PathRelative()
This commit is contained in:
parent
8c3a7da616
commit
89f216d94f
|
@ -151,7 +151,7 @@ int main(int argc, const char** argv)
|
||||||
info.cwd += _S('/');
|
info.cwd += _S('/');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argv[0][0] != _S('/') && argv[0][0] != _S('\\'))
|
if (hecl::PathRelative(argv[0]))
|
||||||
ExeDir = hecl::SystemString(cwdbuf) + _S('/');
|
ExeDir = hecl::SystemString(cwdbuf) + _S('/');
|
||||||
hecl::SystemString Argv0(argv[0]);
|
hecl::SystemString Argv0(argv[0]);
|
||||||
hecl::SystemString::size_type lastIdx = Argv0.find_last_of(_S("/\\"));
|
hecl::SystemString::size_type lastIdx = Argv0.find_last_of(_S("/\\"));
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0cc794f49d8884c30ba43b195aecdfed14062a53
|
Subproject commit 8bcac27c10064e36be2b351f9f764412fceaa1ff
|
|
@ -383,9 +383,9 @@ public:
|
||||||
if (strcmp(readBuf, "OK"))
|
if (strcmp(readBuf, "OK"))
|
||||||
BlenderLog.report(logvisor::Fatal, "unable get AABB: %s", readBuf);
|
BlenderLog.report(logvisor::Fatal, "unable get AABB: %s", readBuf);
|
||||||
|
|
||||||
Vector3f min(*m_parent);
|
Vector3f minPt(*m_parent);
|
||||||
Vector3f max(*m_parent);
|
Vector3f maxPt(*m_parent);
|
||||||
return std::make_pair(min.val, max.val);
|
return std::make_pair(minPt.val, maxPt.val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Vector types with integrated stream reading constructor */
|
/* Vector types with integrated stream reading constructor */
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <Shlwapi.h>
|
||||||
#include "winsupport.hpp"
|
#include "winsupport.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -457,6 +458,17 @@ static inline bool CheckFreeSpace(const SystemChar* path, size_t reqSz)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool PathRelative(const SystemChar* path)
|
||||||
|
{
|
||||||
|
if (!path || !path[0])
|
||||||
|
return false;
|
||||||
|
#if _WIN32
|
||||||
|
return PathIsRelative(path);
|
||||||
|
#else
|
||||||
|
return path[0] != '/';
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline int ConsoleWidth()
|
static inline int ConsoleWidth()
|
||||||
{
|
{
|
||||||
int retval = 80;
|
int retval = 80;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <Shlwapi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
|
@ -1378,17 +1377,6 @@ std::vector<BlenderConnection::DataStream::Light> BlenderConnection::DataStream:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool PathRelative(const SystemString& path)
|
|
||||||
{
|
|
||||||
if (path.empty())
|
|
||||||
return false;
|
|
||||||
#if _WIN32
|
|
||||||
return PathIsRelative(path.c_str());
|
|
||||||
#else
|
|
||||||
return path[0] != '/';
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void BlenderConnection::DataStream::compileGuiFrame(const std::string& pathOut, int version)
|
void BlenderConnection::DataStream::compileGuiFrame(const std::string& pathOut, int version)
|
||||||
{
|
{
|
||||||
if (m_parent->m_loadedType != BlendType::Frame)
|
if (m_parent->m_loadedType != BlendType::Frame)
|
||||||
|
@ -1414,7 +1402,7 @@ void BlenderConnection::DataStream::compileGuiFrame(const std::string& pathOut,
|
||||||
SystemStringView absolute(readStr);
|
SystemStringView absolute(readStr);
|
||||||
auto& proj = m_parent->m_loadedBlend.getProject();
|
auto& proj = m_parent->m_loadedBlend.getProject();
|
||||||
SystemString relative;
|
SystemString relative;
|
||||||
if (PathRelative(absolute.sys_str()))
|
if (PathRelative(absolute.c_str()))
|
||||||
relative = absolute.sys_str();
|
relative = absolute.sys_str();
|
||||||
else
|
else
|
||||||
relative = proj.getProjectRootPath().getProjectRelativeFromAbsolute(absolute);
|
relative = proj.getProjectRootPath().getProjectRelativeFromAbsolute(absolute);
|
||||||
|
|
|
@ -43,6 +43,13 @@ void ClientProcess::BufferTransaction::run(BlenderToken& btok)
|
||||||
void ClientProcess::CookTransaction::run(BlenderToken& btok)
|
void ClientProcess::CookTransaction::run(BlenderToken& btok)
|
||||||
{
|
{
|
||||||
m_dataSpec->setThreadProject();
|
m_dataSpec->setThreadProject();
|
||||||
|
if (m_path.getAuxInfo().empty())
|
||||||
|
LogModule.report(logvisor::Info, _S("Cooking %s"),
|
||||||
|
m_path.getRelativePath().c_str());
|
||||||
|
else
|
||||||
|
LogModule.report(logvisor::Info, _S("Cooking %s|%s"),
|
||||||
|
m_path.getRelativePath().c_str(),
|
||||||
|
m_path.getAuxInfo().c_str());
|
||||||
m_returnResult = m_parent.syncCook(m_path, m_dataSpec, btok);
|
m_returnResult = m_parent.syncCook(m_path, m_dataSpec, btok);
|
||||||
m_complete = true;
|
m_complete = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -761,6 +761,117 @@ const SystemChar* GetTmpDir()
|
||||||
int RunProcess(const SystemChar* path, const SystemChar* const args[])
|
int RunProcess(const SystemChar* path, const SystemChar* const args[])
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
|
||||||
|
HANDLE consoleOutReadTmp, consoleOutWrite, consoleErrWrite, consoleOutRead;
|
||||||
|
if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 0))
|
||||||
|
{
|
||||||
|
LogModule.report(logvisor::Fatal, "Error with CreatePipe");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DuplicateHandle(GetCurrentProcess(), consoleOutWrite,
|
||||||
|
GetCurrentProcess(), &consoleErrWrite, 0,
|
||||||
|
TRUE,DUPLICATE_SAME_ACCESS))
|
||||||
|
{
|
||||||
|
LogModule.report(logvisor::Fatal, "Error with DuplicateHandle");
|
||||||
|
CloseHandle(consoleOutReadTmp);
|
||||||
|
CloseHandle(consoleOutWrite);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DuplicateHandle(GetCurrentProcess(), consoleOutReadTmp,
|
||||||
|
GetCurrentProcess(),
|
||||||
|
&consoleOutRead, // Address of new handle.
|
||||||
|
0, FALSE, // Make it uninheritable.
|
||||||
|
DUPLICATE_SAME_ACCESS))
|
||||||
|
{
|
||||||
|
LogModule.report(logvisor::Fatal, "Error with DupliateHandle");
|
||||||
|
CloseHandle(consoleOutReadTmp);
|
||||||
|
CloseHandle(consoleOutWrite);
|
||||||
|
CloseHandle(consoleErrWrite);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(consoleOutReadTmp);
|
||||||
|
|
||||||
|
hecl::SystemString cmdLine;
|
||||||
|
const SystemChar* const* arg = &args[1];
|
||||||
|
while (*arg)
|
||||||
|
{
|
||||||
|
cmdLine += _S(" \"");
|
||||||
|
cmdLine += *arg++;
|
||||||
|
cmdLine += _S('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
||||||
|
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
|
&sattrs, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
sinfo.dwFlags = STARTF_USESTDHANDLES;
|
||||||
|
sinfo.hStdInput = nulHandle;
|
||||||
|
sinfo.hStdError = consoleErrWrite;
|
||||||
|
sinfo.hStdOutput = consoleOutWrite;
|
||||||
|
|
||||||
|
PROCESS_INFORMATION pinfo = {};
|
||||||
|
if (!CreateProcessW(path, (LPWSTR)cmdLine.c_str(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &sinfo, &pinfo))
|
||||||
|
{
|
||||||
|
LPWSTR messageBuffer = nullptr;
|
||||||
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
|
||||||
|
LogModule.report(logvisor::Error, L"unable to launch process from %s: %s", path, messageBuffer);
|
||||||
|
LocalFree(messageBuffer);
|
||||||
|
|
||||||
|
CloseHandle(nulHandle);
|
||||||
|
CloseHandle(consoleErrWrite);
|
||||||
|
CloseHandle(consoleOutWrite);
|
||||||
|
CloseHandle(consoleOutRead);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(nulHandle);
|
||||||
|
CloseHandle(consoleErrWrite);
|
||||||
|
CloseHandle(consoleOutWrite);
|
||||||
|
|
||||||
|
bool consoleThreadRunning = true;
|
||||||
|
auto consoleThread = std::thread([=, &consoleThreadRunning]()
|
||||||
|
{
|
||||||
|
CHAR lpBuffer[256];
|
||||||
|
DWORD nBytesRead;
|
||||||
|
DWORD nCharsWritten;
|
||||||
|
|
||||||
|
while (consoleThreadRunning)
|
||||||
|
{
|
||||||
|
if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer),
|
||||||
|
&nBytesRead, NULL) || !nBytesRead)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
if (err == ERROR_BROKEN_PIPE)
|
||||||
|
break; // pipe done - normal exit path.
|
||||||
|
else
|
||||||
|
LogModule.report(logvisor::Error, "Error with ReadFile: %08X", err); // Something bad happened.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display the character read on the screen.
|
||||||
|
auto lk = logvisor::LockLog();
|
||||||
|
if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer,
|
||||||
|
nBytesRead, &nCharsWritten, NULL))
|
||||||
|
LogModule.report(logvisor::Error, "Error with WriteConsole: %08X", GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(consoleOutRead);
|
||||||
|
});
|
||||||
|
|
||||||
|
WaitForSingleObject(pinfo.hProcess, INFINITE);
|
||||||
|
DWORD ret;
|
||||||
|
if (!GetExitCodeProcess(pinfo.hProcess, &ret))
|
||||||
|
ret = -1;
|
||||||
|
consoleThreadRunning = false;
|
||||||
|
if (consoleThread.joinable())
|
||||||
|
consoleThread.join();
|
||||||
|
|
||||||
|
CloseHandle(pinfo.hProcess);
|
||||||
|
CloseHandle(pinfo.hThread);
|
||||||
|
|
||||||
|
return ret;
|
||||||
#else
|
#else
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (!pid)
|
if (!pid)
|
||||||
|
|
Loading…
Reference in New Issue