diff --git a/src/filesys.h b/src/filesys.h index c22e89b3e..bfb340d85 100644 --- a/src/filesys.h +++ b/src/filesys.h @@ -26,9 +26,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifdef _WIN32 // WINDOWS #define DIR_DELIM "\\" +#define DIR_DELIM_CHAR '\\' #define FILESYS_CASE_INSENSITIVE 1 #else // POSIX #define DIR_DELIM "/" +#define DIR_DELIM_CHAR '/' #define FILESYS_CASE_INSENSITIVE 0 #endif diff --git a/src/porting.cpp b/src/porting.cpp index 812f148da..1834fb7c8 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -35,12 +35,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #endif - +#if defined(__hpux) + #define _PSTAT64 + #include +#endif #if !defined(_WIN32) && !defined(__APPLE__) && \ !defined(__ANDROID__) && !defined(SERVER) #define XORG_USED #endif - #ifdef XORG_USED #include #include @@ -99,39 +101,29 @@ void signal_handler_init(void) #else // _WIN32 #include - BOOL WINAPI event_handler(DWORD sig) - { - switch(sig) - { - case CTRL_C_EVENT: - case CTRL_CLOSE_EVENT: - case CTRL_LOGOFF_EVENT: - case CTRL_SHUTDOWN_EVENT: - - if(g_killed == false) - { - dstream<= len) + return false; -#else // RUN_IN_PLACE + return true; +} - /* - Use platform-specific paths otherwise - */ - infostream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<= buflen, "Overlow"); + FATAL_ERROR_IF(!getCurrentExecPath(buf, sizeof(buf)), + "Failed to get current executable path"); pathRemoveFile(buf, '\\'); // Use ".\bin\.." path_share = std::string(buf) + "\\.."; // Use "C:\Documents and Settings\user\Application Data\" - len = GetEnvironmentVariable("APPDATA", buf, buflen); - FATAL_ERROR_IF(len >= buflen, "Overlow"); + DWORD len = GetEnvironmentVariable("APPDATA", buf, sizeof(buf)); + FATAL_ERROR_IF(len == 0 || len > sizeof(buf), "Failed to get APPDATA"); + path_user = std::string(buf) + DIR_DELIM + lowercase(PROJECT_NAME); + return true; +} - /* - Linux - */ - #elif defined(linux) || defined(__linux) - // Get path to executable - std::string bindir = ""; - { - char buf[BUFSIZ]; - memset(buf, 0, BUFSIZ); - if (readlink("/proc/self/exe", buf, BUFSIZ-1) == -1) { - errorstream << "Unable to read bindir "<< std::endl; -#ifndef __ANDROID__ - FATAL_ERROR("Unable to read bindir"); +//// Linux +#elif defined(linux) || defined(__linux) + +bool setSystemPaths() +{ + char buf[BUFSIZ]; + + if (!getCurrentExecPath(buf, sizeof(buf))) { +#ifdef __ANDROID__ + errorstream << "Unable to read bindir "<< std::endl; +#else + FATAL_ERROR("Unable to read bindir"); #endif - } else { - pathRemoveFile(buf, '/'); - bindir = buf; - } + return false; } + pathRemoveFile(buf, '/'); + std::string bindir(buf); + // Find share directory from these. // It is identified by containing the subdirectory "builtin". std::list trylist; std::string static_sharedir = STATIC_SHAREDIR; - if(static_sharedir != "" && static_sharedir != ".") + if (static_sharedir != "" && static_sharedir != ".") trylist.push_back(static_sharedir); - trylist.push_back( - bindir + DIR_DELIM + ".." + DIR_DELIM + "share" + DIR_DELIM + lowercase(PROJECT_NAME)); - trylist.push_back(bindir + DIR_DELIM + ".."); + + trylist.push_back(bindir + DIR_DELIM ".." DIR_DELIM "share" + DIR_DELIM + lowercase(PROJECT_NAME)); + trylist.push_back(bindir + DIR_DELIM ".."); + #ifdef __ANDROID__ trylist.push_back(path_user); #endif - for(std::list::const_iterator i = trylist.begin(); - i != trylist.end(); i++) - { + for (std::list::const_iterator + i = trylist.begin(); i != trylist.end(); i++) { const std::string &trypath = *i; - if(!fs::PathExists(trypath) || !fs::PathExists(trypath + DIR_DELIM + "builtin")){ - dstream<<"WARNING: system-wide share not found at \"" - <= 1 && buf[cwdlen - 1] == DIR_DELIM_CHAR) { + cwdlen--; + buf[cwdlen] = '\0'; + } + + if (cwdlen >= 4 && !strcmp(buf + cwdlen - 4, DIR_DELIM "bin")) + pathRemoveFile(buf, DIR_DELIM_CHAR); + + std::string execpath(buf); + + path_share = execpath; + path_user = execpath; + } + +#else + infostream << "Using system-wide paths (NOT RUN_IN_PLACE)" << std::endl; + + if (!setSystemPaths()) + errorstream << "Failed to get one or more system-wide path" << std::endl; + +#endif + + infostream << "Detected share path: " << path_share << std::endl; + infostream << "Detected user path: " << path_user << std::endl; +} + + + void setXorgClassHint(const video::SExposedVideoData &video_data, const std::string &name) { @@ -568,8 +661,20 @@ void setXorgClassHint(const video::SExposedVideoData &video_data, #endif } + +//// +//// Video/Display Information (Client-only) +//// + #ifndef SERVER +static irr::IrrlichtDevice *device; + +void initIrrlicht(irr::IrrlichtDevice *device_) +{ + device = device_; +} + v2u32 getWindowSize() { return device->getVideoDriver()->getScreenSize(); @@ -641,9 +746,8 @@ const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type) return driver_names[type]; } - -#ifndef __ANDROID__ -#ifdef XORG_USED +# ifndef __ANDROID__ +# ifdef XORG_USED static float calcDisplayDensity() { @@ -679,12 +783,12 @@ float getDisplayDensity() } -#else +# else // XORG_USED float getDisplayDensity() { return g_settings->getFloat("screen_dpi")/96.0; } -#endif +# endif // XORG_USED v2u32 getDisplaySize() { @@ -695,8 +799,8 @@ v2u32 getDisplaySize() return deskres; } -#endif -#endif +# endif // __ANDROID__ +#endif // SERVER } //namespace porting diff --git a/src/porting.h b/src/porting.h index ddb56cf7d..add3926ea 100644 --- a/src/porting.h +++ b/src/porting.h @@ -377,7 +377,7 @@ const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type); const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type); #endif -inline const char * getPlatformName() +inline const char *getPlatformName() { return #if defined(ANDROID) @@ -401,8 +401,12 @@ inline const char * getPlatformName() "AIX" #elif defined(__hpux) "HP-UX" -#elif defined(__sun) && defined(__SVR4) - "Solaris" +#elif defined(__sun) || defined(sun) + #if defined(__SVR4) + "Solaris" + #else + "SunOS" + #endif #elif defined(__CYGWIN__) "Cygwin" #elif defined(__unix__) || defined(__unix)