From 540ffb6ad022bb59a519a8f01b9926fb4900b941 Mon Sep 17 00:00:00 2001 From: Andrew Mickelson Date: Mon, 7 Nov 2016 22:58:42 -0800 Subject: [PATCH] Added scraping of game overview text from thegamesdb.net --- Layouts.md | 2 + config/language/de.msg | 5 ++ config/language/en.msg | 1 + config/language/es.msg | 5 ++ config/language/fr.msg | 5 ++ config/language/it.msg | 5 ++ config/language/jp.msg | 6 +- config/language/kr.msg | 6 +- config/language/msg_template.txt | 5 ++ src/fe_config.cpp | 11 ++- src/fe_settings.cpp | 138 +++++++++++++++++++++---------- src/fe_settings.hpp | 16 +++- src/fe_vm.cpp | 26 ++++-- src/scraper_general.cpp | 2 + src/scraper_net.cpp | 20 +++++ src/scraper_xml.cpp | 25 ++++++ src/scraper_xml.hpp | 5 ++ 17 files changed, 227 insertions(+), 56 deletions(-) diff --git a/Layouts.md b/Layouts.md index f4a56f7cd..88f8ace9e 100644 --- a/Layouts.md +++ b/Layouts.md @@ -198,6 +198,7 @@ Manufacturer's name. There are more examples below. game's emulator - `[SystemN]` - the last "System" name configured for the selected game's emulator + - `[Overview]` - the overview description for the selected game * Magic tokens can also be used to run a function defined in your layout or plugin's squirrel script to obtain the desired text. These tokens are in the form `[!]`. When used, Attract-Mode will run the @@ -672,6 +673,7 @@ Parameters: - `Info.PlayedTime` - `Info.FileIsAvailable` - `Info.System` + - `Info.Overview` * index_offset - the offset (from the current selection) of the game to retrieve info on. i.e. -1=previous game, 0=current game, 1=next game... and so on. Default value is 0. diff --git a/config/language/de.msg b/config/language/de.msg index 072107004..f2f60c7e4 100644 --- a/config/language/de.msg +++ b/config/language/de.msg @@ -322,6 +322,7 @@ _help_autolaunch_last_game;Beim Hochfahren automatisch das zuletzt gespielte Spi Add '$1' to Favourites?;Add '$1' to Favourites? Add Exception;Add Exception Add tag: '$1';Add tag: '$1' +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Intro;Configure Intro Configure Layout;Configure Layout @@ -339,17 +340,20 @@ Enter Romlist Name;Enter Romlist Name Enter new tag name;Enter new tag name Exception;Exception Exception Edit;Exception Edit +Extra;Extra FileIsAvailable;FileIsAvailable Intro;Intro Launch Last Game;Launch Last Game Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout Next Game;Next Game +Overview;Overview Previous Game;Previous Game Remove '$1' from Favourites?;Remove '$1' from Favourites? Remove tag: '$1';Remove tag: '$1' Scrape Fanart;Scrape Fanart Scrape Videos (MAME only);Scrape Videos (MAME only) +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Show Displays Menu;Show Displays Menu Show Last Selection (Default);Show Last Selection (Default) Show in Cycle;Show in Cycle @@ -381,6 +385,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_input_default_action;Set the default behaviour for this control diff --git a/config/language/en.msg b/config/language/en.msg index 5272a8bb6..56d029733 100644 --- a/config/language/en.msg +++ b/config/language/en.msg @@ -105,6 +105,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_hide_brackets;Hide text in brackets when showing game titles diff --git a/config/language/es.msg b/config/language/es.msg index a70bb4e5e..8be7fde59 100644 --- a/config/language/es.msg +++ b/config/language/es.msg @@ -323,6 +323,7 @@ _help_autolaunch_last_game;Lanza automaticamente el útlito juego jugado en el i Add '$1' to Favourites?;Add '$1' to Favourites? Add Exception;Add Exception Add tag: '$1';Add tag: '$1' +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Intro;Configure Intro Configure Layout;Configure Layout @@ -340,17 +341,20 @@ Enter Romlist Name;Enter Romlist Name Enter new tag name;Enter new tag name Exception;Exception Exception Edit;Exception Edit +Extra;Extra FileIsAvailable;FileIsAvailable Intro;Intro Launch Last Game;Launch Last Game Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout Next Game;Next Game +Overview;Overview Previous Game;Previous Game Remove '$1' from Favourites?;Remove '$1' from Favourites? Remove tag: '$1';Remove tag: '$1' Scrape Fanart;Scrape Fanart Scrape Videos (MAME only);Scrape Videos (MAME only) +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Show Displays Menu;Show Displays Menu Show Last Selection (Default);Show Last Selection (Default) Show in Cycle;Show in Cycle @@ -382,6 +386,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_input_default_action;Set the default behaviour for this control diff --git a/config/language/fr.msg b/config/language/fr.msg index f3ace2ac3..3d6985c4c 100644 --- a/config/language/fr.msg +++ b/config/language/fr.msg @@ -327,6 +327,7 @@ $1 Rule(s);$1 Rule(s) Add '$1' to Favourites?;Add '$1' to Favourites? Add Exception;Add Exception Add tag: '$1';Add tag: '$1' +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Intro;Configure Intro Configure Layout;Configure Layout @@ -344,17 +345,20 @@ Enter Romlist Name;Enter Romlist Name Enter new tag name;Enter new tag name Exception;Exception Exception Edit;Exception Edit +Extra;Extra FileIsAvailable;FileIsAvailable Intro;Intro Launch Last Game;Launch Last Game Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout Next Game;Next Game +Overview;Overview Play Sound;Play Sound Previous Game;Previous Game Remove '$1' from Favourites?;Remove '$1' from Favourites? Remove tag: '$1';Remove tag: '$1' Scrape Videos (MAME only);Scrape Videos (MAME only) +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Show Displays Menu;Show Displays Menu Show Last Selection (Default);Show Last Selection (Default) Show in Cycle;Show in Cycle @@ -385,6 +389,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_input_action; diff --git a/config/language/it.msg b/config/language/it.msg index 78added4c..36c19da45 100644 --- a/config/language/it.msg +++ b/config/language/it.msg @@ -389,18 +389,23 @@ _help_control_page_up;Configura i controlli che muovono la selezione una pagina # # Strings still needing translation # +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Layout;Configure Layout Default;Default Enter Romlist Name;Enter Romlist Name +Extra;Extra Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout +Overview;Overview +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Window (No Border);Window (No Border) multi;multi _help_displays_menu;Configure options for the "Displays Menu" _help_displays_menu_layout;The layout to use for the 'Displays Menu'. Set to 'Default' to use the frontend's built-in menu _help_displays_menu_prompt;The 'Displays Menu' prompt (i.e. "Select System") _help_emu_sel_gen_romlist;Generate a Collection/Romlist containing games for multiple emulators +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_scrape_mamedb;Set whether mame snaps and marquees should be scraped from mamedb.com diff --git a/config/language/jp.msg b/config/language/jp.msg index 1b4110f5e..5d2ba74fd 100644 --- a/config/language/jp.msg +++ b/config/language/jp.msg @@ -79,6 +79,7 @@ Exit Attract-Mode?;終了しますか? Exit Command;終了コマンド Exit Hotkey;終了ホットキー Exit to Desktop;終了 +Extra;その他(Extra) Favourite;お気に入り FileIsAvailable;Romファイルの存在 Fill Screen (Default);全画面に広げる (デフォルト) @@ -294,7 +295,6 @@ Configure available emulators;エミュレータの設定 Configure filter rule;フィルターのルールー編集 Delete this filter;このフィルターを削除 Exit menu;出る -Extra;その他(Extra) Launch Last Game on Startup;最後にプレイしたゲームを次の起動時 再起動 Page Down;1画面下 Page Up;1画面上 @@ -317,6 +317,7 @@ $1 Rule(s);$1 Rule(s) Add '$1' to Favourites?;Add '$1' to Favourites? Add Exception;Add Exception Add tag: '$1';Add tag: '$1' +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Intro;Configure Intro Configure Layout;Configure Layout @@ -340,6 +341,7 @@ Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout Next Game;Next Game Next Page;Next Page +Overview;Overview Play Sound;Play Sound Previous Game;Previous Game Previous Page;Previous Page @@ -347,6 +349,7 @@ Remove '$1' from Favourites?;Remove '$1' from Favourites? Remove tag: '$1';Remove tag: '$1' Scrape Fanart;Scrape Fanart Scrape Videos (MAME only);Scrape Videos (MAME only) +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Show Displays Menu;Show Displays Menu Show Last Selection (Default);Show Last Selection (Default) Show in Cycle;Show in Cycle @@ -382,6 +385,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_input_action; diff --git a/config/language/kr.msg b/config/language/kr.msg index aa027e089..0547c54ac 100644 --- a/config/language/kr.msg +++ b/config/language/kr.msg @@ -79,6 +79,7 @@ Exit Attract-Mode?;종료하시겠습니까? Exit Command;종료 명령어 Exit Hotkey;종료 핫키 Exit to Desktop;종료 +Extra;기타정보(Extra) Favourite;즐겨찾기 FileIsAvailable;롬파일 존재여부 Fill Screen (Default);전체 화면 크기로 확장 (기본값) @@ -294,7 +295,6 @@ Configure available emulators;기존 에뮬레이터 편집 Configure filter rule;필터 내용 수정 Delete this filter;본 필터 삭제 Exit menu;나가기 -Extra;기타정보(Extra) Launch Last Game on Startup;기동시 직전 게임 자동 재시작 Page Down;페이지 아래로 Page Up;페이지 위로 @@ -317,6 +317,7 @@ $1 Rule(s);$1 Rule(s) Add '$1' to Favourites?;Add '$1' to Favourites? Add Exception;Add Exception Add tag: '$1';Add tag: '$1' +Buttons;Buttons Configure / Displays Menu;Configure / Displays Menu Configure Intro;Configure Intro Configure Layout;Configure Layout @@ -340,6 +341,7 @@ Menu Prompt;Menu Prompt Menu Style / Layout;Menu Style / Layout Next Game;Next Game Next Page;Next Page +Overview;Overview Play Sound;Play Sound Previous Game;Previous Game Previous Page;Previous Page @@ -347,6 +349,7 @@ Remove '$1' from Favourites?;Remove '$1' from Favourites? Remove tag: '$1';Remove tag: '$1' Scrape Fanart;Scrape Fanart Scrape Videos (MAME only);Scrape Videos (MAME only) +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Show Displays Menu;Show Displays Menu Show Last Selection (Default);Show Last Selection (Default) Show in Cycle;Show in Cycle @@ -382,6 +385,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_build;Generate romlist with the selected emulator(s) _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_input_action; diff --git a/config/language/msg_template.txt b/config/language/msg_template.txt index 7f94e222f..95c3e4a7a 100644 --- a/config/language/msg_template.txt +++ b/config/language/msg_template.txt @@ -24,6 +24,7 @@ Ambient Volume;Ambient Volume Artwork Label;Artwork Label Artwork Path;Artwork Path Back;Back +Buttons;Buttons Category;Category CloneOf;CloneOf Collection/Rom List;Collection/Rom List @@ -99,6 +100,7 @@ Exit Attract-Mode?;Exit Attract-Mode? Exit Command;Exit Command Exit Hotkey;Exit Hotkey Exit to Desktop;Exit to Desktop +Extra;Extra Favourite;Favourite FileIsAvailable;FileIsAvailable Fill Screen (Default);Fill Screen (Default) @@ -145,6 +147,7 @@ No Sort;No Sort No Wrap;No Wrap None;None OR;OR +Overview;Overview Overwrite existing '$1' list?;Overwrite existing '$1' list? Play Sound;Play Sound PlayedCount;PlayedCount @@ -175,6 +178,7 @@ Scrape Fanart;Scrape Fanart Scrape Flyers/Boxart;Scrape Flyers/Boxart Scrape Game Logos (Wheel Art);Scrape Game Logos (Wheel Art) Scrape Marquees;Scrape Marquees +Scrape mamedb.com (MAME only);Scrape mamedb.com (MAME only) Scrape Snaps;Scrape Snaps Scrape Videos (MAME only);Scrape Videos (MAME only) Scraper;Scraper @@ -323,6 +327,7 @@ _help_game_custom_args;Set this to override the default command line arguments f _help_game_custom_executable;Set this to override the default executable for this game _help_game_delete;Delete this game from the Romlist _help_game_edit;Edit this game information +_help_game_overview;Edit game overview _help_generator_opt;Set whether this emulator is to be included in the generated romlist _help_generator_build;Generate romlist with the selected emulator(s) _help_hide_brackets;Hide text in brackets when showing game titles diff --git a/src/fe_config.cpp b/src/fe_config.cpp index 35879ff7d..49b1791cb 100644 --- a/src/fe_config.cpp +++ b/src/fe_config.cpp @@ -2336,6 +2336,11 @@ void FeEditGameMenu::get_options( FeConfigContext &ctx ) ctx.opt_list[ FeRomInfo::PlayedCount ].opaque = 3; ctx.opt_list[ FeRomInfo::PlayedTime ].opaque = 3; + ctx.add_optl( Opt::EDIT, "Overview", + ctx.fe_settings.get_game_extra( FeSettings::Overview ), + "_help_game_overview" ); + ctx.back_opt().opaque = 4; + ctx.add_optl( Opt::EDIT, "Custom Executable", ctx.fe_settings.get_game_extra( FeSettings::Executable ), "_help_game_custom_executable" ); @@ -2392,6 +2397,7 @@ bool FeEditGameMenu::on_option_select( FeConfigContext &ctx, FeBaseConfigMenu *& m_update_extras = true; break; + case 100: // Delete Game if ( ctx.confirm_dialog( "Delete game '$1'?", ctx.opt_list[1].get_value() ) ) { @@ -2436,8 +2442,9 @@ bool FeEditGameMenu::save( FeConfigContext &ctx ) if ( m_update_extras ) { - ctx.fe_settings.set_game_extra( FeSettings::Executable, ctx.opt_list[border].get_value() ); - ctx.fe_settings.set_game_extra( FeSettings::Arguments, ctx.opt_list[border+1].get_value() ); + ctx.fe_settings.set_game_extra( FeSettings::Overview, ctx.opt_list[border].get_value() ); + ctx.fe_settings.set_game_extra( FeSettings::Executable, ctx.opt_list[border+1].get_value() ); + ctx.fe_settings.set_game_extra( FeSettings::Arguments, ctx.opt_list[border+2].get_value() ); ctx.fe_settings.save_game_extras(); } diff --git a/src/fe_settings.cpp b/src/fe_settings.cpp index 3ec61b2ad..e4958cebc 100644 --- a/src/fe_settings.cpp +++ b/src/fe_settings.cpp @@ -266,6 +266,7 @@ FeSettings::FeSettings( const std::string &config_path, m_scrape_fanart( false ), m_scrape_vids( false ), m_scrape_mamedb( true ), + m_scrape_overview( true ), #ifdef SFML_SYSTEM_WINDOWS m_hide_console( false ), #endif @@ -429,6 +430,7 @@ const char *FeSettings::configSettingStrings[] = "scrape_fanart", "scrape_videos", "scrape_mamedb", + "scrape_overview", #ifdef SFML_SYSTEM_WINDOWS "hide_console", #endif @@ -555,6 +557,8 @@ int FeSettings::process_setting( const std::string &setting, void FeSettings::init_display() { + m_loaded_game_extras = false; + // // Setting new_index to negative causes us to do the 'Displays Menu' w/ custom layout // @@ -1395,11 +1399,12 @@ namespace { const char *game_extra_strings[] = { "executable", "args", + "overview", NULL }; }; -std::string FeSettings::get_game_extra( GameExtra id ) +const std::string &FeSettings::get_game_extra( GameExtra id ) { if ( !m_loaded_game_extras ) { @@ -1416,54 +1421,66 @@ std::string FeSettings::get_game_extra( GameExtra id ) if ( romlist_name.empty() ) return FE_EMPTY_STRING; - std::string path( m_config_path ); - path += FE_ROMLIST_SUBDIR; - path += romlist_name; - path += "/"; - - std::string name = get_rom_info( 0, 0, FeRomInfo::Romname ); - if (( !directory_exists( path ) ) || name.empty() ) + if ( !load_game_extras( + romlist_name, + get_rom_info( 0, 0, FeRomInfo::Romname ), + m_game_extras ) ) return FE_EMPTY_STRING; + } - path += name; - path += FE_GAME_EXTRA_FILE_EXTENSION; - if ( !file_exists( path ) ) - return FE_EMPTY_STRING; + std::map::iterator it = m_game_extras.find( id ); + if ( it != m_game_extras.end() ) + return (*it).second; - std::ifstream in_file( path.c_str() ); - if ( !in_file.is_open() ) - return FE_EMPTY_STRING; + return FE_EMPTY_STRING; +} + +bool FeSettings::load_game_extras( + const std::string &romlist_name, + const std::string &romname, + std::map &extras ) +{ + std::string path( m_config_path ); + path += FE_ROMLIST_SUBDIR; + path += romlist_name; + path += "/"; + + if (( !directory_exists( path ) ) || romname.empty() ) + return false; - while ( in_file.good() ) + path += romname; + path += FE_GAME_EXTRA_FILE_EXTENSION; + if ( !file_exists( path ) ) + return false; + + std::ifstream in_file( path.c_str() ); + if ( !in_file.is_open() ) + return false; + + while ( in_file.good() ) + { + std::string line, s, v; + getline( in_file, line ); + if ( line_to_setting_and_value( line, s, v ) ) { - std::string line, s, v; - getline( in_file, line ); - if ( line_to_setting_and_value( line, s, v ) ) + int i=0; + while ( game_extra_strings[i] != NULL ) { - int i=0; - while ( game_extra_strings[i] != NULL ) + if ( s.compare( game_extra_strings[i] ) == 0 ) { - if ( s.compare( game_extra_strings[i] ) == 0 ) - { - m_game_extras[ (GameExtra)i ] = v; - break; - } - i++; + extras[ (GameExtra)i ] = v; + break; } - - if ( game_extra_strings[i] == NULL ) - std::cerr << " ! Unrecognized game setting: " << s << " " << v << std::endl; + i++; } - } - in_file.close(); + if ( game_extra_strings[i] == NULL ) + std::cerr << " ! Unrecognized game setting: " << s << " " << v << std::endl; + } } - std::map::iterator it = m_game_extras.find( id ); - if ( it != m_game_extras.end() ) - return (*it).second; - - return FE_EMPTY_STRING; + in_file.close(); + return true; } void FeSettings::set_game_extra( GameExtra id, const std::string &value ) @@ -1487,6 +1504,16 @@ void FeSettings::save_game_extras() if ( romlist_name.empty() ) return; + save_game_extras( + romlist_name, + get_rom_info( 0, 0, FeRomInfo::Romname ), + m_game_extras ); +} + +void FeSettings::save_game_extras( const std::string &romlist_name, + const std::string &romname, + const std::map &extras ) +{ std::string path( m_config_path ); path += FE_ROMLIST_SUBDIR; @@ -1495,15 +1522,13 @@ void FeSettings::save_game_extras() path += romlist_name; path += "/"; - std::string name = get_rom_info( 0, 0, FeRomInfo::Romname ); - - if ( name.empty() ) + if ( romname.empty() ) return; - path += name; + path += romname; path += FE_GAME_EXTRA_FILE_EXTENSION; - if ( m_game_extras.empty() ) + if ( extras.empty() ) { if ( file_exists( path ) ) delete_file( path ); @@ -1515,8 +1540,8 @@ void FeSettings::save_game_extras() if ( !out_file.is_open() ) return; - std::map::iterator it; - for ( it=m_game_extras.begin(); it!=m_game_extras.end(); ++it ) + std::map::const_iterator it; + for ( it=extras.begin(); it!=extras.end(); ++it ) out_file << game_extra_strings[(int)(*it).first] << " " << (*it).second << std::endl; out_file.close(); @@ -2095,6 +2120,7 @@ void FeSettings::do_text_substitutions_absolute( std::string &str, int filter_in "SortValue", "System", "SystemN", + "Overview", NULL }; @@ -2215,6 +2241,24 @@ void FeSettings::do_text_substitutions_absolute( std::string &str, int filter_in } break; + case 14: // "Overview" + if (( filter_index == 0 ) && ( rom_index == 0 )) + rep = get_game_extra( Overview ); + else if ( m_current_display >= 0 ) + { + std::map extras; + + load_game_extras( + m_displays[m_current_display].get_info( FeDisplayInfo::Romlist ), + get_rom_info_absolute( filter_index, rom_index, FeRomInfo::Romname ), + extras ); + + rep = extras[ Overview ]; + } + + perform_substitution( rep, "\\n", "\n" ); + break; + default: ASSERT( 0 ); // unhandled token break; @@ -2525,6 +2569,8 @@ bool FeSettings::get_info_bool( int index ) const return m_scrape_vids; case ScrapeMameDB: return m_scrape_mamedb; + case ScrapeOverview: + return m_scrape_overview; #ifdef SFML_SYSTEM_WINDOWS case HideConsole: return m_hide_console; @@ -2700,6 +2746,10 @@ bool FeSettings::set_info( int index, const std::string &value ) m_scrape_mamedb = config_str_to_bool( value ); break; + case ScrapeOverview: + m_scrape_overview = config_str_to_bool( value ); + break; + #ifdef SFML_SYSTEM_WINDOWS case HideConsole: m_hide_console = config_str_to_bool( value ); diff --git a/src/fe_settings.hpp b/src/fe_settings.hpp index bbd95465f..b937e917d 100644 --- a/src/fe_settings.hpp +++ b/src/fe_settings.hpp @@ -125,6 +125,7 @@ class FeSettings : public FeBaseConfigurable ScrapeFanArt, ScrapeVids, ScrapeMameDB, + ScrapeOverview, #ifdef SFML_SYSTEM_WINDOWS HideConsole, #endif @@ -140,7 +141,8 @@ class FeSettings : public FeBaseConfigurable enum GameExtra { Executable =0, // custom executable to override the configured emulator executable - Arguments // custom arguments to override the configured emulator arguments + Arguments, // custom arguments to override the configured emulator arguments + Overview }; private: @@ -198,6 +200,7 @@ class FeSettings : public FeBaseConfigurable bool m_scrape_fanart; bool m_scrape_vids; bool m_scrape_mamedb; + bool m_scrape_overview; #ifdef SFML_SYSTEM_WINDOWS bool m_hide_console; #endif @@ -232,6 +235,15 @@ class FeSettings : public FeBaseConfigurable bool thegamesdb_scraper( FeImporterContext & ); void apply_xml_import( FeImporterContext &, bool ); + bool load_game_extras( + const std::string &romlist_name, + const std::string &romname, + std::map &extras ); + + void save_game_extras( + const std::string &romlist_name, + const std::string &romname, + const std::map &extras ); public: FeSettings( const std::string &config_dir, @@ -441,7 +453,7 @@ class FeSettings : public FeBaseConfigurable // This info is only ever loaded for the currently selected game, and is not intended // to be used in a filter // - std::string get_game_extra( GameExtra id ); + const std::string &get_game_extra( GameExtra id ); void set_game_extra( GameExtra id, const std::string &value ); void save_game_extras(); diff --git a/src/fe_vm.cpp b/src/fe_vm.cpp index 33bdd3686..df49d85d4 100644 --- a/src/fe_vm.cpp +++ b/src/fe_vm.cpp @@ -564,6 +564,7 @@ bool FeVM::on_new_layout() } info.Const( "System", FeRomInfo::LAST_INDEX ); // special cases with same value info.Const( "NoSort", FeRomInfo::LAST_INDEX ); // + info.Const( "Overview", FeRomInfo::LAST_INDEX+1 ); // ConstTable().Enum( _SC("Info"), info); Enumeration transition; @@ -1949,7 +1950,9 @@ const char *FeVM::cb_game_info( int index, int offset, int filter_offset ) HSQUIRRELVM vm = Sqrat::DefaultVM::Get(); FeVM *fev = (FeVM *)sq_getforeignptr( vm ); - if (( index > FeRomInfo::LAST_INDEX ) || ( index < 0 )) + static std::string retval; + + if (( index > FeRomInfo::LAST_INDEX+1 ) || ( index < 0 )) { // the better thing to do would be to raise a squirrel error here // @@ -1961,13 +1964,24 @@ const char *FeVM::cb_game_info( int index, int offset, int filter_offset ) std::string emu_name = fev->m_feSettings->get_rom_info( filter_offset, offset, FeRomInfo::Emulator ); FeEmulatorInfo *emu = fev->m_feSettings->get_emulator( emu_name ); - static std::string sys_name; + retval.clear(); if ( emu ) - sys_name = emu->get_info( FeEmulatorInfo::System ); - else - sys_name = ""; + retval = emu->get_info( FeEmulatorInfo::System ); + + return retval.c_str(); + } + else if ( index == FeRomInfo::LAST_INDEX+1 ) + { + // Overview + retval.clear(); + if (( offset == 0 ) && ( filter_offset == 0 )) + retval = fev->m_feSettings->get_game_extra( FeSettings::Overview ).c_str(); + // + //TODO: loading overview where there is a filter or index offset is not yet implemented + // - return sys_name.c_str(); + perform_substitution( retval, "\\n", "\n" ); + return retval.c_str(); } return (fev->m_feSettings->get_rom_info( filter_offset, offset, (FeRomInfo::Index)index )).c_str(); diff --git a/src/scraper_general.cpp b/src/scraper_general.cpp index 6bb94ce73..80fd5b205 100644 --- a/src/scraper_general.cpp +++ b/src/scraper_general.cpp @@ -511,6 +511,7 @@ bool FeSettings::build_romlist( const std::vector< FeImportTask > &task_list, FeImporterContext ctx( *emu, romlist ); ctx.full = full; + ctx.out_name = output_name; build_basic_romlist( ctx ); @@ -722,6 +723,7 @@ bool FeSettings::build_romlist( const std::vector &emu_list, const FeImporterContext ctx( *emu, romlist ); ctx.uiupdate = uiu; ctx.uiupdatedata = uid; + ctx.out_name = out_name; build_basic_romlist( ctx ); apply_xml_import( ctx, true ); diff --git a/src/scraper_net.cpp b/src/scraper_net.cpp index a09f8c118..3b1d03427 100644 --- a/src/scraper_net.cpp +++ b/src/scraper_net.cpp @@ -145,6 +145,8 @@ bool FeSettings::mameps_scraper( FeImporterContext &c ) if ( !c.emulator.is_mame() || !m_scrape_vids ) return true; + std::cout << " - scraping www.progettosnaps.net..." << std::endl; + // // Build a map for looking up parents // @@ -193,6 +195,8 @@ bool FeSettings::mamedb_scraper( FeImporterContext &c ) if ( !c.emulator.is_mame() || !m_scrape_mamedb || ( !m_scrape_snaps && !m_scrape_marquees )) return true; + std::cout << " - scraping mamedb.com..." << std::endl; + // // Build a map for looking up parents // @@ -437,6 +441,8 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) std::vector system_list; std::vector system_ids; + std::cout << " - scraping thegamesdb.net..." << std::endl; + // // Get a list of valid platforms // @@ -631,6 +637,20 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) } else { + std::string overview; + if( m_scrape_overview && gdbp.get_overview( overview ) ) + { + // + // Save the overview now... + // + std::map extras; + const std::string &rn = (worklist[id])->get_info( FeRomInfo::Romname ); + + load_game_extras( c.out_name, rn, extras ); + extras[ Overview ] = overview; + save_game_extras( c.out_name, rn, extras ); + } + aux = (worklist[id])->get_info( FeRomInfo::Title ); done_count+=NUM_ARTS; } diff --git a/src/scraper_xml.cpp b/src/scraper_xml.cpp index 52dc2aa1b..c2cfbc86e 100644 --- a/src/scraper_xml.cpp +++ b/src/scraper_xml.cpp @@ -1175,6 +1175,7 @@ void FeGameDBParser::start_element( m_players.clear(); m_manufacturer.clear(); m_platform.clear(); + m_overview.clear(); } else if (( strcmp( element, "ReleaseDate" ) == 0 ) || ( strcmp( element, "genre" ) == 0 ) @@ -1183,6 +1184,7 @@ void FeGameDBParser::start_element( || ( strcmp( element, "Platform" ) == 0 ) || ( strcmp( element, "GameTitle" ) == 0 ) || ( strcmp( element, "title" ) == 0 ) + || ( strcmp( element, "Overview" ) == 0 ) ) { m_element_open=true; @@ -1279,6 +1281,8 @@ void FeGameDBParser::end_element( const char *element ) m_manufacturer = m_current_data; else if ( strcmp( element, "Platform" ) == 0 ) m_platform = m_current_data; + else if ( strcmp( element, "Overview" ) == 0 ) + m_overview = m_current_data; else if ( m_art ) { @@ -1336,6 +1340,7 @@ void FeGameDBParser::end_element( const char *element ) set_info_val( FeRomInfo::Category, m_category ); set_info_val( FeRomInfo::Players, m_players ); set_info_val( FeRomInfo::Manufacturer, m_manufacturer ); + m_overview_keep.swap( m_overview ); if ( m_art ) { @@ -1380,6 +1385,26 @@ void FeGameDBParser::set_info_val( FeRomInfo::Index i, const std::string &v ) m_rom.set_info( i, v ); } +bool FeGameDBParser::get_overview( std::string &overview ) +{ + if ( m_overview_keep.empty() ) + return false; + + // + // escape newlines in m_overview + // + size_t pos1=0, pos=0; + while ( ( pos = m_overview_keep.find( "\n", pos1 ) ) != std::string::npos ) + { + overview += m_overview_keep.substr( pos1, pos-pos1 ); + overview += "\\n"; + pos1 = pos+1; + } + overview += m_overview_keep.substr( pos1 ); + + return true; +} + bool FeGameDBParser::parse( const std::string &data ) { m_element_open=m_keep_rom=m_ignore=false; diff --git a/src/scraper_xml.hpp b/src/scraper_xml.hpp index c498691b5..8e3798de1 100644 --- a/src/scraper_xml.hpp +++ b/src/scraper_xml.hpp @@ -84,6 +84,7 @@ class FeImporterContext int progress_range; int download_count; std::string user_message; + std::string out_name; }; class FeListXMLParser : private FeXMLParser @@ -197,6 +198,8 @@ class FeGameDBParser : private FeXMLParser bool parse( const std::string &data ); + bool get_overview( std::string & ); + private: void start_element( const char *, const char ** ); void end_element( const char * ); @@ -213,6 +216,8 @@ class FeGameDBParser : private FeXMLParser std::string m_players; std::string m_manufacturer; std::string m_platform; + std::string m_overview; + std::string m_overview_keep; FeRomInfo &m_rom; FeGameDBArt *m_art;