Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 12, 2010, 12:47:30 AM (14 years ago)
Author:
rgrieder
Message:

Basic stuff up and running for the Qt sandbox.
No GUI support yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox_qt/src/libraries/core/PathConfig.cc

    r6417 r7421  
    3333#include <cstdio>
    3434#include <vector>
    35 #include <boost/version.hpp>
    36 #include <boost/filesystem.hpp>
    3735
    3836#ifdef ORXONOX_PLATFORM_WINDOWS
     
    5452#include "util/Debug.h"
    5553#include "util/Exception.h"
    56 #include "CommandLineParser.h"
    57 
    58 // Boost 1.36 has some issues with deprecated functions that have been omitted
    59 #if (BOOST_VERSION == 103600)
    60 #  define BOOST_LEAF_FUNCTION filename
    61 #else
    62 #  define BOOST_LEAF_FUNCTION leaf
    63 #endif
    6454
    6555namespace orxonox
    6656{
    67     namespace bf = boost::filesystem;
    68 
    6957    //! Static pointer to the singleton
    7058    PathConfig* PathConfig::singletonPtr_s  = 0;
    7159
    72     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    73     SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    74 
    7560    PathConfig::PathConfig()
    76         : rootPath_(*(new bf::path()))
    77         , executablePath_(*(new bf::path()))
    78         , modulePath_(*(new bf::path()))
    79         , dataPath_(*(new bf::path()))
    80         , externalDataPath_(*(new bf::path()))
    81         , configPath_(*(new bf::path()))
    82         , logPath_(*(new bf::path()))
    83         , bDevRun_(false)
    8461    {
    8562        //////////////////////////
     
    125102#endif
    126103
    127         executablePath_ = bf::path(buffer);
     104        executablePath_ = QDir(buffer);
    128105#ifndef ORXONOX_PLATFORM_APPLE
    129         executablePath_ = executablePath_.branch_path(); // remove executable name
    130 #endif
    131 
    132         /////////////////////
    133         // SET MODULE PATH //
    134         /////////////////////
    135 
    136         if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))
     106        executablePath_.cdUp(); // remove executable name
     107#endif
     108
     109        if (executablePath_.exists("orxonox_dev_build.keep_me"))
    137110        {
    138111            COUT(1) << "Running from the build tree." << std::endl;
    139112            PathConfig::bDevRun_ = true;
    140             modulePath_ = specialConfig::moduleDevDirectory;
    141113        }
    142114        else
     
    146118
    147119            // Also set the root path
    148             bf::path relativeExecutablePath(specialConfig::defaultRuntimePath);
     120            QDir relativeExecutablePath(specialConfig::defaultRuntimePath);
    149121            rootPath_ = executablePath_;
    150             while (!bf::equivalent(rootPath_ / relativeExecutablePath, executablePath_) && !rootPath_.empty())
    151                 rootPath_ = rootPath_.branch_path();
    152             if (rootPath_.empty())
    153                 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
    154 
    155             // Module path is fixed as well
    156             modulePath_ = rootPath_ / specialConfig::defaultModulePath;
     122            while (rootPath_ / relativeExecutablePath != executablePath_)
     123            {
     124                if (!rootPath_.cdUp())
     125                    ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
     126            }
    157127
    158128#else
    159129
    160130            // There is no root path, so don't set it at all
    161             // Module path is fixed as well
    162             modulePath_ = specialConfig::moduleInstallDirectory;
    163131
    164132#endif
     
    168136    PathConfig::~PathConfig()
    169137    {
    170         delete &rootPath_;
    171         delete &executablePath_;
    172         delete &modulePath_;
    173         delete &dataPath_;
    174         delete &externalDataPath_;
    175         delete &configPath_;
    176         delete &logPath_;
    177138    }
    178139
     
    184145            configPath_       = specialConfig::configDevDirectory;
    185146            logPath_          = specialConfig::logDevDirectory;
    186 
    187             // Check for data path override by the command line
    188             if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue())
    189                 externalDataPath_ = CommandLineParser::getValue("externalDataPath").getString();
    190             else
    191                 externalDataPath_ = specialConfig::externalDataDevDirectory;
    192147        }
    193148        else
     
    213168            if (userDataPathPtr == NULL)
    214169                ThrowException(General, "Could not retrieve user data path.");
    215             bf::path userDataPath(userDataPathPtr);
     170            QDir userDataPath(userDataPathPtr);
    216171            userDataPath /= ".orxonox";
    217172
     
    223178        }
    224179
    225         // Option to put all the config and log files in a separate folder
    226         if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue())
    227         {
    228             const std::string& directory(CommandLineParser::getValue("writingPathSuffix").getString());
    229             configPath_ = configPath_ / directory;
    230             logPath_    = logPath_    / directory;
    231         }
    232 
    233180        // Create directories to avoid problems when opening files in non existent folders.
    234         std::vector<std::pair<bf::path, std::string> > directories;
    235         directories.push_back(std::make_pair(bf::path(configPath_), "config"));
    236         directories.push_back(std::make_pair(bf::path(logPath_), "log"));
    237 
    238         for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin();
     181        std::vector<std::pair<QDir, std::string> > directories;
     182        directories.push_back(std::make_pair(QDir(configPath_), "config"));
     183        directories.push_back(std::make_pair(QDir(logPath_), "log"));
     184
     185        for (std::vector<std::pair<QDir, std::string> >::iterator it = directories.begin();
    239186            it != directories.end(); ++it)
    240187        {
    241             if (bf::exists(it->first) && !bf::is_directory(it->first))
     188            if (!it->first.exists())
    242189            {
    243                 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
    244                                          Please remove " + it->first.string());
    245             }
    246             if (bf::create_directories(it->first)) // function may not return true at all (bug?)
    247             {
     190                if (!it->first.mkpath("."))
     191                    ThrowException(General, std::string("The ") + it->second + " directory could not be created.");
    248192                COUT(4) << "Created " << it->second << " directory" << std::endl;
    249193            }
     
    251195    }
    252196
    253     std::vector<std::string> PathConfig::getModulePaths()
    254     {
    255         std::vector<std::string> modulePaths;
    256 
    257         // We search for helper files with the following extension
    258         const std::string& moduleextension = specialConfig::moduleExtension;
    259         size_t moduleextensionlength = moduleextension.size();
    260 
    261         // Add that path to the PATH variable in case a module depends on another one
    262         std::string pathVariable(getenv("PATH"));
    263         putenv(const_cast<char*>(("PATH=" + pathVariable + ';' + modulePath_.string()).c_str()));
    264 
    265         // Make sure the path exists, otherwise don't load modules
    266         if (!boost::filesystem::exists(modulePath_))
    267             return modulePaths;
    268 
    269         boost::filesystem::directory_iterator file(modulePath_);
    270         boost::filesystem::directory_iterator end;
    271 
    272         // Iterate through all files
    273         while (file != end)
    274         {
    275             const std::string& filename = file->BOOST_LEAF_FUNCTION();
    276 
    277             // Check if the file ends with the exension in question
    278             if (filename.size() > moduleextensionlength)
    279             {
    280                 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
    281                 {
    282                     // We've found a helper file
    283                     const std::string& library = filename.substr(0, filename.size() - moduleextensionlength);
    284                     modulePaths.push_back((modulePath_ / library).file_string());
    285                 }
    286             }
    287             ++file;
    288         }
    289 
    290         return modulePaths;
    291     }
    292 
    293197    /*static*/ std::string PathConfig::getRootPathString()
    294198    {
    295         return getInstance().rootPath_.string() + '/';
     199        return getInstance().rootPath_.path().toStdString() + '/';
    296200    }
    297201
    298202    /*static*/ std::string PathConfig::getExecutablePathString()
    299203    {
    300         return getInstance().executablePath_.string() + '/';
     204        return getInstance().executablePath_.path().toStdString() + '/';
    301205    }
    302206
    303207    /*static*/ std::string PathConfig::getDataPathString()
    304208    {
    305         return getInstance().dataPath_.string() + '/';
    306     }
    307 
    308     /*static*/ std::string PathConfig::getExternalDataPathString()
    309     {
    310         return getInstance().externalDataPath_.string() + '/';
     209        return getInstance().dataPath_.path().toStdString() + '/';
    311210    }
    312211
    313212    /*static*/ std::string PathConfig::getConfigPathString()
    314213    {
    315         return getInstance().configPath_.string() + '/';
     214        return getInstance().configPath_.path().toStdString() + '/';
    316215    }
    317216
    318217    /*static*/ std::string PathConfig::getLogPathString()
    319218    {
    320         return getInstance().logPath_.string() + '/';
    321     }
    322 
    323     /*static*/ std::string PathConfig::getModulePathString()
    324     {
    325         return getInstance().modulePath_.string() + '/';
     219        return getInstance().logPath_.path().toStdString() + '/';
    326220    }
    327221}
Note: See TracChangeset for help on using the changeset viewer.