MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / SetCurrentDir

Method SetCurrentDir

ImGuiFileDialog.cpp:2324–2369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2322}
2323
2324void IGFD::FileManager::SetCurrentDir(const std::string& vPath) {
2325 std::string path = vPath;
2326#ifdef _IGFD_WIN_
2327 if (fsRoot == path) path += IGFD::Utils::GetPathSeparator();
2328#endif // _IGFD_WIN_
2329
2330 bool dir_opened = m_FileSystemPtr->IsDirectory(path);
2331 if (!dir_opened) {
2332 path = ".";
2333 dir_opened = m_FileSystemPtr->IsDirectory(path);
2334 }
2335 if (dir_opened) {
2336#ifdef _IGFD_WIN_
2337 DWORD numchar = 0;
2338 std::wstring wpath = IGFD::Utils::UTF8Decode(path);
2339 numchar = GetFullPathNameW(wpath.c_str(), 0, nullptr, nullptr);
2340 std::wstring fpath(numchar, 0);
2341 GetFullPathNameW(wpath.c_str(), numchar, (wchar_t*)fpath.data(), nullptr);
2342 std::string real_path = IGFD::Utils::UTF8Encode(fpath);
2343 while (real_path.back() == '\0') { // for fix issue we can have with std::string concatenation.. if there is a \0 at end
2344 real_path = real_path.substr(0, real_path.size() - 1U);
2345 }
2346 if (!real_path.empty())
2347#elif defined(_IGFD_UNIX_) // _IGFD_UNIX_ is _IGFD_WIN_ or APPLE
2348 char real_path[PATH_MAX];
2349 char* numchar = realpath(path.c_str(), real_path);
2350 if (numchar != nullptr)
2351#endif // _IGFD_WIN_
2352 {
2353 m_CurrentPath = std::move(real_path);
2354 if (m_CurrentPath.size() > 1 && m_CurrentPath[m_CurrentPath.size() - 1] == PATH_SEP) {
2355 m_CurrentPath = m_CurrentPath.substr(0, m_CurrentPath.size() - 1);
2356 }
2357 IGFD::Utils::SetBuffer(inputPathBuffer, MAX_PATH_BUFFER_SIZE, m_CurrentPath);
2358 m_CurrentPathDecomposition = IGFD::Utils::SplitStringToVector(m_CurrentPath, PATH_SEP, false);
2359#ifdef _IGFD_UNIX_ // _IGFD_UNIX_ is _IGFD_WIN_ or APPLE
2360 m_CurrentPathDecomposition.insert(m_CurrentPathDecomposition.begin(), IGFD::Utils::GetPathSeparator());
2361#endif // _IGFD_UNIX_
2362 if (!m_CurrentPathDecomposition.empty()) {
2363#ifdef _IGFD_WIN_
2364 fsRoot = m_CurrentPathDecomposition[0];
2365#endif // _IGFD_WIN_
2366 }
2367 }
2368 }
2369}
2370
2371bool IGFD::FileManager::CreateDir(const std::string& vPath) {
2372 if (!vPath.empty()) {

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.80
emptyMethod · 0.80
beginMethod · 0.80
IsDirectoryMethod · 0.45

Tested by

no test coverage detected