From 5459f2b73cf8e84962da5f37d21980457eadaf8d Mon Sep 17 00:00:00 2001 From: Andrew Mickelson Date: Wed, 15 Nov 2017 23:56:54 -0800 Subject: [PATCH] Added --loglevel and --logfile commandline options New command line options added to control logging in Attract-Mode: --loglevel (silent|info|debug) --logfile `--loglevel silent` suppresses all logging output `--loglevel info` is the default log level `--loglevel debug` provides additional debug messages With the windows GUI version of Attract-Mode, logs are written to "last_run.log" by default. For all other versions (linux, MacOS, windows console) logs are written to the console (stdout) by default. The --logfile option can be used to log to a specified file --- Readme.md | 15 ++++- src/fe_base.cpp | 137 +++++++++++++++++++++++++++++++++++++--- src/fe_base.hpp | 14 ++++ src/fe_cmdline.cpp | 108 +++++++++++++++++++------------ src/fe_image.cpp | 9 +-- src/fe_info.cpp | 8 +-- src/fe_input.cpp | 8 +-- src/fe_net.cpp | 5 +- src/fe_present.cpp | 2 +- src/fe_romlist.cpp | 6 +- src/fe_settings.cpp | 34 +++++----- src/fe_sound.cpp | 8 +-- src/fe_util.cpp | 18 +++--- src/fe_vm.cpp | 39 ++++++------ src/fe_window.cpp | 2 +- src/main.cpp | 56 ++++++++++++---- src/media.cpp | 87 ++++++++++++------------- src/media_dxva2.cpp | 4 +- src/media_vaapi.cpp | 4 +- src/scraper_general.cpp | 50 +++++++-------- src/scraper_net.cpp | 16 ++--- src/scraper_xml.cpp | 38 +++++------ src/zip.cpp | 15 ++--- 23 files changed, 437 insertions(+), 246 deletions(-) diff --git a/Readme.md b/Readme.md index fdc7726c9..5e5caa4b9 100644 --- a/Readme.md +++ b/Readme.md @@ -27,9 +27,9 @@ line as follows: attract --config /my/config/location - In the (hopefully unlikely) event that Attract-Mode has difficulty -finding a display font to use on your system, you can specify one at the -command line as follows: +In the (hopefully unlikely) event that Attract-Mode has difficulty finding a +display font to use on your system, you can specify one at the command line as +follows: attract --font @@ -254,5 +254,14 @@ For a full description of the command lines options available, run: `attract --help` +Attract-Mode by default will print log messages to the console window (stdout). +To suppress these messages, run with the following command line: + +`attract --loglevel silent` + +Alternatively, more verbose debug log messages can be enabled by running: + +`attract --loglevel debug` + [Compile.md]: Compile.md [Layouts.md]: Layouts.md diff --git a/src/fe_base.cpp b/src/fe_base.cpp index a89aa7960..f0d7e7bbe 100644 --- a/src/fe_base.cpp +++ b/src/fe_base.cpp @@ -22,6 +22,18 @@ #include "fe_base.hpp" #include "fe_util.hpp" + +#ifndef NO_MOVIE +extern "C" +{ +#include +} +#endif + +#ifndef NO_SWF +#include "gameswf/gameswf.h" +#endif + #include #include @@ -29,7 +41,7 @@ const char *FE_NAME = FE_NAME_D; const char *FE_COPYRIGHT = FE_NAME_D " " FE_VERSION_D \ - " Copyright (c) 2013-2016 Andrew Mickelson"; + " Copyright (c) 2013-2017 Andrew Mickelson"; const char *FE_VERSION = FE_VERSION_D; const char *FE_WHITESPACE=" \t\r"; @@ -41,6 +53,113 @@ const char *FE_EMULATOR_SUBDIR = "emulators/"; const char *FE_EMULATOR_FILE_EXTENSION = ".cfg"; const char *FE_EMULATOR_DEFAULT = "default-emulator.cfg"; +namespace { + std::ofstream g_logfile; +#ifdef SFML_SYSTEM_WINDOWS + std::ofstream g_nullstream( "NUL" ); +#else + std::ofstream g_nullstream( "/dev/null" ); +#endif + enum FeLogLevel g_log_level=FeLog_Info; + + void ffmpeg_log_callback( void *ptr, int level, const char *fmt, va_list vargs ) + { + if ( level <= av_log_get_level() ) + { + char buff[256]; + vsnprintf( buff, 256, fmt, vargs ); + FeLog() << "FFmpeg: " << buff; + } + } + + void gs_log_callback( bool error, const char *message ) + { + FeLog() << "gameswf: " << message; + } +}; + +std::ostream &FeDebug() +{ + if ( g_log_level == FeLog_Debug ) + return FeLog(); + else + return g_nullstream; +} + +std::ostream &FeLog() +{ + if ( g_log_level == FeLog_Silent ) + return g_nullstream; + + if ( g_logfile.is_open() ) + return g_logfile; + else + return std::cout; +} + +void fe_set_log_file( const std::string &fn ) +{ + if ( fn.empty() ) + g_logfile.close(); + else + g_logfile.open( fn.c_str() ); +} + +void fe_set_log_level( enum FeLogLevel f ) +{ + g_log_level = f; + + +#ifndef NO_MOVIE + if ( f == FeLog_Silent ) + av_log_set_callback( NULL ); + else + { + av_log_set_callback( ffmpeg_log_callback ); + av_log_set_level( ( f == FeLog_Debug ) ? AV_LOG_VERBOSE : AV_LOG_ERROR ); + } +#endif +#ifndef NO_SWF + if ( f == FeLog_Silent ) + gameswf::register_log_callback( NULL ); + else + { + gameswf::register_log_callback( gs_log_callback ); + + gameswf::set_verbose_action( f == FeLog_Debug ); + } +#endif +} + +void fe_print_version() +{ + FeLog() << FE_NAME << " " << FE_VERSION << " (" + << get_OS_string() + << ", SFML " << SFML_VERSION_MAJOR << '.' << SFML_VERSION_MINOR +#ifdef USE_FONTCONFIG + << " +FontConfig" +#endif +#ifdef USE_XINERAMA + << " +Xinerama" +#endif +#ifdef USE_GLES + << " +GLES" +#endif +#ifndef NO_SWF + << " +SWF" +#endif +#ifdef USE_LIBARCHIVE + << " +7z" +#endif + << ") " << std::endl; +#ifdef NO_MOVIE + FeLog() << "No Video, using SFML for Audio." << std::endl; +#else + print_ffmpeg_version_info(); +#endif + +} + void FeBaseConfigurable::invalid_setting( const std::string & fn, const char *base, @@ -49,29 +168,29 @@ void FeBaseConfigurable::invalid_setting( const char **valid2, const char *label ) { - std::cerr << "Unrecognized \"" << base << "\" " << label - << " of \"" << setting << "\""; + FeLog() << "Unrecognized \"" << base << "\" " << label + << " of \"" << setting << "\""; if ( !fn.empty() ) - std::cerr << " in file: " << fn; + FeLog() << " in file: " << fn; - std::cerr << "."; + FeLog() << "."; int i=0; if (valid1[i]) - std::cerr << " Valid " << label <<"s are: " << valid1[i++]; + FeLog() << " Valid " << label <<"s are: " << valid1[i++]; while (valid1[i]) - std::cerr << ", " << valid1[i++]; + FeLog() << ", " << valid1[i++]; if ( valid2 != NULL ) { i=0; while (valid2[i]) - std::cerr << ", " << valid2[i++]; + FeLog() << ", " << valid2[i++]; } - std::cerr << std::endl; + FeLog() << std::endl; } bool FeBaseConfigurable::load_from_file( const std::string &filename, diff --git a/src/fe_base.hpp b/src/fe_base.hpp index 9639e28e8..9d18f5a96 100644 --- a/src/fe_base.hpp +++ b/src/fe_base.hpp @@ -24,6 +24,7 @@ #define FE_BASE_HPP #include +#include extern const char *FE_NAME; extern const char *FE_COPYRIGHT; @@ -36,6 +37,19 @@ extern const char *FE_EMULATOR_SUBDIR; extern const char *FE_EMULATOR_FILE_EXTENSION; extern const char *FE_EMULATOR_DEFAULT; +enum FeLogLevel +{ + FeLog_Silent, + FeLog_Info, + FeLog_Debug +}; + +std::ostream &FeLog(); +std::ostream &FeDebug(); +void fe_set_log_file( const std::string & ); +void fe_set_log_level( enum FeLogLevel ); +void fe_print_version(); + class FeBaseConfigurable { protected: diff --git a/src/fe_cmdline.cpp b/src/fe_cmdline.cpp index f82c479ed..3612e1309 100644 --- a/src/fe_cmdline.cpp +++ b/src/fe_cmdline.cpp @@ -29,7 +29,9 @@ void process_args( int argc, char *argv[], std::string &config_path, std::string &cmdln_font, - bool &process_console ) + bool &process_console, + std::string &log_file, + FeLogLevel &log_level ) { // // Deal with command line arguments @@ -54,7 +56,7 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no config directory specified with --config option." << std::endl; + FeLog() << "Error, no config directory specified with --config option." << std::endl; exit(1); } } @@ -69,10 +71,58 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no font name specified with --font option." << std::endl; + FeLog() << "Error, no font name specified with --font option." << std::endl; exit(1); } } + else if ( strcmp( argv[next_arg], "--logfile" ) == 0 ) + { + next_arg++; + if ( next_arg < argc ) + { + log_file = argv[next_arg]; + next_arg++; + } + else + { + FeLog() << "Error, no log file specified with --log option." << std::endl; + exit(1); + } + } + else if ( strcmp( argv[next_arg], "--loglevel" ) == 0 ) + { + next_arg++; + if ( next_arg < argc ) + { + if ( strcmp( argv[next_arg], "silent" ) == 0 ) + { + log_level = FeLog_Silent; + next_arg++; + } + else if ( strcmp( argv[next_arg], "info" ) == 0 ) + { + log_level = FeLog_Info; + next_arg++; + } + else if ( strcmp( argv[next_arg], "debug" ) == 0 ) + { + log_level = FeLog_Debug; + next_arg++; + } + else + { + FeLog() << "Unreconized loglevel: " << argv[next_arg] << std::endl; + exit( 1 ); + } + } + else + { + FeLog() << "Error, no log level specified with --loglevel option." << std::endl; + exit(1); + } + + next_arg++; + } else if (( strcmp( argv[next_arg], "-b" ) == 0 ) || ( strcmp( argv[next_arg], "--build-romlist" ) == 0 )) { @@ -89,7 +139,7 @@ void process_args( int argc, char *argv[], if ( next_arg == first_cmd_arg ) { - std::cerr << "Error, no target emulators specified with --build-romlist option." + FeLog() << "Error, no target emulators specified with --build-romlist option." << std::endl; exit(1); } @@ -108,7 +158,7 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no filename specified with --import-romlist option." << std::endl; + FeLog() << "Error, no filename specified with --import-romlist option." << std::endl; exit(1); } @@ -131,7 +181,7 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no output filename specified with --output option." << std::endl; + FeLog() << "Error, no output filename specified with --output option." << std::endl; exit(1); } } @@ -157,7 +207,7 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no rule specified with --filter option." << std::endl; + FeLog() << "Error, no rule specified with --filter option." << std::endl; exit(1); } @@ -180,7 +230,7 @@ void process_args( int argc, char *argv[], } else { - std::cerr << "Error, no exception specified with --exception option." << std::endl; + FeLog() << "Error, no exception specified with --exception option." << std::endl; exit(1); } @@ -202,7 +252,7 @@ void process_args( int argc, char *argv[], if ( next_arg == first_cmd_arg ) { - std::cerr << "Error, no target emulators specified with --scrape-art option." + FeLog() << "Error, no target emulators specified with --scrape-art option." << std::endl; exit(1); } @@ -210,37 +260,13 @@ void process_args( int argc, char *argv[], else if (( strcmp( argv[next_arg], "-v" ) == 0 ) || ( strcmp( argv[next_arg], "--version" ) == 0 )) { - std::cout << FE_NAME << " " << FE_VERSION << " (" - << get_OS_string() - << ", SFML " << SFML_VERSION_MAJOR << '.' << SFML_VERSION_MINOR -#ifdef USE_FONTCONFIG - << " +FontConfig" -#endif -#ifdef USE_XINERAMA - << " +Xinerama" -#endif -#ifdef USE_GLES - << " +GLES" -#endif -#ifndef NO_SWF - << " +SWF" -#endif -#ifdef USE_LIBARCHIVE - << " +7z" -#endif - << ") " << std::endl << std::endl; - -#ifdef NO_MOVIE - std::cout << "No Video, using SFML for Audio." << std::endl; -#else - print_ffmpeg_version_info(); -#endif - std::cout << std::endl; + fe_print_version(); + FeLog() << std::endl; if ( sf::Shader::isAvailable() ) - std::cout << "Shaders are available." << std::endl; + FeLog() << "Shaders are available." << std::endl; else - std::cout << "Shaders are not available." << std::endl; + FeLog() << "Shaders are not available." << std::endl; exit(0); } @@ -257,12 +283,12 @@ void process_args( int argc, char *argv[], if (( strcmp( argv[next_arg], "-h" ) != 0 ) && ( strcmp( argv[next_arg], "--help" ) != 0 )) { - std::cerr << "Unrecognized command line option: " + FeLog() << "Unrecognized command line option: " << argv[next_arg] << std::endl; retval=0; } - std::cout << FE_COPYRIGHT << std::endl + FeLog() << FE_COPYRIGHT << std::endl << "Usage: " << argv[0] << " [option...]" << std::endl << std::endl << "ROMLIST IMPORT/BUILD OPTIONS:" << std::endl << " -b, --build-romlist [emu(s)...]" << std::endl @@ -291,6 +317,10 @@ void process_args( int argc, char *argv[], << " Specify the configuration to use" << std::endl << " -f, --font " << std::endl << " Specify the default font to use" << std::endl + << " --logfile " << std::endl + << " Write log info to the specified file" << std::endl + << " --loglevel (silent,info,debug)" << std::endl + << " Set logging level" << std::endl #ifndef SFML_SYSTEM_WINDOWS << " --console" << std::endl << " Enable script console" << std::endl diff --git a/src/fe_image.cpp b/src/fe_image.cpp index bd0e58099..9970ded60 100644 --- a/src/fe_image.cpp +++ b/src/fe_image.cpp @@ -313,7 +313,7 @@ bool FeTextureContainer::load_with_ffmpeg( if ( !res ) { - std::cout << "ERROR loading video: " + FeLog() << "ERROR loading video: " << loaded_name << std::endl; delete m_movie; @@ -361,7 +361,7 @@ bool FeTextureContainer::try_to_load( if (!m_swf->open_from_archive( path, filename )) { - std::cout << " ! ERROR loading SWF from archive: " + FeLog() << " ! ERROR loading SWF from archive: " << path << " (" << filename << ")" << std::endl; delete m_swf; @@ -378,7 +378,7 @@ bool FeTextureContainer::try_to_load( m_swf = new FeSwf(); if (!m_swf->open_from_file( loaded_name )) { - std::cout << " ! ERROR loading SWF: " + FeLog() << " ! ERROR loading SWF: " << loaded_name << std::endl; delete m_swf; @@ -493,7 +493,8 @@ void FeTextureContainer::internal_update_selection( FeSettings *feSettings ) && ( m_current_filter_index == filter_index )) { #ifdef FE_DEBUG - std::cout << "Optimization: " << m_file_name << " not loaded." << std::endl; + FeDebug() << "Texture internal update optimization: " << m_file_name + << " not reloaded." << std::endl; #endif return; } diff --git a/src/fe_info.cpp b/src/fe_info.cpp index 186eba1b8..127a43d38 100644 --- a/src/fe_info.cpp +++ b/src/fe_info.cpp @@ -151,7 +151,7 @@ void FeRomInfo::update_stats( const std::string &path, int count_incr, int playe if ( !myfile.is_open() ) { - std::cerr << "Error writing stat file: " << filename << std::endl; + FeLog() << "Error writing stat file: " << filename << std::endl; return; } @@ -284,7 +284,7 @@ void FeRule::init() (const SQChar *)m_filter_what.c_str(), &err ); if ( !m_rex ) - std::cout << "Error compiling regular expression \"" + FeLog() << "Error compiling regular expression \"" << m_filter_what << "\": " << err << std::endl; } @@ -1087,9 +1087,7 @@ int FeEmulatorInfo::process_setting( const std::string &setting, void FeEmulatorInfo::save( const std::string &filename ) const { -#ifdef FE_DEBUG - std::cout << "Writing emulator config to: " << filename << std::endl; -#endif + FeLog() << "Writing emulator config to: " << filename << std::endl; std::ofstream outfile( filename.c_str() ); if ( outfile.is_open() ) diff --git a/src/fe_input.cpp b/src/fe_input.cpp index 782cc95f0..9c9ebc8df 100644 --- a/src/fe_input.cpp +++ b/src/fe_input.cpp @@ -118,13 +118,11 @@ namespace g_joy_femap[i] = i; #endif -#ifdef FE_DEBUG - std::cout << "Joysticks after mapping: " << std::endl; + FeDebug() << "Joysticks after mapping: " << std::endl; for ( i=0; i Joy" << g_joyfemap[i] << "(" + FeDebug() << "ID: " << i << " => Joy" << g_joyfemap[i] << "(" << sf::Joystick::getIdentification(i).name.toAnsiString() << ")" << std::endl; -#endif } }; @@ -1307,7 +1305,7 @@ int FeInputMap::process_setting( const std::string &setting, FeInputMapEntry new_entry( value, cmd ); if ( new_entry.inputs.empty() ) { - std::cout << "Unrecognized input type: " << value << " in file: " << fn << std::endl; + FeLog() << "Unrecognized input type: " << value << " in file: " << fn << std::endl; return 1; } diff --git a/src/fe_net.cpp b/src/fe_net.cpp index af1884d00..6c14a5326 100644 --- a/src/fe_net.cpp +++ b/src/fe_net.cpp @@ -21,6 +21,7 @@ */ #include "fe_net.hpp" +#include "fe_base.hpp" #include #include @@ -83,7 +84,7 @@ bool FeNetTask::do_task( sf::Http::Response::Status &status ) std::ofstream outfile( m_filename.c_str(), std::ios_base::binary ); if ( !outfile.is_open() ) { - std::cerr << " ! Unable to open file for writing: " + FeLog() << " ! Unable to open file for writing: " << m_filename << std::endl; return false; } @@ -221,7 +222,7 @@ void FeNetWorker::work_process() if (( status != sf::Http::Response::Ok ) && ( status != sf::Http::Response::NotFound )) { - std::cerr << " ! Error processing request. Status code: " + FeLog() << " ! Error processing request. Status code: " << status << " (" << err_req << ")" << std::endl; } diff --git a/src/fe_present.cpp b/src/fe_present.cpp index 21ef7b031..bc2b16036 100644 --- a/src/fe_present.cpp +++ b/src/fe_present.cpp @@ -1022,7 +1022,7 @@ void FePresent::load_layout( bool initial_load ) if ( empty_layout ) { - std::cout << " - Layout is empty, initializing with the default layout settings" << std::endl; + FeLog() << " - Layout is empty, initializing with the default layout settings" << std::endl; init_with_default_layout(); } diff --git a/src/fe_romlist.cpp b/src/fe_romlist.cpp index 2458ea0d4..8a3e795f5 100644 --- a/src/fe_romlist.cpp +++ b/src/fe_romlist.cpp @@ -48,7 +48,7 @@ void FeRomListSorter::init_title_rex( const std::string &re_mask ) (const SQChar *)re_mask.c_str(), &err ); if ( !m_rex ) - std::cout << "Error compiling regular expression \"" + FeLog() << "Error compiling regular expression \"" << re_mask << "\": " << err << std::endl; } @@ -363,7 +363,7 @@ bool FeRomList::load_romlist( const std::string &path, (*it).load_stats( stat_path ); } - std::cout << " - Loaded master romlist '" << m_romlist_name + FeLog() << " - Loaded master romlist '" << m_romlist_name << "' in " << load_timer.getElapsedTime().asMilliseconds() << " ms (" << m_list.size() << " entries kept, " << m_global_filtered_out_count << " discarded)" << std::endl; @@ -448,7 +448,7 @@ void FeRomList::create_filters( } } - std::cout << " - Constructed " << filters_count << " filters in " + FeLog() << " - Constructed " << filters_count << " filters in " << load_timer.getElapsedTime().asMilliseconds() << " ms (" << filters_count * m_list.size() << " comparisons)" << std::endl; } diff --git a/src/fe_settings.cpp b/src/fe_settings.cpp index 5765606cc..096aba721 100644 --- a/src/fe_settings.cpp +++ b/src/fe_settings.cpp @@ -312,13 +312,13 @@ void FeSettings::load() if (( FE_DATA_PATH != NULL ) && ( !directory_exists( FE_DATA_PATH ) )) { - std::cerr << "Warning: Attract-Mode was compiled to look for its default configuration files in: " + FeLog() << "Warning: Attract-Mode was compiled to look for its default configuration files in: " << FE_DATA_PATH << ", which is not available." << std::endl; } if ( load_from_file( filename ) == false ) { - std::cout << "Config file not found: " << filename << ", performing initial setup." << std::endl; + FeLog() << "Config file not found: " << filename << ", performing initial setup." << std::endl; // // If there is no config file, then we do some initial setting up of the FE here, prompt @@ -347,7 +347,7 @@ void FeSettings::load() // if ( !file_exists( to ) ) { - std::cout << "Copying: '" << from << "' to '" << to_path << "'" << std::endl; + FeLog() << "Copying: '" << from << "' to '" << to_path << "'" << std::endl; std::ifstream src( from.c_str() ); std::ofstream dst( to.c_str() ); @@ -358,7 +358,7 @@ void FeSettings::load() } else { - std::cout << "Config: " << filename << std::endl; + FeLog() << "Config: " << filename << std::endl; if ( m_language.empty() ) m_language = "en"; @@ -619,7 +619,7 @@ void FeSettings::init_display() return; } - std::cout << std::endl << "*** Initializing display: '" << get_current_display_title() << "'" << std::endl; + FeLog() << std::endl << "*** Initializing display: '" << get_current_display_title() << "'" << std::endl; std::string stat_path; if ( m_track_usage ) @@ -647,7 +647,7 @@ void FeSettings::init_display() user_path, stat_path, m_displays[m_current_display] ) == false ) - std::cerr << "Error opening romlist: " << romlist_name << std::endl; + FeLog() << "Error opening romlist: " << romlist_name << std::endl; // // Construct our display index views here, for lack of a better spot @@ -1064,7 +1064,7 @@ bool FeSettings::get_path( } else { - std::cerr << "Error loading screensaver: " << FE_SCREENSAVER_FILE + FeLog() << "Error loading screensaver: " << FE_SCREENSAVER_FILE << std::endl; return false; } @@ -1518,7 +1518,7 @@ bool FeSettings::load_game_extras( } if ( game_extra_strings[i] == NULL ) - std::cerr << " ! Unrecognized game setting: " << s << " " << v << std::endl; + FeLog() << " ! Unrecognized game setting: " << s << " " << v << std::endl; } } @@ -1850,7 +1850,7 @@ bool FeSettings::get_sound_file( FeInputMap::Command c, std::string &s, bool ful { if ( !internal_resolve_config_file( m_config_path, s, FE_SOUND_SUBDIR, filename ) ) { - std::cerr << "Sound file not found: " << filename << std::endl; + FeLog() << "Sound file not found: " << filename << std::endl; return false; } } @@ -2002,7 +2002,7 @@ void FeSettings::run( int &minimum_run_seconds, romfilename = rom_path + rom_name + extension; - std::cerr << "Warning: could not locate rom. Best guess: " + FeLog() << "Warning: could not locate rom. Best guess: " << romfilename << std::endl; } @@ -2042,16 +2042,16 @@ void FeSettings::run( int &minimum_run_seconds, } if ( !work_dir.empty() ) - std::cout << " - Working directory: " << work_dir << std::endl; + FeLog() << " - Working directory: " << work_dir << std::endl; - std::cout << "*** Running: " << command << " " << args << std::endl; + FeLog() << "*** Running: " << command << " " << args << std::endl; std::string exit_hotkey = emu->get_info( FeEmulatorInfo::Exit_hotkey ); #if defined(SFML_SYSTEM_LINUX) && defined(USE_XLIB) if ( !exit_hotkey.empty() && ( m_window_mode == Fullscreen )) { - std::cout << " ! NOTE: The 'Exit Hotkey' setting is not supported when running Attract-Mode in 'Fullscreen Mode' on Linux." + FeLog() << " ! NOTE: The 'Exit Hotkey' setting is not supported when running Attract-Mode in 'Fullscreen Mode' on Linux." << " Configured exit hotkey of '" << exit_hotkey << "' is being ignored." << std::endl; exit_hotkey.clear(); @@ -3010,9 +3010,7 @@ void FeSettings::save() const std::string filename( m_config_path ); filename += FE_CFG_FILE; -#ifdef FE_DEBUG - std::cout << "Writing config to: " << filename << std::endl; -#endif + FeLog() << "Writing config to: " << filename << std::endl; std::ofstream outfile( filename.c_str() ); if ( outfile.is_open() ) @@ -3223,7 +3221,7 @@ void FeSettings::get_plugin_full_path( } - std::cerr << "Plugin file not found: " << label << std::endl; + FeLog() << "Plugin file not found: " << label << std::endl; } void FeSettings::get_plugin_full_path( int id, @@ -3244,7 +3242,7 @@ void FeSettings::internal_load_language( const std::string &lang ) if ( internal_resolve_config_file( m_config_path, fname, FE_LANGUAGE_SUBDIR, lang + FE_LANGUAGE_FILE_EXTENSION ) ) m_resourcemap.load_from_file( fname, ";" ); else - std::cerr << "Error loading language resource file: " << lang << std::endl; + FeLog() << "Error loading language resource file: " << lang << std::endl; } void FeSettings::set_language( const std::string &s ) diff --git a/src/fe_sound.cpp b/src/fe_sound.cpp index fb07fcdc1..1b3e4597b 100644 --- a/src/fe_sound.cpp +++ b/src/fe_sound.cpp @@ -142,7 +142,7 @@ void FeSound::load( const std::string &path, const std::string &fn ) #ifndef NO_MOVIE if ( !m_sound.openFromArchive( path, fn ) ) { - std::cout << "Error loading sound file from archive: " + FeLog() << "Error loading sound file from archive: " << path << " (" << fn << ")" << std::endl; m_file_name = ""; return; @@ -152,7 +152,7 @@ void FeSound::load( const std::string &path, const std::string &fn ) if ( !m_zip.open( fn ) ) { - std::cout << "Error loading sound file from archive: " + FeLog() << "Error loading sound file from archive: " << path << " (" << fn << ")" << std::endl; m_file_name = ""; return; @@ -160,7 +160,7 @@ void FeSound::load( const std::string &path, const std::string &fn ) if ( !m_sound.openFromStream( m_zip ) ) { - std::cout << "Error loading sound file: " << fn + FeLog() << "Error loading sound file: " << fn << std::endl; m_file_name = ""; return; @@ -174,7 +174,7 @@ void FeSound::load( const std::string &path, const std::string &fn ) std::string file_to_load = path + fn; if ( !m_sound.openFromFile( file_to_load ) ) { - std::cout << "Error loading sound file: " << file_to_load << std::endl; + FeLog() << "Error loading sound file: " << file_to_load << std::endl; m_file_name = ""; return; } diff --git a/src/fe_util.cpp b/src/fe_util.cpp index 818529a89..52a26709c 100755 --- a/src/fe_util.cpp +++ b/src/fe_util.cpp @@ -821,7 +821,7 @@ bool run_program( const std::string &prog, if ( ret == false ) { - std::cerr << "Error executing command: '" << comstr << "'" << std::endl; + FeLog() << "Error executing command: '" << comstr << "'" << std::endl; return false; } @@ -885,7 +885,7 @@ bool run_program( const std::string &prog, break; default: - std::cerr << "Unexpected failure waiting on process" << std::endl; + FeLog() << "Unexpected failure waiting on process" << std::endl; keep_wait=false; break; } @@ -915,13 +915,13 @@ bool run_program( const std::string &prog, int mypipe[2] = { 0, 0 }; // mypipe[0] = read end, mypipe[1] = write end if (( NULL != callback ) && block && ( pipe( mypipe ) )) - std::cerr << "Error, pipe() failed" << std::endl; + FeLog() << "Error, pipe() failed" << std::endl; pid_t pid = fork(); switch (pid) { case -1: - std::cerr << "Error, fork() failed" << std::endl; + FeLog() << "Error, fork() failed" << std::endl; if ( mypipe[0] ) { close( mypipe[0] ); @@ -937,12 +937,12 @@ bool run_program( const std::string &prog, } if ( !work_dir.empty() && ( chdir( work_dir.c_str() ) != 0 ) ) - std::cerr << "Warning, chdir(" << work_dir << ") failed."; + FeLog() << "Warning, chdir(" << work_dir << ") failed."; execvp( prog.c_str(), arg_list ); // execvp doesn't return unless there is an error. - std::cerr << "Error executing: " << prog << " " << args << std::endl; + FeLog() << "Error executing: " << prog << " " << args << std::endl; _exit(127); default: // parent process @@ -1000,7 +1000,7 @@ bool run_program( const std::string &prog, sf::sleep( sf::milliseconds( 100 ) ); if ( kill( pid, 0 ) == 0 ) { - std::cout << " - Exit Hotkey pressed, sending SIGTERM signal to process " << pid << std::endl; + FeLog() << " - Exit Hotkey pressed, sending SIGTERM signal to process " << pid << std::endl; kill( pid, SIGTERM ); @@ -1021,7 +1021,7 @@ bool run_program( const std::string &prog, // if ( kill( pid, 0 ) == 0 ) { - std::cout << " - Timeout on SIGTERM after " << TERM_TIMEOUT + FeLog() << " - Timeout on SIGTERM after " << TERM_TIMEOUT << " ms, sending SIGKILL signal to process " << pid << std::endl; kill( pid, SIGKILL ); @@ -1038,7 +1038,7 @@ bool run_program( const std::string &prog, else { if ( w < 0 ) - std::cerr << " ! error returned by wait_pid(): " + FeLog() << " ! error returned by wait_pid(): " << strerror( errno ) << std::endl; break; // leave do/while loop diff --git a/src/fe_vm.cpp b/src/fe_vm.cpp index 32d182cbf..aad23ad80 100644 --- a/src/fe_vm.cpp +++ b/src/fe_vm.cpp @@ -58,10 +58,13 @@ namespace // void printFunc(HSQUIRRELVM v, const SQChar *s, ...) { + char buff[2048]; va_list vl; va_start(vl, s); - vprintf(s, vl); + vsnprintf( buff, 2048, s, vl); va_end(vl); + + FeLog() << buff; } bool my_callback( const char *buffer, void *opaque ) @@ -77,7 +80,7 @@ namespace } catch( Sqrat::Exception e ) { - std::cout << "Script Error: " << e.Message() << std::endl; + FeLog() << "Script Error: " << e.Message() << std::endl; } return false; @@ -142,7 +145,7 @@ namespace catch(Sqrat:: Exception e ) { if ( !silent ) - std::cerr << "Script Error in " << path_to_run + FeLog() << "Script Error in " << path_to_run << " - " << e.Message() << std::endl; } return true; @@ -954,7 +957,7 @@ bool FeVM::on_new_layout() m_feSettings->get_current_display_index() ); if ( di ) - std::cerr << " ! Error opening layout: " + FeLog() << " ! Error opening layout: " << di->get_info( FeDisplayInfo::Layout ) << std::endl; } else if ( !run_script( path, filename ) ) @@ -962,7 +965,7 @@ bool FeVM::on_new_layout() if ( ps == FeSettings::Intro_Showing ) return false; // silent fail if intro is not found else - std::cerr << " ! Script file not found: " << path + FeLog() << " ! Script file not found: " << path << " (" << filename << ")" << std::endl; } @@ -1000,7 +1003,7 @@ bool FeVM::on_new_layout() if ( !skip_layout && ( ps == FeSettings::Layout_Showing )) { - std::cout << " - Loaded layout: " << rep_path + FeLog() << " - Loaded layout: " << rep_path << " (" << filename << ")" << std::endl; } @@ -1038,7 +1041,7 @@ bool FeVM::process_console_input() } catch( Sqrat::Exception e ) { - std::cerr << "Error: " << script << " - " << e.Message() << std::endl; + FeLog() << "Error: " << script << " - " << e.Message() << std::endl; } return retval; @@ -1066,7 +1069,7 @@ bool FeVM::on_tick() } catch( Exception &e ) { - std::cout << "Script Error in tick function: " << (*itr).m_fn << " - " + FeLog() << "Script Error in tick function: " << (*itr).m_fn << " - " << e.Message() << std::endl; // Knock out this entry. If it causes a script error, we don't @@ -1090,9 +1093,7 @@ void FeVM::on_transition( { using namespace Sqrat; -#ifdef FE_DEBUG - std::cout << "[Transition] type=" << transitionTypeStrings[t] << ", var=" << var << std::endl; -#endif // FE_DEBUG + FeDebug() << "[Transition] type=" << transitionTypeStrings[t] << ", var=" << var << std::endl; sf::Clock ttimer; @@ -1132,7 +1133,7 @@ void FeVM::on_transition( } catch( Exception &e ) { - std::cout << "Script Error in transition function: " << (*itr)->m_fn + FeLog() << "Script Error in transition function: " << (*itr)->m_fn << " - " << e.Message() << std::endl; } @@ -1197,7 +1198,7 @@ bool FeVM::script_handle_event( FeInputMap::Command c ) } catch( Exception &e ) { - std::cout << "Script Error in signal handler: " << (*itr).m_fn << " - " + FeLog() << "Script Error in signal handler: " << (*itr).m_fn << " - " << e.Message() << std::endl; } } @@ -1358,7 +1359,7 @@ void FePresent::script_process_magic_strings( std::string &str, } catch( Sqrat::Exception &e ) { - std::cout << "Script Error in magic string function: " + FeLog() << "Script Error in magic string function: " << magic << " - " << e.Message() << std::endl; } @@ -1550,7 +1551,7 @@ void FeVM::script_run_config_function( catch( Sqrat::Exception &e ) { return_message = "Script error"; - std::cout << "Script Error in " << script_file + FeLog() << "Script Error in " << script_file << " - " << e.Message() << std::endl; } @@ -1560,7 +1561,7 @@ void FeVM::script_run_config_function( else { return_message = "Script error: Function not found"; - std::cout << "Script Error in " << script_file + FeLog() << "Script Error in " << script_file << " - Function not found: " << func_name << std::endl; } @@ -1965,7 +1966,7 @@ void FeVM::do_nut( const char *script_file ) if ( !internal_do_nut( path, script_file ) ) { - std::cerr << "Error, file not found: " << path + FeLog() << "Error, file not found: " << path << " (" << script_file << ")" << std::endl; } } @@ -2033,7 +2034,7 @@ const char *FeVM::cb_game_info( int index, int offset, int filter_offset ) { // the better thing to do would be to raise a squirrel error here // - std::cerr << "game_info(): index out of range" << std::endl; + FeLog() << "game_info(): index out of range" << std::endl; return ""; } else if ( index == FeRomInfo::LAST_INDEX ) @@ -2237,7 +2238,7 @@ void FeVM::cb_signal( const char *sig ) break; default: - std::cerr << "Error, unrecognized signal: " << sig << std::endl; + FeLog() << "Error, unrecognized signal: " << sig << std::endl; break; } diff --git a/src/fe_window.cpp b/src/fe_window.cpp index 5e911e436..6bb9f4a70 100644 --- a/src/fe_window.cpp +++ b/src/fe_window.cpp @@ -189,7 +189,7 @@ void FeWindow::initial_create() #ifdef USE_XINERAMA if ( m_fes.get_info_bool( FeSettings::MultiMon ) && ( win_mode != FeSettings::Default )) - std::cout << " ! NOTE: Use the 'Fill Screen' window mode if you want multiple monitor support to function correctly" << std::endl; + FeLog() << " ! NOTE: Use the 'Fill Screen' window mode if you want multiple monitor support to function correctly" << std::endl; #endif // Create window diff --git a/src/main.cpp b/src/main.cpp index 309e71533..6b0d5ebe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ /* * * Attract-Mode frontend - * Copyright (C) 2013-15 Andrew Mickelson + * Copyright (C) 2013-17 Andrew Mickelson * * This file is part of Attract-Mode. * @@ -51,35 +51,54 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; void process_args( int argc, char *argv[], std::string &config_path, std::string &cmdln_font, - bool &process_console ); + bool &process_console, + std::string &log_file, + FeLogLevel &log_level ); int main(int argc, char *argv[]) { - std::string config_path, cmdln_font; + std::string config_path, cmdln_font, log_file; bool launch_game = false; bool process_console = false; + FeLogLevel log_level = FeLog_Info; - process_args( argc, argv, config_path, cmdln_font, process_console ); + process_args( argc, argv, config_path, cmdln_font, process_console, log_file, log_level ); + + FeSettings feSettings( config_path, cmdln_font ); // - // Run the front-end + // Setup logging // - std::cout << "Starting " << FE_NAME << " " << FE_VERSION - << " (" << get_OS_string() << ")"; - - if ( process_console ) - std::cout << ", Script Console Enabled"; +#if defined(SFML_SYSTEM_WINDOWS) && !defined(WINDOWS_CONSOLE) + if ( log_file.empty() ) // on windows non-console version, write log to "last_run.log" by default + { + log_file = feSettings.get_config_dir(); + log_file += "last_run.log"; + } +#endif + // + // If a log file was supplied at the command line, write to that log file + // If no file is supplied, logging is to stdout + // + if ( !log_file.empty() ) + fe_set_log_file( clean_path( log_file ) ); - std::cout << std::endl; + // The following call also initializes the log callback for ffmpeg and gameswf + // + fe_set_log_level( log_level ); - FeSettings feSettings( config_path, cmdln_font ); + // + // Run the front-end + // + fe_print_version(); + FeLog() << std::endl; feSettings.load(); std::string def_font_path, def_font_file; if ( feSettings.get_font_file( def_font_path, def_font_file ) == false ) { - std::cerr << "Error, could not find default font." << std::endl; + FeLog() << "Error, could not find default font." << std::endl; return 1; } @@ -238,7 +257,7 @@ int main(int argc, char *argv[]) if ( index < 0 ) { - std::cerr << "Error resolving shortcut, Display `" << name << "' not found." << std::endl; + FeLog() << "Error resolving shortcut, Display `" << name << "' not found." << std::endl; } else { @@ -397,6 +416,9 @@ int main(int argc, char *argv[]) // if ( feVM.script_handle_event( c ) ) { + FeDebug() << "Command intercepted by script handler: " + << FeInputMap::commandStrings[c] << std::endl; + redraw=true; continue; } @@ -448,6 +470,9 @@ int main(int argc, char *argv[]) // if ( feVM.script_handle_event( c ) ) { + FeDebug() << "Command intercepted by script handler: " + << FeInputMap::commandStrings[c] << std::endl; + redraw=true; continue; } @@ -484,6 +509,8 @@ int main(int argc, char *argv[]) // // Default command handling // + FeDebug() << "Handling command: " << FeInputMap::commandStrings[c] << std::endl; + soundsys.sound_event( c ); if ( feVM.handle_event( c ) ) redraw = true; @@ -960,5 +987,6 @@ int main(int argc, char *argv[]) soundsys.stop(); feSettings.save_state(); + FeDebug() << "Attract-Mode ended normally" << std::endl; return 0; } diff --git a/src/media.cpp b/src/media.cpp index 1401fe562..b762e57b3 100644 --- a/src/media.cpp +++ b/src/media.cpp @@ -22,6 +22,7 @@ #include "media.hpp" #include "zip.hpp" +#include "fe_base.hpp" #include #include @@ -74,11 +75,7 @@ extern "C" void print_ffmpeg_version_info() { - std::cout << "Using " - << (( LIBAVCODEC_VERSION_MICRO >= 100 ) ? "FFmpeg" : "Libav" ) - << " for Audio and Video." << std::endl - - << "avcodec " << LIBAVCODEC_VERSION_MAJOR + FeLog() << "avcodec " << LIBAVCODEC_VERSION_MAJOR << '.' << LIBAVCODEC_VERSION_MINOR << '.' << LIBAVCODEC_VERSION_MICRO @@ -91,11 +88,11 @@ void print_ffmpeg_version_info() << '.' << LIBSWSCALE_VERSION_MICRO; #ifdef DO_RESAMPLE - std::cout << RESAMPLE_LIB_STR << RESAMPLE_VERSION_MAJOR + FeLog() << RESAMPLE_LIB_STR << RESAMPLE_VERSION_MAJOR << '.' << RESAMPLE_VERSION_MINOR << '.' << RESAMPLE_VERSION_MICRO; #endif - std::cout << std::endl; + FeLog() << std::endl; } #define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio @@ -402,7 +399,7 @@ enum AVPixelFormat hw_get_output_format( AVBufferRef *hw_frames_ctx ) &p, 0 ); if ( e < 0 ) - std::cerr << "Error getting supported hardware formats." << std::endl; + FeLog() << "Error getting supported hardware formats." << std::endl; else retval = *p; @@ -423,21 +420,20 @@ bool FeVideoImp::hw_retrieve_data( AVFrame *f ) if ( hwaccel_output_format == AV_PIX_FMT_NONE ) { hwaccel_output_format = hw_get_output_format( codec_ctx->hw_frames_ctx ); -#ifdef FE_DEBUG - std::cout << "HWAccel output pixel format: " + + FeDebug() << "HWAccel output pixel format: " << av_pix_fmt_desc_get( hwaccel_output_format )->name << std::endl; -#endif } sw_frame->format = hwaccel_output_format; int err = av_hwframe_transfer_data( sw_frame, f, 0 ); if ( err < 0 ) - std::cerr << "Error transferring hardware frame data." << std::endl; + FeLog() << "Error transferring hardware frame data." << std::endl; err = av_frame_copy_props( sw_frame, f ); if ( err < 0 ) - std::cerr << "Error copying hardware frame properties." << std::endl; + FeLog() << "Error copying hardware frame properties." << std::endl; av_frame_unref( f ); av_frame_move_ref( f, sw_frame ); @@ -503,7 +499,7 @@ void FeVideoImp::preload() AV_PIX_FMT_RGBA, 1); if (ret < 0) { - std::cerr << "Error allocating image during preload" << std::endl; + FeLog() << "Error allocating image during preload" << std::endl; return; } } @@ -537,7 +533,7 @@ void FeVideoImp::preload() if ( len < 0 ) { - std::cerr << "Error decoding video" << std::endl; + FeLog() << "Error decoding video" << std::endl; keep_going=false; } @@ -560,7 +556,7 @@ void FeVideoImp::preload() if ( !sws_ctx ) { - std::cerr << "Error allocating SwsContext during preload" << std::endl; + FeLog() << "Error allocating SwsContext during preload" << std::endl; free_frame( raw_frame ); free_packet( packet ); return; @@ -593,7 +589,7 @@ void FeVideoImp::video_thread() if ((!sws_ctx) || (!rgba_buffer[0])) { - std::cerr << "Error initializing video thread" << std::endl; + FeLog() << "Error initializing video thread" << std::endl; goto the_end; } @@ -707,7 +703,7 @@ void FeVideoImp::video_thread() int len = avcodec_decode_video2( codec_ctx, raw_frame, &got_frame, packet ); if ( len < 0 ) - std::cerr << "Error decoding video" << std::endl; + FeLog() << "Error decoding video" << std::endl; if ( got_frame ) { @@ -762,18 +758,15 @@ void FeVideoImp::video_thread() if ( detached_frame ) free_frame( detached_frame ); -#ifdef FE_DEBUG - int total_shown = displayed + discarded; int average = ( total_shown == 0 ) ? qscore_accum : ( qscore_accum / total_shown ); - std::cout << "End Video Thread - " << m_parent->m_imp->m_format_ctx->filename << std::endl + FeDebug() << "End Video Thread - " << m_parent->m_imp->m_format_ctx->filename << std::endl << " - bit_rate=" << codec_ctx->bit_rate << ", width=" << codec_ctx->width << ", height=" << codec_ctx->height << std::endl << " - displayed=" << displayed << ", discarded=" << discarded << std::endl << " - average qscore=" << average << std::endl; -#endif } FeMedia::FeMedia( Type t ) @@ -799,11 +792,6 @@ void FeMedia::init_av() { avcodec_register_all(); av_register_all(); - -#ifndef FE_DEBUG - av_log_set_level(AV_LOG_FATAL); -#endif - do_init=false; } } @@ -914,7 +902,7 @@ bool FeMedia::openFromFile( const std::string &name, sf::Texture *outt ) if ( avformat_open_input( &(m_imp->m_format_ctx), name.c_str(), NULL, NULL ) < 0 ) { - std::cerr << "Error opening input file: " << name << std::endl; + FeLog() << "Error opening input file: " << name << std::endl; return false; } @@ -964,8 +952,18 @@ bool FeMedia::openFromArchive( const std::string &archive, FeZipStream *z = new FeZipStream( archive ); if ( !z->open( name ) ) { - delete z; - return false; + // Error opening specified filename. Try to correct + // in case filname is in a subdir of the archive + std::string temp; + if ( get_archive_filename_with_base( temp, archive, name ) ) + { + z->open( temp ); + } + else + { + delete z; + return false; + } } m_imp->m_format_ctx = avformat_alloc_context(); @@ -986,7 +984,7 @@ bool FeMedia::openFromArchive( const std::string &archive, if ( avformat_open_input( &(m_imp->m_format_ctx), name.c_str(), NULL, NULL ) < 0 ) { - std::cerr << "Error opening input file: " << name << std::endl; + FeLog() << "Error opening input file: " << name << std::endl; return false; } @@ -997,7 +995,7 @@ bool FeMedia::internal_open( sf::Texture *outt ) { if ( avformat_find_stream_info( m_imp->m_format_ctx, NULL ) < 0 ) { - std::cerr << "Error finding stream information in input file: " + FeLog() << "Error finding stream information in input file: " << m_imp->m_format_ctx->filename << std::endl; return false; } @@ -1016,7 +1014,7 @@ bool FeMedia::internal_open( sf::Texture *outt ) if ( avcodec_open2( codec_ctx, dec, NULL ) < 0 ) { - std::cerr << "Could not open audio decoder for file: " + FeLog() << "Could not open audio decoder for file: " << m_imp->m_format_ctx->filename << std::endl; } else @@ -1044,7 +1042,7 @@ bool FeMedia::internal_open( sf::Texture *outt ) #ifndef DO_RESAMPLE if ( codec_ctx->sample_fmt != AV_SAMPLE_FMT_S16 ) { - std::cerr << "Warning: Attract-Mode was compiled without an audio resampler (libswresample or libavresample)." << std::endl + FeLog() << "Warning: Attract-Mode was compiled without an audio resampler (libswresample or libavresample)." << std::endl << "The audio format in " << m_imp->m_format_ctx->filename << " appears to need resampling. It will likely sound like garbage." << std::endl; } #endif @@ -1061,7 +1059,7 @@ bool FeMedia::internal_open( sf::Texture *outt ) if ( stream_id < 0 ) { - std::cout << "No video stream found, file: " + FeLog() << "No video stream found, file: " << m_imp->m_format_ctx->filename << std::endl; } else @@ -1076,7 +1074,7 @@ bool FeMedia::internal_open( sf::Texture *outt ) if ( avcodec_open2( codec_ctx, dec, NULL ) < 0 ) { - std::cerr << "Could not open video decoder for file: " + FeLog() << "Could not open video decoder for file: " << m_imp->m_format_ctx->filename << std::endl; } else @@ -1209,7 +1207,7 @@ bool FeMedia::onGetData( Chunk &data ) (m_audio->buffer + offset), &bsize, packet) < 0 ) { - std::cerr << "Error decoding audio." << std::endl; + FeLog() << "Error decoding audio." << std::endl; FeBaseStream::free_packet( packet ); return false; } @@ -1235,11 +1233,9 @@ bool FeMedia::onGetData( Chunk &data ) int len = avcodec_decode_audio4( m_audio->codec_ctx, frame, &got_frame, packet ); if ( len < 0 ) { -#ifdef FE_DEBUG char buff[256]; av_strerror( len, buff, 256 ); - std::cerr << "Error decoding audio: " << buff << std::endl; -#endif + FeDebug() << "Error decoding audio: " << buff << std::endl; } if ( got_frame ) @@ -1271,7 +1267,7 @@ bool FeMedia::onGetData( Chunk &data ) m_audio->resample_ctx = resample_alloc(); if ( !m_audio->resample_ctx ) { - std::cerr << "Error allocating audio format converter." << std::endl; + FeLog() << "Error allocating audio format converter." << std::endl; FeBaseStream::free_packet( packet ); FeBaseStream::free_frame( frame ); return false; @@ -1291,16 +1287,15 @@ bool FeMedia::onGetData( Chunk &data ) av_opt_set_int( m_audio->resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0 ); av_opt_set_int( m_audio->resample_ctx, "out_sample_rate", frame->sample_rate, 0 ); -#ifdef FE_DEBUG - std::cout << "Initializing resampler: in_sample_fmt=" + FeDebug() << "Initializing resampler: in_sample_fmt=" << av_get_sample_fmt_name( (AVSampleFormat)frame->format ) << ", in_sample_rate=" << frame->sample_rate << ", out_sample_fmt=" << av_get_sample_fmt_name( AV_SAMPLE_FMT_S16 ) << ", out_sample_rate=" << frame->sample_rate << std::endl; -#endif + if ( resample_init( m_audio->resample_ctx ) < 0 ) { - std::cerr << "Error initializing audio format converter, input format=" + FeLog() << "Error initializing audio format converter, input format=" << av_get_sample_fmt_name( (AVSampleFormat)frame->format ) << ", input sample rate=" << frame->sample_rate << std::endl; FeBaseStream::free_packet( packet ); @@ -1340,7 +1335,7 @@ bool FeMedia::onGetData( Chunk &data ) #endif if ( out_samples < 0 ) { - std::cerr << "Error performing audio conversion." << std::endl; + FeLog() << "Error performing audio conversion." << std::endl; FeBaseStream::free_packet( packet ); FeBaseStream::free_frame( frame ); break; diff --git a/src/media_dxva2.cpp b/src/media_dxva2.cpp index b9f94932a..3632eb118 100644 --- a/src/media_dxva2.cpp +++ b/src/media_dxva2.cpp @@ -38,7 +38,7 @@ enum AVPixelFormat get_format_dxva2( AVCodecContext *codec_ctx, const enum AVPix if ( ret < 0 ) { - std::cerr << "Error creating dxva2 hardware device context" << std::endl; + FeLog() << "Error creating dxva2 hardware device context" << std::endl; continue; } @@ -71,7 +71,7 @@ enum AVPixelFormat get_format_dxva2( AVCodecContext *codec_ctx, const enum AVPix if ( ret < 0 ) { - std::cerr << "Error initializing dxva2 hardware frame context" << std::endl; + FeLog() << "Error initializing dxva2 hardware frame context" << std::endl; av_buffer_unref( &device_ctx ); av_buffer_unref( &frames_ctx ); continue; diff --git a/src/media_vaapi.cpp b/src/media_vaapi.cpp index 7214562c7..8f89d8949 100644 --- a/src/media_vaapi.cpp +++ b/src/media_vaapi.cpp @@ -39,7 +39,7 @@ enum AVPixelFormat get_format_vaapi( AVCodecContext *codec_ctx, const enum AVPix if ( ret < 0 ) { - std::cerr << "Error creating vaapi hardware device context" << std::endl; + FeLog() << "Error creating vaapi hardware device context" << std::endl; continue; } @@ -68,7 +68,7 @@ enum AVPixelFormat get_format_vaapi( AVCodecContext *codec_ctx, const enum AVPix if ( ret < 0 ) { - std::cerr << "Error initializing vaapi hardware frame context" << std::endl; + FeLog() << "Error initializing vaapi hardware frame context" << std::endl; av_buffer_unref( &device_ctx ); av_buffer_unref( &frames_ctx ); continue; diff --git a/src/scraper_general.cpp b/src/scraper_general.cpp index 3cc3a6b23..5d095bbb9 100644 --- a/src/scraper_general.cpp +++ b/src/scraper_general.cpp @@ -53,14 +53,14 @@ void build_basic_romlist( FeImporterContext &c ) c.romlist.push_back( new_rom ); } - std::cout << " - Found " << names.size() << " files." << std::endl; + FeLog() << " - Found " << names.size() << " files." << std::endl; } void write_romlist( const std::string &filename, const FeRomInfoListType &romlist ) { - std::cout << " + Writing " << romlist.size() << " entries to: " + FeLog() << " + Writing " << romlist.size() << " entries to: " << filename << std::endl; int i=0; @@ -176,7 +176,7 @@ void ini_import( const std::string &filename, } } - std::cout << "[Import " << filename << "] - found info for " << count + FeLog() << "[Import " << filename << "] - found info for " << count << " entries." << std::endl; } @@ -197,7 +197,7 @@ void apply_import_extras( FeImporterContext &c, bool skip_xml ) { if ( skip_xml ) { - std::cout << " - Skipping import_extras file: " + FeLog() << " - Skipping import_extras file: " << path << std::endl; } else @@ -207,7 +207,7 @@ void apply_import_extras( FeImporterContext &c, bool skip_xml ) } } else - std::cout << " * Unsupported import_extras file: " << path << std::endl; + FeLog() << " * Unsupported import_extras file: " << path << std::endl; } } @@ -237,7 +237,7 @@ bool import_mamewah( const std::string &input_filename, std::ifstream myfile( input_filename.c_str() ); if ( !myfile.is_open() ) { - std::cerr << " ! Error opening file: " << input_filename << std::endl; + FeLog() << " ! Error opening file: " << input_filename << std::endl; return false; } @@ -278,7 +278,7 @@ bool import_mamewah( const std::string &input_filename, if ( count > 1 ) { - std::cout << " * Warning: Unexpected end of file encountered: " << input_filename + FeLog() << " * Warning: Unexpected end of file encountered: " << input_filename << ", this probably means the import failed." << std::endl; } @@ -366,10 +366,10 @@ void FeSettings::apply_xml_import( FeImporterContext &c, bool include_gdb ) case FeEmulatorInfo::Listxml: { - std::cout << " - Obtaining -listxml info..."; + FeLog() << " - Obtaining -listxml info..."; FeListXMLParser mamep( c ); if ( !mamep.parse_command( base_command, work_dir ) ) - std::cerr << " ! No XML output found, command: " + FeLog() << " ! No XML output found, command: " << base_command << " -listxml" << std::endl; } break; @@ -380,7 +380,7 @@ void FeSettings::apply_xml_import( FeImporterContext &c, bool include_gdb ) const std::vector < std::string > &system_names = c.emulator.get_systems(); if ( system_names.empty() ) { - std::cout << " * Note: No system configured for emulator: " + FeLog() << " * Note: No system configured for emulator: " << c.emulator.get_info( FeEmulatorInfo::Name ) << ", unable to obtain -listsoftware info." << std::endl; @@ -462,7 +462,7 @@ void FeSettings::apply_xml_import( FeImporterContext &c, bool include_gdb ) ASSERT( !fields_left ); } else - std::cerr << " ! Error opening file: " << fname << std::endl; + FeLog() << " ! Error opening file: " << fname << std::endl; } if ( include_gdb ) @@ -501,13 +501,13 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, if ( (*itr).task_type == FeImportTask::BuildRomlist ) { // Build romlist task - std::cout << "*** Generating Collection/Rom List: " + FeLog() << "*** Generating Collection/Rom List: " << (*itr).emulator_name << std::endl; FeEmulatorInfo *emu = m_rl.get_emulator( (*itr).emulator_name ); if ( emu == NULL ) { - std::cerr << " ! Error: Invalid --build-rom-list target: " + FeLog() << " ! Error: Invalid --build-rom-list target: " << (*itr).emulator_name << std::endl; } else @@ -532,7 +532,7 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, else if ( (*itr).task_type == FeImportTask::ImportRomlist ) { // import romlist from file task - std::cout << "*** Importing Collection/Rom List: " + FeLog() << "*** Importing Collection/Rom List: " << (*itr).file_name << std::endl; FeRomInfoListType romlist; @@ -586,17 +586,17 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, } else { - std::cerr << " ! Error: Unsupported --import-rom-list file: " + FeLog() << " ! Error: Unsupported --import-rom-list file: " << (*itr).file_name << std::endl; } - std::cout << "[Import " << (*itr).file_name << "] - Imported " + FeLog() << "[Import " << (*itr).file_name << "] - Imported " << romlist.size() << " entries." << std::endl; FeEmulatorInfo *emu = m_rl.get_emulator( emu_name ); if ( emu == NULL ) { - std::cout << " * Warning: The emulator specified with --import-rom-list was not found: " + FeLog() << " * Warning: The emulator specified with --import-rom-list was not found: " << emu_name << std::endl; } else @@ -613,7 +613,7 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, if ( emu == NULL ) return false; - std::cout << "*** Scraping artwork for: " << (*itr).emulator_name << std::endl; + FeLog() << "*** Scraping artwork for: " << (*itr).emulator_name << std::endl; FeRomInfoListType romlist; std::string fn = get_config_dir() + FE_ROMLIST_SUBDIR + (*itr).emulator_name + FE_ROMLIST_FILE_EXTENSION; @@ -639,7 +639,7 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, general_mame_scraper( ctx ); thegamesdb_scraper( ctx ); - std::cout << "*** Scraping done." << std::endl; + FeLog() << "*** Scraping done." << std::endl; } } @@ -650,13 +650,13 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, total_romlist.sort( FeRomListSorter() ); // strip duplicate entries - std::cout << " - Removing any duplicate entries..." << std::endl; + FeLog() << " - Removing any duplicate entries..." << std::endl; total_romlist.unique(); // Apply the specified filter if ( filter.get_rule_count() > 0 ) { - std::cout << " - Applying filter..." << std::endl; + FeLog() << " - Applying filter..." << std::endl; filter.init(); FeRomInfoListType::iterator last_it=total_romlist.begin(); @@ -721,7 +721,7 @@ bool FeSettings::build_romlist( const std::vector &emu_list, const retval = true; - std::cout << "*** Generating Collection/Rom List: " + FeLog() << "*** Generating Collection/Rom List: " << emu->get_info( FeEmulatorInfo::Name ) << std::endl; FeRomInfoListType romlist; @@ -748,7 +748,7 @@ bool FeSettings::build_romlist( const std::vector &emu_list, const total_romlist.sort( FeRomListSorter() ); // strip duplicate entries - std::cout << " - Removing any duplicate entries..." << std::endl; + FeLog() << " - Removing any duplicate entries..." << std::endl; total_romlist.unique(); std::string filename = get_config_dir(); @@ -784,7 +784,7 @@ bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void if ( uiu ) uiu( uid, 0, "" ); - std::cout << "*** Scraping artwork for: " << emu_name << std::endl; + FeLog() << "*** Scraping artwork for: " << emu_name << std::endl; FeRomInfoListType romlist; @@ -826,7 +826,7 @@ bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void if ( uiu ) uiu( uid, 100, "" ); - std::cout << "*** Scraping done." << std::endl; + FeLog() << "*** Scraping done." << std::endl; if ( ctx.user_message.empty() ) get_resource( "Scraped $1 artwork file(s)", as_str( ctx.download_count ), msg ); diff --git a/src/scraper_net.cpp b/src/scraper_net.cpp index 4dac1f98a..f433237cb 100644 --- a/src/scraper_net.cpp +++ b/src/scraper_net.cpp @@ -105,7 +105,7 @@ bool process_q_simple( FeNetQueue &q, { if ( id == -1 ) { - std::cout << " + Downloaded: " << result << std::endl; + FeLog() << " + Downloaded: " << result << std::endl; c.download_count++; // find second last forward slash in filename @@ -154,7 +154,7 @@ bool FeSettings::simple_scraper( FeImporterContext &c, ParentMapType parent_map; build_parent_map( parent_map, c.romlist, false ); - std::cout << " - Scraping " << host << " [" << art_label << "]" << std::endl; + FeLog() << " - Scraping " << host << " [" << art_label << "]" << std::endl; std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name ); std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR; @@ -306,7 +306,7 @@ bool get_system_list( FeImporterContext &c, fes.get_resource( "Error getting platform list from thegamesdb.net. Code: $1", as_str( status ), c.user_message ); - std::cerr << " ! " << c.user_message << " (" << err_req << ")" << std::endl; + FeLog() << " ! " << c.user_message << " (" << err_req << ")" << std::endl; return false; } @@ -366,7 +366,7 @@ bool get_system_list( FeImporterContext &c, fes.get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.", c.user_message ); - std::cerr << " ! " << c.user_message << std::endl; + FeLog() << " ! " << c.user_message << std::endl; return false; } } @@ -463,7 +463,7 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) std::vector system_list; std::vector system_ids; - std::cout << " - scraping thegamesdb.net..." << std::endl; + FeLog() << " - scraping thegamesdb.net..." << std::endl; // // Get a list of valid platforms @@ -495,7 +495,7 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) q.do_next_task( status, err_req ); if ( status != sf::Http::Response::Ok ) { - std::cout << " * Unable to get platform information. Status code: " + FeLog() << " * Unable to get platform information. Status code: " << status << " (" << err_req << ")" << std::endl; continue; } @@ -605,7 +605,7 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) { if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask )) { - std::cout << " + Downloaded: " << result << std::endl; + FeLog() << " + Downloaded: " << result << std::endl; c.download_count++; // find second last forward slash in filename @@ -692,7 +692,7 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) q.do_next_task( status, err_req ); if ( status != sf::Http::Response::Ok ) { - std::cout << " * Error processing request. Status code: " + FeLog() << " * Error processing request. Status code: " << status << " (" << err_req << ")" << std::endl; } } diff --git a/src/scraper_xml.cpp b/src/scraper_xml.cpp index 8657fae21..38eec1cae 100644 --- a/src/scraper_xml.cpp +++ b/src/scraper_xml.cpp @@ -195,17 +195,17 @@ void romlist_console_report( FeRomInfoListType &rl ) FeRomInfoListType::iterator itr; for ( itr=rl.begin(); itr!=rl.end(); ++itr ) { - std::cout << " > " << std::left << std::setw( 25 ) + FeLog() << " > " << std::left << std::setw( 25 ) << truncate( *itr, FeRomInfo::Romname, 25 ) << " ==> " << std::setw( 25 ) << truncate( *itr, FeRomInfo::Title, 25 ); if ( (*itr).get_info( FeRomInfo::BuildScore ).empty() ) - std::cout << std::endl; + FeLog() << std::endl; else - std::cout << " [" << std::right << std::setw( 3 ) - << (*itr).get_info( FeRomInfo::BuildScore ) << "]" - << std::endl; + FeLog() << " [" << std::right << std::setw( 3 ) + << (*itr).get_info( FeRomInfo::BuildScore ) << "]" + << std::endl; } } @@ -253,8 +253,8 @@ bool my_parse_callback( const char *buff, void *opaque ) if ( XML_Parse( ds->parser, buff, strlen(buff), XML_FALSE ) == XML_STATUS_ERROR ) { - std::cout << "Error parsing xml output:" - << buff << std::endl; + FeLog() << "Error parsing xml output:" + << buff << std::endl; } else ds->parsed_xml = true; @@ -629,15 +629,15 @@ void FeListXMLParser::post_parse() if ( !m_discarded.empty() ) { - std::cout << " - Discarded " << m_discarded.size() + FeLog() << " - Discarded " << m_discarded.size() << " entries based on xml info: "; std::vector::iterator itr; for ( itr = m_discarded.begin(); itr != m_discarded.end(); ++itr ) { - std::cout << (*(*itr)).get_info( FeRomInfo::Romname ) << " "; + FeLog() << (*(*itr)).get_info( FeRomInfo::Romname ) << " "; m_ctx.romlist.erase( (*itr) ); } - std::cout << std::endl; + FeLog() << std::endl; } } @@ -680,7 +680,7 @@ bool FeListXMLParser::parse_file( const std::string &filename ) std::ifstream myfile( filename.c_str() ); if ( !myfile.is_open() ) { - std::cerr << "Error opening file: " << filename << std::endl; + FeLog() << "Error opening file: " << filename << std::endl; return false; } @@ -698,7 +698,7 @@ bool FeListXMLParser::parse_file( const std::string &filename ) if ( XML_Parse( parser, line.c_str(), line.size(), XML_FALSE ) == XML_STATUS_ERROR ) { - std::cout << "Error parsing xml:" + FeLog() << "Error parsing xml:" << line << std::endl; ret_val = false; break; @@ -984,16 +984,16 @@ bool FeListSoftwareParser::parse( const std::string &prog, } } - std::cout << " * Calculated CRCs for " << m_crc_map.size() << " files in " + FeLog() << " * Calculated CRCs for " << m_crc_map.size() << " files in " << my_timer.getElapsedTime().asMilliseconds() << "ms." << std::endl; if ( system_name.empty() ) { - std::cerr << " * Error: No system identifier found that is recognized by -listxml" << std::endl; + FeLog() << " * Error: No system identifier found that is recognized by -listxml" << std::endl; return false; } - std::cout << " - Obtaining -listsoftware info [" + FeLog() << " - Obtaining -listsoftware info [" << system_name << "]" << std::endl; // Now get the individual game -listsoftware settings @@ -1002,7 +1002,7 @@ bool FeListSoftwareParser::parse( const std::string &prog, if ( !retval ) { - std::cout << " * Error: No XML output found, command: " << prog << " " + FeLog() << " * Error: No XML output found, command: " << prog << " " << system_name + " -listsoftware" << std::endl; } @@ -1064,7 +1064,7 @@ bool FeGameDBPlatformListParser::parse( const std::string &data ) if ( XML_Parse( parser, data.c_str(), data.size(), XML_FALSE ) == XML_STATUS_ERROR ) { - std::cout << "Error parsing xml." << std::endl; + FeLog() << "Error parsing xml." << std::endl; ret_val = false; } @@ -1160,7 +1160,7 @@ bool FeGameDBPlatformParser::parse( const std::string &data ) if ( XML_Parse( parser, data.c_str(), data.size(), XML_FALSE ) == XML_STATUS_ERROR ) { - std::cout << "Error parsing xml." << std::endl; + FeLog() << "Error parsing xml." << std::endl; ret_val = false; } @@ -1444,7 +1444,7 @@ bool FeGameDBParser::parse( const std::string &data ) if ( XML_Parse( parser, data.c_str(), data.size(), XML_FALSE ) == XML_STATUS_ERROR ) { - std::cout << "Error parsing xml." << std::endl; + FeLog() << "Error parsing xml." << std::endl; ret_val = false; } diff --git a/src/zip.cpp b/src/zip.cpp index d871e0350..a15791b41 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -22,6 +22,7 @@ #include "zip.hpp" #include "fe_util.hpp" +#include "fe_base.hpp" #include #include #include @@ -168,7 +169,7 @@ bool fe_zip_open_to_buff( if ( r != ARCHIVE_OK ) { - std::cerr << "Error opening archive: " + FeLog() << "Error opening archive: " << arch << std::endl; archive_read_free( a ); return false; @@ -207,7 +208,7 @@ bool fe_zip_get_dir( if ( r != ARCHIVE_OK ) { - std::cerr << "Error opening archive: " + FeLog() << "Error opening archive: " << archive << std::endl; archive_read_free( a ); return false; @@ -238,7 +239,7 @@ bool fe_zip_open_to_buff( if ( !mz_zip_reader_init_file( &zip, archive, 0 ) ) { - std::cerr << "Error initializing zip. zip: " + FeLog() << "Error initializing zip. zip: " << archive << std::endl; return false; } @@ -247,8 +248,6 @@ bool fe_zip_open_to_buff( filename, NULL, 0 ); if ( index < 0 ) { - std::cerr << "Error locating file. zip: " - << archive << ", file: " << filename << std::endl; mz_zip_reader_end( &zip ); return false; } @@ -256,7 +255,7 @@ bool fe_zip_open_to_buff( mz_zip_archive_file_stat file_stat; if ( !mz_zip_reader_file_stat(&zip, index, &file_stat) ) { - std::cerr << "Error reading filestats. zip: " + FeLog() << "Error reading filestats. zip: " << archive << ", file: " << filename << std::endl; mz_zip_reader_end( &zip ); return false; @@ -267,7 +266,7 @@ bool fe_zip_open_to_buff( if ( !mz_zip_reader_extract_to_mem( &zip, index, &(buff[0]), buff.size(), 0 ) ) { - std::cerr << "Error extracting to buffer. zip: " + FeLog() << "Error extracting to buffer. zip: " << archive << ", file: " << filename << std::endl; mz_zip_reader_end( &zip ); return false; @@ -290,7 +289,7 @@ bool fe_zip_get_dir( if ( !mz_zip_reader_init_file( &zip, archive, 0 ) ) { - std::cerr << "Error initializing zip: " + FeLog() << "Error initializing zip: " << archive << std::endl; return false; }