Skip to content

Commit

Permalink
fixup travis (failure to find preferences is not reported as error)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed May 20, 2014
1 parent c5838b9 commit 302b0a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
17 changes: 11 additions & 6 deletions src/filesystem.cpp
Expand Up @@ -703,23 +703,28 @@ static std::string read_stream(std::istream& s)
return ss.str();
}

std::istream *istream_file(const std::string &fname)
std::istream *istream_file(const std::string &fname, bool treat_failure_as_error)
{
LOG_FS << "Streaming " << fname << " for reading.\n";
LOG_FS << "Streaming " << fname << " for reading." << std::endl;
if (fname.empty())
{
ERR_FS << "Trying to open file with empty name.\n";
ERR_FS << "Trying to open file with empty name." << std::endl;
std::ifstream *s = new std::ifstream();
s->clear(std::ios_base::failbit);
return s;
}

std::ifstream *s = new std::ifstream(fname.c_str(),std::ios_base::binary);
if (s->is_open())
if (s->is_open()) {
return s;
ERR_FS << "Could not open '" << fname << "' for reading.\n";
return s;
}

if (treat_failure_as_error) {
ERR_FS << "Could not open '" << fname << "' for reading." << std::endl;
} else {
LOG_FS << "Could not open '" << fname << "' for reading." << std::endl;
}
return s;
}

std::string read_file(const std::string &fname)
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem.hpp
Expand Up @@ -96,7 +96,7 @@ bool looks_like_pbl(const std::string& file);
* to the game path (true) or to the current directory from which Wesnoth was run (false).
*/
std::string read_file(const std::string &fname);
std::istream *istream_file(const std::string &fname);
std::istream *istream_file(const std::string &fname, bool treat_failure_as_error = true);
std::ostream *ostream_file(std::string const &fname);
/** Throws io_exception if an error occurs. */
void write_file(const std::string& fname, const std::string& data);
Expand Down
6 changes: 3 additions & 3 deletions src/preferences.cpp
Expand Up @@ -60,7 +60,7 @@ base_manager::base_manager()
{
try{
#ifdef DEFAULT_PREFS_PATH
scoped_istream stream = istream_file(get_default_prefs_file());
scoped_istream stream = istream_file(get_default_prefs_file(),false);
read(prefs, *stream);

config user_prefs;
Expand All @@ -69,13 +69,13 @@ base_manager::base_manager()

prefs.merge_with(user_prefs);
#else
scoped_istream stream = istream_file(get_prefs_file());
scoped_istream stream = istream_file(get_prefs_file(),false);
read(prefs, *stream);
#endif
} catch(const config::error& e) {
ERR_CFG << "Error loading preference, message: "
<< e.what()
<< '\n';
<< std::endl;
}
}

Expand Down

0 comments on commit 302b0a8

Please sign in to comment.