Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 1, 2010, 10:05:56 PM (14 years ago)
Author:
rgrieder
Message:

Added support for keybindings.ini merging:
When running development builds, the keybinder will merge the local file and the one from the data folder.
Catch: if you want to remove a binding, you'll have to write "NoBinding" (not case sensitive) to override the default command

The keybind command already does that for you though.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/src/libraries/core/ConfigFileManager.cc

    r6432 r6437  
    3333#include "util/Convert.h"
    3434#include "util/Math.h"
    35 #include "util/StringUtils.h"
    3635#include "ConsoleCommand.h"
    3736#include "ConfigValueContainer.h"
     
    116115    }
    117116
    118     std::list<ConfigFileEntry*>::const_iterator ConfigFileSection::getEntryIterator(const std::string& name) const
     117    ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const
    119118    {
    120119        for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
    121120        {
    122121            if ((*it)->getName() == name)
    123                 return it;
    124         }
    125         return this->entries_.end();
     122                return *it;
     123        }
     124        return NULL;
     125    }
     126
     127    ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const
     128    {
     129        for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     130        {
     131            if (((*it)->getName() == name) && ((*it)->getIndex() == index))
     132                return *it;
     133        }
     134        return NULL;
    126135    }
    127136
     
    140149
    141150        return this->entries_.insert(this->entries_.end(), new ConfigFileEntryValue(name, fallback, bString));
    142     }
    143 
    144     std::list<ConfigFileEntry*>::const_iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index) const
    145     {
    146         for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
    147         {
    148             if (((*it)->getName() == name) && ((*it)->getIndex() == index))
    149                 return it;
    150         }
    151         return this->entries_.end();
    152151    }
    153152
     
    175174    // ConfigFile //
    176175    ////////////////
    177     ConfigFile::ConfigFile(const std::string& filename)
     176
     177    const char* ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig";
     178
     179    ConfigFile::ConfigFile(const std::string& filename, bool bCopyFallbackFile)
    178180        : filename_(filename)
     181        , bCopyFallbackFile_(bCopyFallbackFile)
    179182        , bUpdated_(false)
    180183    {
     
    191194        this->clear();
    192195
    193         // Get default file if necessary and available
    194         boost::filesystem::path filepath(PathConfig::getConfigPath() / this->filename_);
    195         if (!boost::filesystem::exists(filepath))
    196         {
    197             // Try to get default one from the data folder
    198             boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / "defaultConfig" / this->filename_);
    199             if (boost::filesystem::exists(defaultFilepath))
    200             {
    201                 COUT(3) << "Copied " << this->filename_ << " from the defaultConfig folder." << std::endl;
    202                 boost::filesystem::copy_file(defaultFilepath, filepath);
     196        boost::filesystem::path filepath(this->filename_);
     197        if (!filepath.is_complete())
     198        {
     199            filepath = PathConfig::getConfigPath() / filepath;
     200            if (this->bCopyFallbackFile_)
     201            {
     202                // Look for default file in the data folder
     203                if (!boost::filesystem::exists(filepath))
     204                {
     205                    boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / DEFAULT_CONFIG_FOLDER / this->filename_);
     206                    if (boost::filesystem::exists(defaultFilepath))
     207                    {
     208                        // Try to copy default file from the data folder
     209                        try
     210                        {
     211                            boost::filesystem::copy_file(defaultFilepath, filepath);
     212                            COUT(3) << "Copied " << this->filename_ << " from the default config folder." << std::endl;
     213                        }
     214                        catch (const boost::filesystem::filesystem_error& ex)
     215                        { COUT(1) << "Error in ConfigFile: " << ex.what() << std::endl; }
     216                    }
     217                }
    203218            }
    204219        }
     
    295310            COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
    296311
    297             // Save the file in case something changed (like stripped white space)
    298             this->save();
     312            // DO NOT save the file --> we can open supposedly read only config files
    299313        } // end file.is_open()
    300314    }
     
    307321    void ConfigFile::saveAs(const std::string& filename) const
    308322    {
     323        boost::filesystem::path filepath(filename);
     324        if (!filepath.is_complete())
     325            filepath = PathConfig::getConfigPath() / filename;
    309326        std::ofstream file;
    310         file.open((PathConfig::getConfigPathString() + filename).c_str(), std::fstream::out);
     327        file.open(filepath.string().c_str(), std::fstream::out);
    311328        file.setf(std::ios::fixed, std::ios::floatfield);
    312329        file.precision(6);
Note: See TracChangeset for help on using the changeset viewer.