fix #1021, always check if files exist

This commit is contained in:
Dennis Luxen
2014-05-20 12:11:19 +02:00
parent 4fc329a1eb
commit 4ec9f2c00f
3 changed files with 29 additions and 7 deletions
+15 -3
View File
@@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef INI_FILE_UTIL_H
#define INI_FILE_UTIL_H
#include "SimpleLogger.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -40,9 +42,19 @@ inline std::string ReadIniFileAndLowerContents(const boost::filesystem::path &pa
boost::filesystem::fstream config_stream(path);
std::string input_str((std::istreambuf_iterator<char>(config_stream)),
std::istreambuf_iterator<char>());
std::regex regex("^([^=]*)"); // match from start of line to '='
std::string format("\\L$1\\E"); // replace with downcased substring
return std::regex_replace(input_str, regex, format);
std::regex regex("\\w+=");
std::string output = input_str;
const std::sregex_token_iterator end;
for (std::sregex_token_iterator i(input_str.begin(), input_str.end(), regex); i != end; ++i)
{
std::string match = *i;
std::string new_regex = *i;
std::transform(new_regex.begin(), new_regex.end(), new_regex.begin(), ::tolower);
SimpleLogger().Write() << match << " - " << new_regex;
output = std::regex_replace(output, std::regex(match), new_regex);
}
return output;
}
#endif // INI_FILE_UTIL_H
+3
View File
@@ -150,6 +150,7 @@ inline unsigned GenerateServerProgramOptions(const int argc,
// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
bool use_ini_file = false;
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
@@ -159,6 +160,8 @@ inline unsigned GenerateServerProgramOptions(const int argc,
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
use_ini_file = true;
return INIT_OK_START_ENGINE;
}
if (1 > requested_num_threads)