Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7661 in orxonox.OLD for trunk/src/lib/util


Ignore:
Timestamp:
May 18, 2006, 12:55:34 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

Location:
trunk/src/lib/util
Files:
1 deleted
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/loading/resource_manager.cc

    r7460 r7661  
    1717
    1818#include "util/loading/resource_manager.h"
    19 
     19#include "file.h"
    2020#include "substring.h"
    2121#include "debug.h"
     
    6060
    6161  this->dataDir = "./";
    62   this->_cwd = "";
    6362  this->tryDataDir("./data");
    6463}
     
    8786bool ResourceManager::setDataDir(const std::string& dataDir)
    8887{
    89   std::string realDir = ResourceManager::homeDirCheck(dataDir);
    90   if (isDir(realDir))
    91   {
    92     if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\')
     88  File dataDirectory(dataDir);
     89  if (dataDirectory.isDirectory())
     90  {
     91    this->dataDir = dataDirectory.name();
     92
     93    if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')
    9394    {
    94       this->dataDir = realDir;
    95     }
    96     else
    97     {
    98       this->dataDir = realDir;
    9995      this->dataDir += '/';
    10096    }
     
    10399  else
    104100  {
    105     PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir.c_str(), this->dataDir.c_str());
     101    PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir.c_str(), this->dataDir.c_str());
    106102    return false;
    107103  }
     
    116112bool ResourceManager::tryDataDir(const std::string& dataDir)
    117113{
    118   std::string realDir = ResourceManager::homeDirCheck(dataDir);
    119   if (isDir(realDir))
    120   {
    121     if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\')
     114  File dataDirectory(dataDir);
     115  if (dataDirectory.isDirectory())
     116  {
     117    this->dataDir = dataDirectory.name();
     118
     119    if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')
    122120    {
    123       this->dataDir = realDir;
    124     }
    125     else
    126     {
    127       this->dataDir = realDir;
    128121      this->dataDir += '/';
    129122    }
     
    140133bool ResourceManager::verifyDataDir(const std::string& fileInside)
    141134{
    142   bool retVal;
    143   if (!isDir(this->dataDir))
    144   {
    145     PRINTF(1)("%s is not a directory\n", this->dataDir.c_str());
     135  File dataDirectory(this->dataDir);
     136  if (!dataDirectory.isDirectory())
     137  {
     138    PRINTF(1)("'%s' is not a directory\n", this->dataDir.c_str());
    146139    return false;
    147140  }
    148141
    149   std::string testFile = this->dataDir + fileInside;
    150   retVal = isFile(testFile);
    151   return retVal;
     142  File testFile(this->dataDir + fileInside);
     143  return testFile.isFile();
    152144}
    153145
     
    161153bool ResourceManager::addImageDir(const std::string& imageDir)
    162154{
    163   std::string newDir;
    164   if (imageDir[imageDir.size()-1] == '/' || imageDir[imageDir.size()-1] == '\\')
    165   {
    166     newDir = imageDir;
    167   }
    168   else
    169   {
    170     newDir = imageDir;
     155  std::string newDir = imageDir;
     156  if (imageDir[imageDir.size()-1] != '/' && imageDir[imageDir.size()-1] != '\\')
     157  {
    171158    newDir += '/';
    172159  }
    173160  // check if the param is a Directory
    174   if (isDir(newDir))
     161  if (File(newDir).isDirectory())
    175162  {
    176163    // check if the Directory has been added before
     
    381368        tmpResource->param[0] = 1.0f;
    382369
    383       if(ResourceManager::isFile(fullName))
     370      if(File(fullName).isFile())
    384371        tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());
    385372      else
     
    407394      break;
    408395    case MD2:
    409       if(ResourceManager::isFile(fullName))
     396      if(File(fullName).isFile())
    410397      {
    411398        tmpResource->param[0] = param0;
     
    425412        tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE;
    426413
    427       if(isFile(fullName))
     414      if(File(fullName).isFile())
    428415        tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
    429416      else
     
    433420#ifndef NO_AUDIO
    434421    case WAV:
    435       if(isFile(fullName))
     422      if(File(fullName).isFile())
    436423        tmpResource->pointer = new OrxSound::SoundBuffer(fullName);
    437424      break;
    438425    case OGG:
    439       if (isFile(fullName))
     426      if (File(fullName).isFile())
    440427        tmpResource->pointer = new OrxSound::OggPlayer(fullName);
    441428      break;
     
    447434      else
    448435        tmpResource->param[0] = GL_TEXTURE_2D;
    449       if(isFile(fullName))
     436      if(File(fullName).isFile())
    450437      {
    451438        PRINTF(4)("Image %s resides to %s\n", fileName, fullName);
     
    458445        {
    459446          std::string imgName = *imageDir + fileName;
    460           if(isFile(imgName))
     447          if(File(imgName).isFile())
    461448          {
    462449            PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
     
    472459#ifndef NO_SHADERS
    473460    case SHADER:
    474       if(ResourceManager::isFile(fullName))
     461      if(File(fullName).isFile())
    475462      {
    476463        if (param0 != MT_NULL)
     
    478465          MultiType param = param0; /// HACK
    479466          std::string secFullName = ResourceManager::getFullName(param.getCString());
    480           if (ResourceManager::isFile(secFullName))
     467          if (File(secFullName).isFile())
    481468          {
    482469            tmpResource->param[0] = secFullName;
     
    750737
    751738/**
    752  * @brief Checks if it is a Directory
    753  * @param directoryName the Directory to check for
    754  * @returns true if it is a directory/symlink false otherwise
    755 */
    756 bool ResourceManager::isDir(const std::string& directoryName)
    757 {
    758   std::string tmpDirName = directoryName;
    759   struct stat status;
    760 
    761   // checking for the termination of the string given. If there is a "/" at the end cut it away
    762   if (directoryName[directoryName.size()-1] == '/' ||
    763       directoryName[directoryName.size()-1] == '\\')
    764   {
    765     tmpDirName.erase(tmpDirName.size()-1);
    766   }
    767 
    768   if(!stat(tmpDirName.c_str(), &status))
    769   {
    770     if (status.st_mode & (S_IFDIR
    771 #ifndef __WIN32__
    772                           | S_IFLNK
    773 #endif
    774                          ))
    775     {
    776       return true;
    777     }
    778     else
    779       return false;
    780   }
    781   else
    782     return false;
    783 }
    784 
    785 /**
    786  * @brief Checks if the file is either a Regular file or a Symlink
    787  * @param fileName the File to check for
    788  * @returns true if it is a regular file/symlink, false otherwise
    789 */
    790 bool ResourceManager::isFile(const std::string& fileName)
    791 {
    792   if (fileName.empty())
    793     return false;
    794   std::string tmpFileName = ResourceManager::homeDirCheck(fileName);
    795   // actually checks the File
    796   struct stat status;
    797   if (!stat(tmpFileName.c_str(), &status))
    798   {
    799     if (status.st_mode & (S_IFREG
    800 #ifndef __WIN32__
    801                           | S_IFLNK
    802 #endif
    803                          ))
    804     {
    805       return true;
    806     }
    807     else
    808       return false;
    809   }
    810   else
    811     return false;
    812 }
    813 
    814 /**
    815  * @brief touches a File on the disk (thereby creating it)
    816  * @param fileName The file to touch
    817 */
    818 bool ResourceManager::touchFile(const std::string& fileName)
    819 {
    820   std::string tmpName = ResourceManager::homeDirCheck(fileName);
    821   if (tmpName.empty())
    822     return false;
    823   FILE* stream;
    824   if( (stream = fopen (tmpName.c_str(), "w")) == NULL)
    825   {
    826     PRINTF(1)("could not open %s fro writing\n", fileName.c_str());
    827     return false;
    828   }
    829   fclose(stream);
    830 }
    831 
    832 /**
    833  * @brief deletes a File from disk
    834  * @param fileName the File to delete
    835 */
    836 bool ResourceManager::deleteFile(const std::string& fileName)
    837 {
    838   std::string tmpName = ResourceManager::homeDirCheck(fileName);
    839   unlink(tmpName.c_str());
    840 }
    841 
    842 /**
    843  * @param name the Name of the file to check
    844  * @returns The name of the file, including the HomeDir
    845  */
    846 std::string ResourceManager::homeDirCheck(const std::string& name)
    847 {
    848   if (name.size() >= 2 && name[0] == '~' && name[1] == '/')
    849   {
    850     std::string homeDir;
    851     std::string newName = name.substr(1);
    852 #ifdef __WIN32__
    853     homeDir = getenv("USERPROFILE");
    854 #else
    855     homeDir = getenv("HOME");
    856 #endif
    857     return homeDir + newName;
    858   }
    859   else
    860     return name;
    861 }
    862 
    863 /**
    864  * @param name the relative name of the File/Directory.
    865  * @returns a new std::string with the name in abs-dir-format
    866  */
    867 std::string ResourceManager::getAbsDir(const std::string& name)
    868 {
    869   if (name.empty())
    870     return "";
    871   std::string retName = name;
    872   if (strncmp(name.c_str(), "/", 1))
    873   {
    874     if (name[0] == '.' && name[1] != '.')
    875       retName.erase(0);
    876     const std::string& absDir = ResourceManager::cwd();
    877     retName = absDir + retName;
    878   }
    879   return retName;
    880 }
    881 
    882 
    883 /**
    884739 * @param fileName the Name of the File to check
    885740 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
     
    892747
    893748  std::string retName = ResourceManager::getInstance()->getDataDir() +fileName;
    894   if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
     749  if (File(retName).isFile() || File(retName).isDirectory())
    895750    return retName;
    896751  else
    897752    return "";
    898 }
    899 
    900 #ifdef __unix__
    901   #include <unistd.h>
    902 #elif __WIN32__ || _MS_DOS_
    903   #include <dir.h>
    904 #else
    905   #include <direct.h> /* Visual C++ */
    906 #endif
    907 /**
    908  * @returns the Current Woring Directory
    909  */
    910 const std::string& ResourceManager::cwd()
    911 {
    912   if (ResourceManager::getInstance()->_cwd.empty())
    913   {
    914     char cwd[1024];
    915     char* errorCode = getcwd(cwd, 1024);
    916     if (errorCode == 0)
    917       return ResourceManager::getInstance()->_cwd;
    918 
    919     ResourceManager::getInstance()->_cwd = cwd;
    920   }
    921   return ResourceManager::getInstance()->_cwd;
    922753}
    923754
     
    936767  std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName;
    937768
    938   if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile))
     769  if (File(checkFile).exists())
    939770    retVal = true;
    940771  else
  • trunk/src/lib/util/loading/resource_manager.h

    r7225 r7661  
    2121
    2222#include "base_object.h"
     23#include "file.h"
     24
    2325#include "multi_type.h"
    24 
    2526#include <vector>
    2627
     
    130131
    131132  // utility functions for handling files in and around the data-directory
    132   static bool isDir(const std::string& directory);
    133   static bool isFile(const std::string& fileName);
    134   static bool touchFile(const std::string& fileName);
    135   static bool deleteFile(const std::string& fileName);
    136   static std::string homeDirCheck(const std::string& fileName);
    137133  static std::string getFullName(const std::string& fileName);
    138134  static bool isInDataDir(const std::string& fileName);
    139   static std::string getAbsDir(const std::string& fileName);
    140   static const std::string& cwd();
    141135
    142136  static const char* ResourceTypeToChar(ResourceType type);
     
    151145  static ResourceManager*    singletonRef;       //!< singleton Reference
    152146
    153   std::string                _cwd;               //!< The currend Working directory.
    154147  std::string                dataDir;            //!< The Data Directory, where all relevant Data is stored.
    155148  std::vector<std::string>   imageDirs;          //!< A list of directories in which images are stored.
  • trunk/src/lib/util/preferences.cc

    r7256 r7661  
    1717
    1818#include "preferences.h"
    19 
    20 using namespace std;
     19#include "lib/parser/ini_parser/ini_parser.h"
    2120
    2221
     
    137136 * @return value of the item if found. defaultValue else
    138137 */
    139 const std::string Preferences::getString(const std::string& section, const std::string& name, const std::string& defaultValue)
     138std::string Preferences::getString(const std::string& section, const std::string& name, const std::string& defaultValue)
    140139{
    141140  return getMultiType(section, name, MultiType(defaultValue)).getString();
     
    260259  IniParser iniParser(this->fileName);
    261260
    262   if ( !iniParser.isOpen() )
    263     return false;
    264 
    265261  std::list<prefSection>::iterator it = data.begin();
    266262  bool didChanges = false;
     
    278274    }
    279275  }
    280 
    281   if ( didChanges )
     276  /// HACK DO WE HAVE TO CHECK THIS??
     277  //if ( didChanges )
    282278  {
    283279    iniParser.writeFile( this->fileName );
     
    314310{
    315311  std::list<std::string> lst;
    316  
     312
    317313  std::list<prefSection>::const_iterator it = data.begin();
    318314
  • trunk/src/lib/util/preferences.h

    r7256 r7661  
    99#include "base_object.h"
    1010#include "multi_type.h"
    11 #include "lib/parser/ini_parser/ini_parser.h"
    1211
    1312// FORWARD DECLARATION
     
    4443   void setMultiType(const std::string& section, const std::string& name, const MultiType& value, bool dontSetModified = false);
    4544
    46    const std::string getString(const std::string& section, const std::string& name, const std::string& defaultValue);
     45   std::string getString(const std::string& section, const std::string& name, const std::string& defaultValue);
    4746   int getInt(const std::string& section, const std::string& name, int defaultValue);
    4847   float getFloat(const std::string& section, const std::string& name, float defaultValue);
     
    5453
    5554   void debug();
    56    
     55
    5756   std::list<std::string> listKeys( const std::string section );
    5857
Note: See TracChangeset for help on using the changeset viewer.