DefinesFile.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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                         // Path not set the root
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 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3