Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 30, 2015, 12:22:27 PM (9 years ago)
Author:
landauf
Message:

moved static application paths (root, executable, modules) into new class named ApplicationPaths
moved configurable data paths (data, log, config) into new class named ConfigurablePaths
removed PathConfig

File:
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/ApplicationPaths.cc

    r10457 r10509  
    2727 */
    2828
    29 #include "PathConfig.h"
     29#include "ApplicationPaths.h"
    3030
    3131#include <cassert>
     
    5353#include "util/Output.h"
    5454#include "util/Exception.h"
    55 #include "commandline/CommandLineIncludes.h"
    5655
    5756// Differentiate Boost Filesystem v2 and v3
     
    5958#  define BF_LEAF leaf
    6059#  define BF_GENERIC_STRING string
    61 #  define BF_NATIVE_STRING file_string
    6260#else
    6361#  define BF_LEAF path().filename().string
    6462#  define BF_GENERIC_STRING generic_string
    65 #  define BF_NATIVE_STRING string
    6663#endif
    6764
     
    7168
    7269    //! Static pointer to the singleton
    73     PathConfig* PathConfig::singletonPtr_s  = 0;
    74 
    75     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    76     SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    77 
    78     PathConfig::PathConfig()
     70    ApplicationPaths* ApplicationPaths::singletonPtr_s  = 0;
     71
     72    ApplicationPaths::ApplicationPaths()
    7973        : rootPath_(*(new bf::path()))
    8074        , executablePath_(*(new bf::path()))
    8175        , modulePath_(*(new bf::path()))
    82         , dataPath_(*(new bf::path()))
    83         , externalDataPath_(*(new bf::path()))
    84         , configPath_(*(new bf::path()))
    85         , logPath_(*(new bf::path()))
    8676        , bBuildDirectoryRun_(false)
    8777    {
     
    138128        {
    139129            orxout(internal_info) << "Running from the build tree." << endl;
    140             PathConfig::bBuildDirectoryRun_ = true;
     130            ApplicationPaths::bBuildDirectoryRun_ = true;
    141131            modulePath_ = specialConfig::moduleDevDirectory;
    142132        }
     
    167157    }
    168158
    169     PathConfig::~PathConfig()
     159    ApplicationPaths::~ApplicationPaths()
    170160    {
    171161        delete &rootPath_;
    172162        delete &executablePath_;
    173163        delete &modulePath_;
    174         delete &dataPath_;
    175         delete &externalDataPath_;
    176         delete &configPath_;
    177         delete &logPath_;
    178     }
    179 
    180     void PathConfig::setConfigurablePaths()
    181     {
    182         if (bBuildDirectoryRun_)
    183         {
    184             dataPath_         = specialConfig::dataDevDirectory;
    185             configPath_       = specialConfig::configDevDirectory;
    186             logPath_          = specialConfig::logDevDirectory;
    187 
    188             // Check for data path override by the command line
    189             if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue())
    190                 externalDataPath_ = CommandLineParser::getValue("externalDataPath").get<std::string>();
    191             else
    192                 externalDataPath_ = specialConfig::externalDataDevDirectory;
    193         }
    194         else
    195         {
    196 
    197 #ifdef INSTALL_COPYABLE // --> relative paths
    198 
    199             // Using paths relative to the install prefix, complete them
    200             dataPath_   = rootPath_ / specialConfig::defaultDataPath;
    201             configPath_ = rootPath_ / specialConfig::defaultConfigPath;
    202             logPath_    = rootPath_ / specialConfig::defaultLogPath;
    203 
    204 #else
    205 
    206             dataPath_  = specialConfig::dataInstallDirectory;
    207 
    208             // Get user directory
    209 #ifdef ORXONOX_PLATFORM_UNIX
    210             char* userDataPathPtr(getenv("HOME"));
    211 #else
    212             char* userDataPathPtr(getenv("APPDATA"));
    213 #endif
    214             if (userDataPathPtr == NULL)
    215                 ThrowException(General, "Could not retrieve user data path.");
    216             bf::path userDataPath(userDataPathPtr);
    217             userDataPath /= ".orxonox";
    218 
    219             configPath_ = userDataPath / specialConfig::defaultConfigPath;
    220             logPath_    = userDataPath / specialConfig::defaultLogPath;
    221 
    222 #endif
    223 
    224         }
    225 
    226         // Option to put all the config and log files in a separate folder
    227         if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue())
    228         {
    229             const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get<std::string>());
    230             configPath_ = configPath_ / directory;
    231             logPath_    = logPath_    / directory;
    232         }
    233 
    234         // Create directories to avoid problems when opening files in non existent folders.
    235         std::vector<std::pair<bf::path, std::string> > directories;
    236         directories.push_back(std::make_pair(bf::path(configPath_), std::string("config")));
    237         directories.push_back(std::make_pair(bf::path(logPath_), std::string("log")));
    238 
    239         for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin();
    240             it != directories.end(); ++it)
    241         {
    242             if (bf::exists(it->first) && !bf::is_directory(it->first))
    243             {
    244                 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
    245                                          Please remove " + it->first.BF_GENERIC_STRING());
    246             }
    247             if (bf::create_directories(it->first)) // function may not return true at all (bug?)
    248             {
    249                 orxout(internal_info) << "Created " << it->second << " directory" << endl;
    250             }
    251         }
    252     }
    253 
    254     std::vector<std::string> PathConfig::getModulePaths()
     164    }
     165
     166    std::vector<std::string> ApplicationPaths::getModulePaths()
    255167    {
    256168        std::vector<std::string> modulePaths;
     
    288200    }
    289201
    290     /*static*/ std::string PathConfig::getRootPathString()
     202    /*static*/ std::string ApplicationPaths::getRootPathString()
    291203    {
    292204        return getInstance().rootPath_.BF_GENERIC_STRING() + '/';
    293205    }
    294206
    295     /*static*/ std::string PathConfig::getExecutablePathString()
     207    /*static*/ std::string ApplicationPaths::getExecutablePathString()
    296208    {
    297209        return getInstance().executablePath_.BF_GENERIC_STRING() + '/';
    298210    }
    299211
    300     /*static*/ std::string PathConfig::getDataPathString()
    301     {
    302         return getInstance().dataPath_.BF_GENERIC_STRING() + '/';
    303     }
    304 
    305     /*static*/ std::string PathConfig::getExternalDataPathString()
    306     {
    307         return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/';
    308     }
    309 
    310     /*static*/ std::string PathConfig::getConfigPathString()
    311     {
    312         return getInstance().configPath_.BF_GENERIC_STRING() + '/';
    313     }
    314 
    315     /*static*/ std::string PathConfig::getLogPathString()
    316     {
    317         return getInstance().logPath_.BF_GENERIC_STRING() + '/';
    318     }
    319 
    320     /*static*/ std::string PathConfig::getModulePathString()
     212    /*static*/ std::string ApplicationPaths::getModulePathString()
    321213    {
    322214        return getInstance().modulePath_.BF_GENERIC_STRING() + '/';
Note: See TracChangeset for help on using the changeset viewer.