Skip to content

Commit

Permalink
Issue #391 - store overview information by emulator
Browse files Browse the repository at this point in the history
- overview information is now stored for each emulator in
  <config>/scraper/<emu>/overview/<romname>.txt

- There is no automatic migration of old overviews to new... after this
  update, users will have to re-scrape artwork or regenerate a romlist
  for each emulator to re-establish overview information
  • Loading branch information
mickelson committed Jul 11, 2018
1 parent f2f0fca commit 88595c8
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 65 deletions.
34 changes: 25 additions & 9 deletions src/fe_config.cpp
Expand Up @@ -2448,7 +2448,8 @@ bool FeConfigMenu::save( FeConfigContext &ctx )
FeEditGameMenu::FeEditGameMenu() FeEditGameMenu::FeEditGameMenu()
: m_update_rl( false ), : m_update_rl( false ),
m_update_stats( false ), m_update_stats( false ),
m_update_extras( false ) m_update_extras( false ),
m_update_overview( false )
{ {
} }


Expand Down Expand Up @@ -2542,10 +2543,14 @@ void FeEditGameMenu::get_options( FeConfigContext &ctx )
ctx.opt_list[ FeRomInfo::PlayedCount ].opaque = 3; ctx.opt_list[ FeRomInfo::PlayedCount ].opaque = 3;
ctx.opt_list[ FeRomInfo::PlayedTime ].opaque = 3; ctx.opt_list[ FeRomInfo::PlayedTime ].opaque = 3;


ctx.add_optl( Opt::EDIT, "Overview", int filter_idx = ctx.fe_settings.get_filter_index_from_offset( 0 );
ctx.fe_settings.get_game_extra( FeSettings::Overview ), int rom_idx = ctx.fe_settings.get_rom_index( filter_idx, 0 );
"_help_game_overview" );
ctx.back_opt().opaque = 4; std::string ov;
ctx.fe_settings.get_game_overview_absolute( filter_idx, rom_idx, ov );

ctx.add_optl( Opt::EDIT, "Overview", newline_escape( ov ), "_help_game_overview" );
ctx.back_opt().opaque = 5;


ctx.add_optl( Opt::EDIT, "Custom Executable", ctx.add_optl( Opt::EDIT, "Custom Executable",
ctx.fe_settings.get_game_extra( FeSettings::Executable ), ctx.fe_settings.get_game_extra( FeSettings::Executable ),
Expand All @@ -2563,9 +2568,7 @@ void FeEditGameMenu::get_options( FeConfigContext &ctx )
m_update_stats=false; m_update_stats=false;
m_update_rl=false; m_update_rl=false;
m_update_extras=false; m_update_extras=false;

m_update_overview=false;
int filter_idx = ctx.fe_settings.get_filter_index_from_offset( 0 );
int rom_idx = ctx.fe_settings.get_rom_index( filter_idx, 0 );


FeRomInfo *rom = ctx.fe_settings.get_rom_absolute( filter_idx, rom_idx ); FeRomInfo *rom = ctx.fe_settings.get_rom_absolute( filter_idx, rom_idx );
if ( rom ) if ( rom )
Expand Down Expand Up @@ -2603,6 +2606,9 @@ bool FeEditGameMenu::on_option_select( FeConfigContext &ctx, FeBaseConfigMenu *&
m_update_extras = true; m_update_extras = true;
break; break;


case 5: // Overview
m_update_overview = true;
break;


case 100: // Delete Game case 100: // Delete Game
if ( ctx.confirm_dialog( "Delete game '$1'?", ctx.opt_list[1].get_value() ) ) if ( ctx.confirm_dialog( "Delete game '$1'?", ctx.opt_list[1].get_value() ) )
Expand Down Expand Up @@ -2648,9 +2654,19 @@ bool FeEditGameMenu::save( FeConfigContext &ctx )
if ( m_update_stats ) if ( m_update_stats )
ctx.fe_settings.update_stats(0,0); // this will force a rewrite of the file ctx.fe_settings.update_stats(0,0); // this will force a rewrite of the file


if ( m_update_overview )
{
std::string ov = ctx.opt_list[border].get_value();
perform_substitution( ov, "\\n", "\n" );

ctx.fe_settings.set_game_overview(
replacement.get_info( FeRomInfo::Emulator ),
replacement.get_info( FeRomInfo::Romname ),
ov, true ); // force overwrites
}

if ( m_update_extras ) if ( m_update_extras )
{ {
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::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.set_game_extra( FeSettings::Arguments, ctx.opt_list[border+2].get_value() );
ctx.fe_settings.save_game_extras(); ctx.fe_settings.save_game_extras();
Expand Down
1 change: 1 addition & 0 deletions src/fe_config.hpp
Expand Up @@ -482,6 +482,7 @@ class FeEditGameMenu : public FeBaseConfigMenu
bool m_update_rl; bool m_update_rl;
bool m_update_stats; bool m_update_stats;
bool m_update_extras; bool m_update_extras;
bool m_update_overview;


public: public:
FeEditGameMenu(); FeEditGameMenu();
Expand Down
134 changes: 117 additions & 17 deletions src/fe_settings.cpp
Expand Up @@ -123,6 +123,7 @@ const char *FE_LANGUAGE_FILE_EXTENSION = ".msg";
const char *FE_SWF_EXT = ".swf"; const char *FE_SWF_EXT = ".swf";
const char *FE_PLUGIN_FILE_EXTENSION = FE_LAYOUT_FILE_EXTENSION; const char *FE_PLUGIN_FILE_EXTENSION = FE_LAYOUT_FILE_EXTENSION;
const char *FE_GAME_EXTRA_FILE_EXTENSION = ".cfg"; const char *FE_GAME_EXTRA_FILE_EXTENSION = ".cfg";
const char *FE_GAME_OVERVIEW_FILE_EXTENSION = ".txt";
const char *FE_LAYOUT_SUBDIR = "layouts/"; const char *FE_LAYOUT_SUBDIR = "layouts/";
const char *FE_ROMLIST_SUBDIR = "romlists/"; const char *FE_ROMLIST_SUBDIR = "romlists/";
const char *FE_SOUND_SUBDIR = "sounds/"; const char *FE_SOUND_SUBDIR = "sounds/";
Expand All @@ -135,6 +136,7 @@ const char *FE_LOADER_SUBDIR = "loader/";
const char *FE_INTRO_SUBDIR = "intro/"; const char *FE_INTRO_SUBDIR = "intro/";
const char *FE_SCRAPER_SUBDIR = "scraper/"; const char *FE_SCRAPER_SUBDIR = "scraper/";
const char *FE_MENU_ART_SUBDIR = "menu-art/"; const char *FE_MENU_ART_SUBDIR = "menu-art/";
const char *FE_OVERVIEW_SUBDIR = "overview/";
const char *FE_EMULATOR_SCRIPT_SUBDIR = "emulators/script/"; const char *FE_EMULATOR_SCRIPT_SUBDIR = "emulators/script/";
const char *FE_LIST_DEFAULT = "default-display.cfg"; const char *FE_LIST_DEFAULT = "default-display.cfg";
const char *FE_FILTER_DEFAULT = "default-filter.cfg"; const char *FE_FILTER_DEFAULT = "default-filter.cfg";
Expand Down Expand Up @@ -1470,7 +1472,6 @@ namespace {
const char *game_extra_strings[] = { const char *game_extra_strings[] = {
"executable", "executable",
"args", "args",
"overview",
NULL NULL
}; };
}; };
Expand Down Expand Up @@ -1528,6 +1529,12 @@ bool FeSettings::load_game_extras(
if ( !in_file.is_open() ) if ( !in_file.is_open() )
return false; return false;


// Before Attract-Mode v 2.4, Overviews were stored with game extras.
//
// There is specific code here to clean up pre 2.4 game extras data (commented)
// this code is intended to be removed at some point in a future version
bool fix_extras_now=false;

while ( in_file.good() ) while ( in_file.good() )
{ {
std::string line, s, v; std::string line, s, v;
Expand All @@ -1546,11 +1553,26 @@ bool FeSettings::load_game_extras(
} }


if ( game_extra_strings[i] == NULL ) if ( game_extra_strings[i] == NULL )
FeLog() << " ! Unrecognized game setting: " << s << " " << v << std::endl; {
// pre 2.4 cleanup code, see comment above
if ( s.compare( "overview" ) == 0 )
fix_extras_now = true;
else
FeLog() << " ! Unrecognized game setting: " << s << " " << v << std::endl;
}
} }
} }


in_file.close(); in_file.close();

FeDebug() << "Loaded game extras from: " << path << std::endl;

// pre 2.4 cleanup code, see comment above
// fix this game extras (removing overview entry)
//
if ( fix_extras_now )
save_game_extras( romlist_name, romname, extras );

return true; return true;
} }


Expand Down Expand Up @@ -1616,6 +1638,98 @@ void FeSettings::save_game_extras( const std::string &romlist_name,
out_file << game_extra_strings[(int)(*it).first] << " " << (*it).second << std::endl; out_file << game_extra_strings[(int)(*it).first] << " " << (*it).second << std::endl;


out_file.close(); out_file.close();

FeDebug() << "Wrote game extras to: " << path << std::endl;
}

bool FeSettings::get_game_overview_filepath( const std::string &emu, const std::string &romname, std::string &path )
{
path = m_config_path;

confirm_directory( path, FE_SCRAPER_SUBDIR );
path += FE_SCRAPER_SUBDIR;

path += emu;
path += "/";

confirm_directory( path, FE_OVERVIEW_SUBDIR );
path += FE_OVERVIEW_SUBDIR;

path += romname;
path += FE_GAME_OVERVIEW_FILE_EXTENSION;

return file_exists( path );
}

bool FeSettings::get_game_overview_absolute( int filter_index, int rom_index, std::string &ov )
{
std::string emulator = get_rom_info_absolute( filter_index, rom_index, FeRomInfo::Emulator );
std::string romname = get_rom_info_absolute( filter_index, rom_index, FeRomInfo::Romname );

if ( romname.empty() )
romname = emulator;

std::string path;
if ( !get_game_overview_filepath( emulator, romname, path ) )
return false;

// We keep the last loaded game overview in memory, use it now if it is a match
//
if ( path.compare( m_last_game_overview_path ) == 0 )
{
ov = m_last_game_overview_text;
return true;
}

ov.clear();

std::ifstream myfile( path.c_str() );
if ( !myfile.is_open() )
return false;

while ( myfile.good() )
{
std::string line;
getline( myfile, line );

ov += line;
ov += "\n";
}
myfile.close();

remove_trailing_spaces( ov );

m_last_game_overview_path = path;
m_last_game_overview_text = ov;

FeDebug() << "Loaded game overview from: " << path
<< " [" << emulator << "][" << romname << "]" << std::endl;

return true;

}

void FeSettings::set_game_overview( const std::string &emu,
const std::string &romname, const std::string &ov, bool overwrite )
{
std::string path;
bool file_exists = get_game_overview_filepath( emu, romname, path );

if ( !file_exists || overwrite )
{
std::ofstream outfile( path.c_str() );
if ( outfile.is_open() )
{
outfile << ov << std::endl;
outfile.close();

m_last_game_overview_path = path;
m_last_game_overview_text = ov;

FeDebug() << "Wrote game overview to: " << path
<< " [" << emu << "][" << romname << "]" << std::endl;
}
}
} }


int FeSettings::get_current_filter_index() const int FeSettings::get_current_filter_index() const
Expand Down Expand Up @@ -2325,21 +2439,7 @@ void FeSettings::do_text_substitutions_absolute( std::string &str, int filter_in
break; break;


case 14: // "Overview" case 14: // "Overview"
if (( filter_index == 0 ) && ( rom_index == 0 )) get_game_overview_absolute( filter_index, rom_index, rep );
rep = get_game_extra( Overview );
else if ( m_current_display >= 0 )
{
std::map<GameExtra,std::string> 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; break;


default: default:
Expand Down
14 changes: 12 additions & 2 deletions src/fe_settings.hpp
Expand Up @@ -143,8 +143,7 @@ class FeSettings : public FeBaseConfigurable
enum GameExtra enum GameExtra
{ {
Executable =0, // custom executable to override the configured emulator executable 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: private:
Expand All @@ -158,6 +157,9 @@ class FeSettings : public FeBaseConfigurable
std::string m_menu_layout; // 'Displays Menu' layout. if blank, use built-in menu std::string m_menu_layout; // 'Displays Menu' layout. if blank, use built-in menu
std::string m_menu_layout_file; // 'Displays Menu" toggled layout file std::string m_menu_layout_file; // 'Displays Menu" toggled layout file


std::string m_last_game_overview_path; // cache the last loaded game overview path
std::string m_last_game_overview_text; // cache the last loaded game overview text

std::vector<std::string> m_font_paths; std::vector<std::string> m_font_paths;
std::vector<FeDisplayInfo> m_displays; std::vector<FeDisplayInfo> m_displays;
std::vector<FePlugInfo> m_plugins; std::vector<FePlugInfo> m_plugins;
Expand Down Expand Up @@ -251,6 +253,9 @@ class FeSettings : public FeBaseConfigurable
const std::string &romname, const std::string &romname,
const std::map<GameExtra,std::string> &extras ); const std::map<GameExtra,std::string> &extras );


// sets path to filename for specified emu and romname. Returns true if file exists, false otherwise
bool get_game_overview_filepath( const std::string &emu, const std::string &romname, std::string &path );

public: public:
FeSettings( const std::string &config_dir, FeSettings( const std::string &config_dir,
const std::string &cmdln_font ); const std::string &cmdln_font );
Expand Down Expand Up @@ -489,6 +494,11 @@ class FeSettings : public FeBaseConfigurable
void set_game_extra( GameExtra id, const std::string &value ); void set_game_extra( GameExtra id, const std::string &value );
void save_game_extras(); void save_game_extras();


bool get_game_overview_absolute( int filter_index, int rom_index, std::string &overview );

// only overwrites an existing file if overwrite = true
void set_game_overview( const std::string &emu, const std::string &romname, const std::string &overview, bool overwrite );

// This function implements the config-mode romlist generation // This function implements the config-mode romlist generation
// A romlist named "<emu_name>.txt" is created in the romlist dir, // A romlist named "<emu_name>.txt" is created in the romlist dir,
// overwriting any previous list of this name. // overwriting any previous list of this name.
Expand Down
21 changes: 21 additions & 0 deletions src/fe_util.cpp
Expand Up @@ -1228,6 +1228,27 @@ std::string url_escape( const std::string &raw )
return escaped.str(); return escaped.str();
} }


std::string newline_escape( const std::string &raw )
{
std::string temp;
size_t pos1=0, pos=0;

while ( ( pos = raw.find( "\n", pos1 ) ) != std::string::npos )
{
temp += raw.substr( pos1, pos-pos1 );
temp += "\\n";
pos1 = pos+1;
}
temp += raw.substr( pos1 );

return temp;
}

void remove_trailing_spaces( std::string &str )
{
str.erase( str.find_last_not_of( " \n\r\t" )+1 );
}

void get_url_components( const std::string &url, void get_url_components( const std::string &url,
std::string &host, std::string &host,
std::string &req ) std::string &req )
Expand Down
3 changes: 3 additions & 0 deletions src/fe_util.hpp
Expand Up @@ -257,6 +257,9 @@ void print_ffmpeg_version_info();
#endif #endif


std::string url_escape( const std::string &raw ); std::string url_escape( const std::string &raw );
std::string newline_escape( const std::string &raw );

void remove_trailing_spaces( std::string &str );


void get_url_components( const std::string &url, void get_url_components( const std::string &url,
std::string &host, std::string &host,
Expand Down
12 changes: 5 additions & 7 deletions src/fe_vm.cpp
Expand Up @@ -2256,14 +2256,12 @@ const char *FeVM::cb_game_info( int index, int offset, int filter_offset )
else if ( index == FeRomInfo::LAST_INDEX+1 ) else if ( index == FeRomInfo::LAST_INDEX+1 )
{ {
// Overview // Overview
retval.clear(); int filter_index = fev->m_feSettings->get_filter_index_from_offset( filter_offset );
if (( offset == 0 ) && ( filter_offset == 0 ))
retval = fev->m_feSettings->get_game_extra( FeSettings::Overview ).c_str(); fev->m_feSettings->get_game_overview_absolute( filter_index,
// fev->m_feSettings->get_rom_index( filter_index, offset ),
//TODO: loading overview where there is a filter or index offset is not yet implemented retval );
//


perform_substitution( retval, "\\n", "\n" );
return retval.c_str(); return retval.c_str();
} }


Expand Down

0 comments on commit 88595c8

Please sign in to comment.