Skip to content

Commit

Permalink
Merge pull request #8 from bwrsandman/linux_default_path
Browse files Browse the repository at this point in the history
linux: use realpath to get current path and split path correctly
  • Loading branch information
gallickgunner authored Feb 12, 2020
2 parents 7307a37 + 7bee8d0 commit 1b28525
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions FileBrowser/ImGuiFileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,29 @@ namespace imgui_addons
#ifdef OSWIN
current_path = "./";
#else
current_path = "/";
current_dirlist.push_back("/");
char* real_path = realpath("./", nullptr);
if (real_path == nullptr)
{
current_path = "/";
current_dirlist.push_back("/");
}
else
{
current_path = real_path;
current_path += "/";
if (real_path[0] == '/')
{
current_dirlist.push_back("/");
real_path++;
}
for (char* slash = strchr(real_path, '/');
slash != nullptr;
real_path = slash + 1, slash = strchr(real_path, '/'))
{
current_dirlist.push_back(std::string(real_path, slash));
}
current_dirlist.push_back(real_path);
}
#endif
}

Expand Down Expand Up @@ -729,7 +750,7 @@ namespace imgui_addons
char* char_arr = new char[len];
std::wcsrtombs(char_arr, &wchar_arr, len, &state);

auto ret_val = std::string(char_arr);
std::string ret_val(char_arr);

delete[] char_arr;
return ret_val;
Expand Down

0 comments on commit 1b28525

Please sign in to comment.