Skip to content

Commit

Permalink
Add --nobanner command-line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 28, 2021
1 parent b134ddf commit 5c8904a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions doc/man/wesnoth.6
Expand Up @@ -226,6 +226,9 @@ or
or
.BR --plugin .
.TP
.B --nobanner
suppress the startup banner.
.TP
.B --nomusic
runs the game without music.
.TP
Expand Down
4 changes: 4 additions & 0 deletions src/commandline_options.cpp
Expand Up @@ -107,6 +107,7 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
, nocache(false)
, nodelay(false)
, nogui(false)
, nobanner(false)
, nomusic(false)
, nosound(false)
, new_widgets(false)
Expand Down Expand Up @@ -280,6 +281,7 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
("unit,u", po::value<std::vector<std::string>>(), "runs a unit test scenario. The GUI is not shown and the exit code of the program reflects the victory / defeat conditions of the scenario.\n\t0 - PASS\n\t1 - FAIL\n\t3 - FAIL (INVALID REPLAY)\n\t4 - FAIL (ERRORED REPLAY)\n\t5 - FAIL (BROKE STRICT)\n\t6 - FAIL (WML EXCEPTION)\n\tMultiple tests can be run by giving this option multiple times, in this case the test run will stop immediately after any test which doesn't PASS and the return code will be the status of the test that caused the stop.")
("showgui", "don't run headlessly (for debugging a failing test)")
("log-strict", po::value<std::string>(), "sets the strict level of the logger. any messages sent to log domains of this level or more severe will cause the unit test to fail regardless of the victory result.")
("nobanner", "suppress startup banner.")
("noreplaycheck", "don't try to validate replay of unit test.")
("mp-test", "load the test mp scenarios.")
;
Expand Down Expand Up @@ -422,6 +424,8 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
nosound = true;
if (vm.count("nogui"))
nogui = true;
if (vm.count("nobanner"))
nobanner = true;
if (vm.count("parm"))
multiplayer_parm = parse_to_uint_string_string_tuples_(vm["parm"].as<std::vector<std::string>>());
if (vm.count("preprocess"))
Expand Down
2 changes: 2 additions & 0 deletions src/commandline_options.hpp
Expand Up @@ -145,6 +145,8 @@ class commandline_options
bool nodelay;
/** True if --nogui was given on the command line. Disables GUI. */
bool nogui;
/** True if --nobanner was given on the command line. Disables startup banner. */
bool nobanner;
/** True if --nomusic was given on the command line. Disables music. */
bool nomusic;
/** True if --nosound was given on the command line. Disables sound. */
Expand Down
20 changes: 11 additions & 9 deletions src/game_launcher.cpp
Expand Up @@ -261,13 +261,15 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts)
if(cmdline_opts_.translation_percent)
set_min_translation_percent(*cmdline_opts_.translation_percent);

std::cerr
<< "\nData directory: " << filesystem::sanitize_path(game_config::path)
<< "\nUser configuration directory: " << filesystem::sanitize_path(filesystem::get_user_config_dir())
<< "\nUser data directory: " << filesystem::sanitize_path(filesystem::get_user_data_dir())
<< "\nCache directory: " << filesystem::sanitize_path(filesystem::get_cache_dir())
<< '\n';
std::cerr << '\n';
if(!cmdline_opts.nobanner) {
std::cerr
<< "\nData directory: " << filesystem::sanitize_path(game_config::path)
<< "\nUser configuration directory: " << filesystem::sanitize_path(filesystem::get_user_config_dir())
<< "\nUser data directory: " << filesystem::sanitize_path(filesystem::get_user_data_dir())
<< "\nCache directory: " << filesystem::sanitize_path(filesystem::get_cache_dir())
<< '\n';
std::cerr << '\n';
}

// disable sound in nosound mode, or when sound engine failed to initialize
if(no_sound || ((preferences::sound_on() || preferences::music_on() ||
Expand Down Expand Up @@ -341,7 +343,7 @@ bool game_launcher::init_lua_script()
{
bool error = false;

std::cerr << "Checking lua scripts... ";
if(!cmdline_opts_.nobanner) std::cerr << "Checking lua scripts... ";

if(cmdline_opts_.script_unsafe_mode) {
// load the "package" package, so that scripts can get what packages they want
Expand Down Expand Up @@ -421,7 +423,7 @@ bool game_launcher::init_lua_script()
}
}

if(!error) {
if(!error && !cmdline_opts_.nobanner) {
std::cerr << "ok\n";
}

Expand Down
21 changes: 16 additions & 5 deletions src/wesnoth.cpp
Expand Up @@ -406,7 +406,7 @@ static int process_command_args(const commandline_options& cmdline_opts)
}

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

if(!filesystem::is_directory(game_config::path)) {
std::cerr << "Could not find directory '" << game_config::path << "'\n";
Expand Down Expand Up @@ -962,6 +962,15 @@ int main(int argc, char** argv)
{
auto args = read_argv(argc, argv);
assert(!args.empty());

// --nobanner needs to be detected before the main command-line parsing happens
bool nobanner = false;
for(const auto& arg : args) {
if(arg == "--nobanner") {
nobanner = true;
break;
}
}

#ifdef _WIN32
// Some switches force a Windows console to be attached to the process even
Expand Down Expand Up @@ -1032,9 +1041,11 @@ int main(int argc, char** argv)
SDL_StartTextInput();

try {
std::cerr << "Battle for Wesnoth v" << game_config::revision << " " << game_config::build_arch() << '\n';
const std::time_t t = std::time(nullptr);
std::cerr << "Started on " << ctime(&t) << "\n";
if(!nobanner) {
std::cerr << "Battle for Wesnoth v" << game_config::revision << " " << game_config::build_arch() << '\n';
const std::time_t t = std::time(nullptr);
std::cerr << "Started on " << ctime(&t) << "\n";
}

const std::string& exe_dir = filesystem::get_exe_dir();
if(!exe_dir.empty()) {
Expand All @@ -1060,7 +1071,7 @@ int main(int argc, char** argv)
}

if(!auto_dir.empty()) {
std::cerr << "Automatically found a possible data directory at " << filesystem::sanitize_path(auto_dir) << '\n';
if(!nobanner) std::cerr << "Automatically found a possible data directory at " << filesystem::sanitize_path(auto_dir) << '\n';
game_config::path = auto_dir;
}
}
Expand Down

0 comments on commit 5c8904a

Please sign in to comment.