From edc73ba637b51eed09159ebfae48ccad8260774e Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 9 Mar 2018 20:54:12 -0500 Subject: [PATCH] WIP sanitizing build info to omit username --- src/build_info.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/build_info.cpp b/src/build_info.cpp index 8a69bcc9ed613..d956a7d083a75 100644 --- a/src/build_info.cpp +++ b/src/build_info.cpp @@ -454,6 +454,23 @@ std::string optional_features_report() return o.str(); } +static std::string sanitize_path(const std::string& path) { +#ifdef _WIN32 + const std::string user_profile = getenv("USERPROFILE"); +#else + const std::string user_profile = getenv("HOME"); +#endif + const std::string canonicalized = filesystem::normalize_path(path, true, false); + if(canonicalized.compare(0, user_profile.size(), user_profile) == 0) { +#ifdef _WIN32 + return "%USERPROFILE%" + canonicalized.substr(user_profile.size()); +#else + return "$HOME" + canonicalized.substr(user_profile.size()); +#endif + } + return canonicalized; +} + std::string full_build_report() { std::ostringstream o; @@ -464,12 +481,12 @@ std::string full_build_report() << "Game paths\n" << "==========\n" << '\n' - << "Data dir: " << game_config::path << '\n' - << "User config dir: " << filesystem::get_user_config_dir() << '\n' - << "User data dir: " << filesystem::get_user_data_dir() << '\n' - << "Saves dir: " << filesystem::get_saves_dir() << '\n' - << "Add-ons dir: " << filesystem::get_addons_dir() << '\n' - << "Cache dir: " << filesystem::get_cache_dir() << '\n' + << "Data dir: " << sanitize_path(game_config::path) << '\n' + << "User config dir: " << sanitize_path(filesystem::get_user_config_dir()) << '\n' + << "User data dir: " << sanitize_path(filesystem::get_user_data_dir()) << '\n' + << "Saves dir: " << sanitize_path(filesystem::get_saves_dir()) << '\n' + << "Add-ons dir: " << sanitize_path(filesystem::get_addons_dir()) << '\n' + << "Cache dir: " << sanitize_path(filesystem::get_cache_dir()) << '\n' << '\n' << "Libraries\n" << "=========\n"