2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 18:24:55 +00:00

Windows build fixes

This commit is contained in:
Jack Andersen
2018-05-24 20:34:58 -10:00
parent 85bab33ae3
commit 77f814192e
18 changed files with 81 additions and 84 deletions

View File

@@ -147,6 +147,40 @@ void SanitizePath(std::wstring& path)
path.pop_back();
}
SystemString GetcwdStr()
{
/* http://stackoverflow.com/a/2869667 */
//const size_t ChunkSize=255;
//const int MaxChunks=10240; // 2550 KiBs of current path are more than enough
SystemChar stackBuffer[255]; // Stack buffer for the "normal" case
if (Getcwd(stackBuffer, 255) != nullptr)
return SystemString(stackBuffer);
if (errno != ERANGE)
{
// It's not ERANGE, so we don't know how to handle it
LogModule.report(logvisor::Fatal, "Cannot determine the current path.");
// Of course you may choose a different error reporting method
}
// Ok, the stack buffer isn't long enough; fallback to heap allocation
for (int chunks=2 ; chunks<10240 ; chunks++)
{
// With boost use scoped_ptr; in C++0x, use unique_ptr
// If you want to be less C++ but more efficient you may want to use realloc
std::unique_ptr<SystemChar[]> cwd(new SystemChar[255*chunks]);
if (Getcwd(cwd.get(), 255*chunks) != nullptr)
return SystemString(cwd.get());
if (errno != ERANGE)
{
// It's not ERANGE, so we don't know how to handle it
LogModule.report(logvisor::Fatal, "Cannot determine the current path.");
// Of course you may choose a different error reporting method
}
}
LogModule.report(logvisor::Fatal, "Cannot determine the current path; the path is apparently unreasonably long");
return SystemString();
}
static std::mutex PathsMutex;
static std::unordered_map<std::thread::id, ProjectPath> PathsInProgress;
@@ -270,7 +304,7 @@ hecl::DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode,
else
continue;
m_entries.push_back(std::move(Entry(std::move(fp), d.cFileName, sz, isDir)));
m_entries.emplace_back(fp, d.cFileName, sz, isDir);
} while (FindNextFileW(dir, &d));
break;
case Mode::DirsThenFilesSorted: