Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound path #6818

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,11 @@ const std::string& get_version_path_suffix()
if(bfs::is_directory(new_saves_dir)) {
if(!bfs::exists(old_saves_dir)) {
std::cout << "Apple developer's userdata migration: ";
std::cout << "symlinking " << old_saves_dir << " to " << new_saves_dir << "\n";
std::cout << "symlinking " << filesystem::sanitize_path(old_saves_dir.string()) << " to " << filesystem::sanitize_path(new_saves_dir.string()) << "\n";
bfs::create_symlink(new_saves_dir, old_saves_dir);
} else if(!bfs::symbolic_link_exists(old_saves_dir)) {
std::cout << "Apple developer's userdata migration: ";
std::cout << "Problem! Old (non-containerized) directory " << old_saves_dir << " is not a symlink. Your savegames are scattered around 2 locations.\n";
std::cout << "Problem! Old (non-containerized) directory " << filesystem::sanitize_path(old_saves_dir.string()) << " is not a symlink. Your savegames are scattered around 2 locations.\n";
}
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/game_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,19 @@ bool game_launcher::init_lua_script()

std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());

std::cerr << "\nRunning lua script: " << *cmdline_opts_.script_file << std::endl;
std::cerr << "\nRunning lua script: " << filesystem::sanitize_path(*cmdline_opts_.script_file) << std::endl;

plugins_manager::get()->get_kernel_base()->run(full_script.c_str(), *cmdline_opts_.script_file);
} else {
std::cerr << "Encountered failure when opening script '" << *cmdline_opts_.script_file << "'\n";
std::cerr << "Encountered failure when opening script '" << filesystem::sanitize_path(*cmdline_opts_.script_file) << "'\n";
error = true;
}
}

if(cmdline_opts_.plugin_file) {
std::string filename = *cmdline_opts_.plugin_file;

std::cerr << "Loading a plugin file'" << filename << "'...\n";
std::cerr << "Loading a plugin file'" << filesystem::sanitize_path(filename) << "'...\n";

filesystem::scoped_istream sf = filesystem::istream_file(filename);

Expand Down
22 changes: 21 additions & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "log.hpp"
#include <boost/algorithm/string.hpp>

#include <map>
#include <sstream>
Expand Down Expand Up @@ -207,6 +208,25 @@ static void print_precise_timestamp(std::ostream& out) noexcept
} catch(...) {}
}

std::string sanitize_log(const std::string& logstr)
{
std::string str = logstr;

#ifdef _WIN32
const char* user_name = getenv("USERNAME");
if(user_name != nullptr) {
boost::replace_all(str, std::string("\\") + user_name + "\\", "\\USER\\");
}
#else
const char* user_name = getenv("USER");
if(user_name != nullptr) {
boost::replace_all(str, std::string("/") + user_name + "/", "/USER/");
}
#endif

return str;
}

log_in_progress logger::operator()(const log_domain& domain, bool show_names, bool do_indent) const
{
if (severity_ > domain.domain_->second) {
Expand Down Expand Up @@ -248,7 +268,7 @@ void log_in_progress::operator|(formatter&& message)
stream_ << get_timestamp(std::time(nullptr));
}
}
stream_ << prefix_ << message.str();
stream_ << prefix_ << sanitize_log(message.str());
}

void log_in_progress::set_indent(int level) {
Expand Down
1 change: 1 addition & 0 deletions src/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void timestamps(bool);
void precise_timestamps(bool);
std::string get_timestamp(const std::time_t& t, const std::string& format="%Y%m%d %H:%M:%S ");
std::string get_timespan(const std::time_t& t);
std::string sanitize_log(const std::string& logstr);

logger &err(), &warn(), &info(), &debug();
log_domain& general();
Expand Down
26 changes: 13 additions & 13 deletions src/wesnoth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static void encode(const std::string& input_file, const std::string& output_file
ifile.peek(); // We need to touch the stream to set the eof bit

if(!ifile.good()) {
std::cerr << "Input file " << input_file
std::cerr << "Input file " << filesystem::sanitize_path(input_file)
<< " is not good for reading. Exiting to prevent bzip2 from segfaulting\n";
safe_exit(1);
}
Expand Down Expand Up @@ -225,19 +225,19 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
if(cmdline_opts.preprocess_input_macros) {
std::string file = *cmdline_opts.preprocess_input_macros;
if(filesystem::file_exists(file) == false) {
std::cerr << "please specify an existing file. File " << file << " doesn't exist.\n";
std::cerr << "please specify an existing file. File " << filesystem::sanitize_path(file) << " doesn't exist.\n";
return;
}

std::cerr << SDL_GetTicks() << " Reading cached defines from: " << file << "\n";
std::cerr << SDL_GetTicks() << " Reading cached defines from: " << filesystem::sanitize_path(file) << "\n";

config cfg;

try {
filesystem::scoped_istream stream = filesystem::istream_file(file);
read(cfg, *stream);
} catch(const config::error& e) {
std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl;
std::cerr << "Caught a config error while parsing file '" << filesystem::sanitize_path(file) << "':\n" << e.message << std::endl;
}

int read = 0;
Expand Down Expand Up @@ -351,7 +351,7 @@ static int handle_validate_command(const std::string& file, abstract_validator&
LOG_PREPROC << "adding define: " << define << '\n';
defines_map.emplace(define, preproc_define(define));
}
std::cout << "Validating " << file << " against schema " << validator.name_ << std::endl;
std::cout << "Validating " << filesystem::sanitize_path(file) << " against schema " << validator.name_ << std::endl;
lg::set_strict_severity(0);
filesystem::scoped_istream stream = preprocess_file(file, &defines_map);
config result;
Expand Down Expand Up @@ -385,7 +385,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
}

if(cmdline_opts.userconfig_path) {
std::cout << filesystem::get_user_config_dir() << '\n';
std::cout << filesystem::sanitize_path(filesystem::get_user_config_dir()) << '\n';
return 0;
}

Expand All @@ -394,7 +394,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
}

if(cmdline_opts.userdata_path) {
std::cout << filesystem::get_user_data_dir() << '\n';
std::cout << filesystem::sanitize_path(filesystem::get_user_data_dir()) << '\n';
return 0;
}

Expand All @@ -412,10 +412,10 @@ static int process_command_args(const commandline_options& cmdline_opts)
}

game_config::path = filesystem::normalize_path(game_config::path, true, true);
if(!cmdline_opts.nobanner) std::cerr << "Overriding data directory with " << game_config::path << std::endl;
if(!cmdline_opts.nobanner) std::cerr << "Overriding data directory with " << filesystem::sanitize_path(game_config::path) << std::endl;

if(!filesystem::is_directory(game_config::path)) {
std::cerr << "Could not find directory '" << game_config::path << "'\n";
std::cerr << "Could not find directory '" << filesystem::sanitize_path(game_config::path) << "'\n";
throw config::error("directory not found");
}

Expand All @@ -424,7 +424,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
}

if(cmdline_opts.data_path) {
std::cout << game_config::path << '\n';
std::cout << filesystem::sanitize_path(game_config::path) << '\n';
return 0;
}

Expand All @@ -443,7 +443,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
if(cmdline_opts.gunzip) {
const std::string input_file(*cmdline_opts.gunzip);
if(!filesystem::is_gzip_file(input_file)) {
std::cerr << "file '" << input_file << "'isn't a .gz file\n";
std::cerr << "file '" << filesystem::sanitize_path(input_file) << "'isn't a .gz file\n";
return 2;
}

Expand All @@ -454,7 +454,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
if(cmdline_opts.bunzip2) {
const std::string input_file(*cmdline_opts.bunzip2);
if(!filesystem::is_bzip2_file(input_file)) {
std::cerr << "file '" << input_file << "'isn't a .bz2 file\n";
std::cerr << "file '" << filesystem::sanitize_path(input_file) << "'isn't a .bz2 file\n";
return 2;
}

Expand Down Expand Up @@ -645,7 +645,7 @@ static void handle_lua_script_args(game_launcher* game, commandline_options& /*c

if(!game->init_lua_script()) {
// std::cerr << "error when loading lua scripts at startup\n";
// std::cerr << "could not load lua script: " << *cmdline_opts.script_file << std::endl;
// std::cerr << "could not load lua script: " << filesystem::sanitize_path(*cmdline_opts.script_file) << std::endl;
}
}

Expand Down