Skip to content

Commit 1b28525

Browse files
Merge pull request #8 from bwrsandman/linux_default_path
linux: use realpath to get current path and split path correctly
2 parents 7307a37 + 7bee8d0 commit 1b28525

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

FileBrowser/ImGuiFileBrowser.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,29 @@ namespace imgui_addons
3434
#ifdef OSWIN
3535
current_path = "./";
3636
#else
37-
current_path = "/";
38-
current_dirlist.push_back("/");
37+
char* real_path = realpath("./", nullptr);
38+
if (real_path == nullptr)
39+
{
40+
current_path = "/";
41+
current_dirlist.push_back("/");
42+
}
43+
else
44+
{
45+
current_path = real_path;
46+
current_path += "/";
47+
if (real_path[0] == '/')
48+
{
49+
current_dirlist.push_back("/");
50+
real_path++;
51+
}
52+
for (char* slash = strchr(real_path, '/');
53+
slash != nullptr;
54+
real_path = slash + 1, slash = strchr(real_path, '/'))
55+
{
56+
current_dirlist.push_back(std::string(real_path, slash));
57+
}
58+
current_dirlist.push_back(real_path);
59+
}
3960
#endif
4061
}
4162

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

732-
auto ret_val = std::string(char_arr);
753+
std::string ret_val(char_arr);
733754

734755
delete[] char_arr;
735756
return ret_val;

0 commit comments

Comments
 (0)