-namespace bbtk
-{
-/// Constructor
-ConfigurationFile::ConfigurationFile()
-{
- char *execPath = GetExecutablePath();
-
- #if defined(WIN32)
- std::string slash("\\");
- #else
- std::string slash("/");
- #endif
-
- // ==> Set system paths
- mBin_path = execPath;
- mInstall_path = mBin_path + slash + "..";
- // The relative path to the doc folder (=BBTK_DOC_REL_PATH)
- mDoc_rel_path = BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH);
- // The path to the doc folder (=mInstall_path+"/"+mDoc_rel_path)
- mDoc_path = mInstall_path + slash + mDoc_rel_path;
- // The relative path to the doc folder (=BBTK_BBS_REL_PATH)
- mBbs_rel_path = BBTK_STRINGIFY_SYMBOL(BBTK_BBS_REL_PATH);
- // The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
- mBbs_path = mInstall_path + slash + mBbs_rel_path;
- // The relative path to the rsc folder (=BBTK_RSC_REL_PATH)
- // mRsc_rel_path = BBTK_STRINGIFY_SYMBOL(BBTK_RSC_REL_PATH);
- // The path to the rsc folder (=mInstall_path+"/"+mRsc_rel_path)
- // mRsc_path = mInstall_path + slash + mRsc_rel_path;
- // The path to the bbtk data folder
- // Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
- // But can be overriden by value read from bbtk_config.xml
- mData_path = mInstall_path + slash + BBTK_STRINGIFY_SYMBOL(BBTK_DATA_REL_PATH);
- // MessageManager::SetMessageLevel("Config",1);
- bbtkMessage("Config",1," ==> bin : '"<<mBin_path<<"'"<<std::endl);
- bbtkMessage("Config",1," ==> prefix : '"<<mInstall_path<<"'"<<std::endl);
- bbtkMessage("Config",1," ==> doc : '"<<mDoc_path<<"'"<<std::endl);
- bbtkMessage("Config",1," ==> bbs : '"<<mBbs_path<<"'"<<std::endl);
- // bbtkMessage("Config",1," ==> rsc : '"<<mRsc_path<<"'"<<std::endl);
- bbtkMessage("Config",1," ==> data : '"<<mData_path<<"'"<<std::endl);
-
- // ==> First we look for bbtk_config.xml in "."
- char buf[2048];
- const char *currentDir = getcwd(buf, 2048);
-
- if( !currentDir )
- {
- std::cerr << "Path was too long to fit on 2048 bytes ?!?" << std::endl;
- // \todo : what else?
- // How abort a constructor and warn the caller function?
- // LG : throw an exception
- }
-
- std::string configXmlFullPathName = currentDir + slash + "bbtk_config.xml";
-
- if ( FileExists( configXmlFullPathName ))
- {
- bbtkMessage("Config",1, "ConfigurationFile : [" << configXmlFullPathName <<
- "] found in current directory" << std::endl);
- //Read(configXmlFullPathName.c_str());
- // traiter le fichier local
- }
-
-// ==> Then we look for bbtk_config.xml in ".bbtk"
- else
- {
- #if defined(__GNUC__)
- std::string str_home(getenv("HOME"));
- #elif defined(_WIN32)
- std::string str_home(getenv("USERPROFILE"));
- #endif
- configXmlFullPathName = str_home + slash + ".bbtk/bbtk_config.xml";
- if (!FileExists( configXmlFullPathName ))
- {
- // ==> Nothing found, we create bbtk_config.xml in ".bbtk"
- InstallPath ();
- }
- }
-
-// In any case, deal with bbtk_config.xml!
- Read(configXmlFullPathName.c_str());
-}
-
-/// Destructor
-ConfigurationFile::~ConfigurationFile()
-{
-}
-
-// See : http://www.techbytes.ca/techbyte103.html for more O.S.
-bool ConfigurationFile::FileExists(std::string strFilename) {
- struct stat stFileInfo;
- bool blnReturn;
- int intStat;
-
- // Attempt to get the file attributes
- intStat = stat(strFilename.c_str(),&stFileInfo);
- if(intStat == 0) {
- // We were able to get the file attributes
- // so the file obviously exists.
- blnReturn = true;
- } else {
- // We were not able to get the file attributes.
- // This may mean that we don't have permission to
- // access the folder which contains this file. If you
- // need to do that level of checking, lookup the
- // return values of stat which will give you
- // more details on why stat failed.
- blnReturn = false;
- }