1616#include < cmath>
1717#include < sys/types.h>
1818#include < sys/stat.h>
19+ #include < pwd.h>
1920#if defined (WIN32) || defined (_WIN32) || defined (__WIN32)
2021#define OSWIN
2122#ifndef NOMINMAX
@@ -63,7 +64,7 @@ namespace imgui_addons
6364 scaleFactor = 1 .0f ;
6465
6566 #ifdef OSWIN
66- current_path = " ./ " ;
67+ initCurrentPathWindows () ;
6768 #else
6869 initCurrentPath ();
6970 #endif
@@ -160,6 +161,7 @@ namespace imgui_addons
160161 if (current_path.empty ())
161162 {
162163 #ifdef OSWIN
164+ initCurrentPathWindows ();
163165 show_error |= !(loadWindowsDrives ());
164166 #else
165167 initCurrentPath ();
@@ -884,7 +886,8 @@ namespace imgui_addons
884886 {
885887 current_dirlist.clear ();
886888 #ifdef OSWIN
887- current_path = pathdir = " ./" ;
889+ initCurrentPathWindows ();
890+ pathdir = current_path;
888891 #else
889892 initCurrentPath ();
890893 pathdir = current_path;
@@ -1244,8 +1247,7 @@ namespace imgui_addons
12441247
12451248 // Windows Exclusive function
12461249 #ifdef OSWIN
1247- bool ImGuiFileBrowser::loadWindowsDrives ()
1248- {
1250+ bool ImGuiFileBrowser::loadWindowsDrives (){
12491251 DWORD len = GetLogicalDriveStringsA (0 ,nullptr );
12501252 char * drives = new char [len];
12511253 if (!GetLogicalDriveStringsA (len,drives))
@@ -1269,6 +1271,20 @@ namespace imgui_addons
12691271 delete[] drives;
12701272 return true ;
12711273 }
1274+
1275+ void ImGuiFileBrowser::initCurrentPathWindows (){
1276+ wchar_t my_documents[1024 ];
1277+ HRESULT result = SHGetFolderPath (NULL , CSIDL_MYDOCUMENTS, NULL , SHGFP_TYPE_CURRENT, my_documents);
1278+
1279+ if (SUCCEEDED (result)){
1280+ char str[1024 ];
1281+ wcstombs (str, my_documents, 1023 );
1282+ current_path = std::string (str);
1283+ parsePathTabs (current_path);
1284+ }else {
1285+ current_path = " ./" ;
1286+ }
1287+ }
12721288 #endif
12731289
12741290 // Unix only
@@ -1287,7 +1303,11 @@ namespace imgui_addons
12871303 if (path_max_def)
12881304 buffer = new char [PATH_MAX];
12891305
1290- char * real_path = realpath (" ./" , buffer);
1306+ // char* real_path = realpath("./", buffer);
1307+
1308+ struct passwd *pw = getpwuid (getuid ());
1309+ char *real_path = pw->pw_dir ;
1310+
12911311 if (real_path == nullptr )
12921312 {
12931313 current_path = " /" ;
0 commit comments