00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string>
00024 #include <common/DefinesFile.h>
00025 #include <sys/types.h>
00026 #include <sys/stat.h>
00027
00028 #pragma warning(disable : 4996)
00029
00030 #ifdef WIN32
00031 #include <direct.h>
00032 #endif
00033
00034 #ifdef HAVE_UNISTD_H
00035 #include <unistd.h>
00036 #endif
00037
00038 std::string S3D::getHomeDir()
00039 {
00040 #ifdef _WIN32
00041 if (getenv("USERPROFILE")) return getenv("USERPROFILE");
00042 if (getenv("HOMEPATH") && getenv("HOMEDRIVE"))
00043 {
00044 if (0 != strcmp(getenv("HOMEPATH"), getenv("HOMEDRIVE")))
00045 {
00046
00047 return getenv("HOMEPATH");
00048 }
00049 }
00050 #endif
00051 if (getenv("HOME")) return getenv("HOME");
00052
00053 return ".";
00054 }
00055
00056 void S3D::fileDos2Unix(std::string &file)
00057 {
00058 for (char *f=(char *) file.c_str(); *f; f++)
00059 {
00060 if (*f == '\\') *f = '/';
00061 }
00062 }
00063
00064 bool S3D::dirMake(const std::string &file)
00065 {
00066 #ifdef WIN32
00067 _mkdir(file.c_str());
00068 #else
00069 mkdir(file.c_str(), 0755);
00070 #endif
00071 return true;
00072 }
00073
00074 bool S3D::fileExists(const std::string &file)
00075 {
00076 return (S3D::fileModTime(file) != 0);
00077 }
00078
00079 bool S3D::dirExists(const std::string &file)
00080 {
00081 return (S3D::fileModTime(file) != 0);
00082 }
00083
00084 time_t S3D::fileModTime(const std::string &file)
00085 {
00086 struct stat buf;
00087 memset(&buf, 0, sizeof(buf));
00088 int result = stat(file.c_str(), &buf );
00089
00090 return buf.st_mtime;
00091 }
00092
00093 std::string S3D::getOSDesc()
00094 {
00095 #ifdef _WIN32
00096 return "Windows";
00097 #else
00098 #ifdef __DARWIN__
00099 return "OSX";
00100 #else
00101 return "Unix";
00102 #endif
00103 #endif
00104 }