From de2b7519ff2ab90dc8b9109736f9dc6d4f2bbf71 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 8 Jul 2009 10:57:16 +0000 Subject: [PATCH] More linux work: store downloaded panda in ~/.panda3d/ instead of /Users/drose/p3ddir --- direct/src/plugin/find_root_dir.cxx | 32 ++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/direct/src/plugin/find_root_dir.cxx b/direct/src/plugin/find_root_dir.cxx index b158f0bb99..5e978d5126 100755 --- a/direct/src/plugin/find_root_dir.cxx +++ b/direct/src/plugin/find_root_dir.cxx @@ -17,6 +17,12 @@ #ifdef _WIN32 #include #include +#else +#include +#include +#include +#include +#include #endif //////////////////////////////////////////////////////////////////// @@ -58,12 +64,28 @@ find_root_dir() { } } - // Couldn't find a directory. Bail. - return "."; - #else // _WIN32 - // TODO. - return "/Users/drose/p3ddir"; + // e.g., /home//.panda3d + + string root; + const char* uname = getlogin(); + if (uname == NULL) uname = getenv("USER"); + + const passwd* pwdata = getpwnam(uname); + if (pwdata == NULL) { + root = getenv("HOME"); + } else { + root = pwdata->pw_dir; + } + + root += "/.panda3d"; + if (mkdir(root.c_str(), 0700) == 0 || errno == EEXIST) { + return root; + } #endif + + // Couldn't find a directory. Bail. + return "."; } +