Skip to content
Permalink
Browse files

Issue #391 - store overview information by emulator

- 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 88595c811b2ebe717d1c9ea116373531b92cc6cb
Showing with 197 additions and 65 deletions.
  1. +25 −9 src/fe_config.cpp
  2. +1 −0 src/fe_config.hpp
  3. +117 −17 src/fe_settings.cpp
  4. +12 −2 src/fe_settings.hpp
  5. +21 −0 src/fe_util.cpp
  6. +3 −0 src/fe_util.hpp
  7. +5 −7 src/fe_vm.cpp
  8. +11 −14 src/scraper_net.cpp
  9. +2 −16 src/scraper_xml.cpp
@@ -2448,7 +2448,8 @@ bool FeConfigMenu::save( FeConfigContext &ctx )
FeEditGameMenu::FeEditGameMenu()
: m_update_rl( false ),
m_update_stats( false ),
m_update_extras( false )
m_update_extras( false ),
m_update_overview( false )
{
}

@@ -2542,10 +2543,14 @@ 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;
int filter_idx = ctx.fe_settings.get_filter_index_from_offset( 0 );
int rom_idx = ctx.fe_settings.get_rom_index( filter_idx, 0 );

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.fe_settings.get_game_extra( FeSettings::Executable ),
@@ -2563,9 +2568,7 @@ void FeEditGameMenu::get_options( FeConfigContext &ctx )
m_update_stats=false;
m_update_rl=false;
m_update_extras=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 );
m_update_overview=false;

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

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

case 100: // Delete Game
if ( ctx.confirm_dialog( "Delete game '$1'?", ctx.opt_list[1].get_value() ) )
@@ -2648,9 +2654,19 @@ bool FeEditGameMenu::save( FeConfigContext &ctx )
if ( m_update_stats )
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 )
{
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();
@@ -482,6 +482,7 @@ class FeEditGameMenu : public FeBaseConfigMenu
bool m_update_rl;
bool m_update_stats;
bool m_update_extras;
bool m_update_overview;

public:
FeEditGameMenu();
@@ -123,6 +123,7 @@ const char *FE_LANGUAGE_FILE_EXTENSION = ".msg";
const char *FE_SWF_EXT = ".swf";
const char *FE_PLUGIN_FILE_EXTENSION = FE_LAYOUT_FILE_EXTENSION;
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_ROMLIST_SUBDIR = "romlists/";
const char *FE_SOUND_SUBDIR = "sounds/";
@@ -135,6 +136,7 @@ const char *FE_LOADER_SUBDIR = "loader/";
const char *FE_INTRO_SUBDIR = "intro/";
const char *FE_SCRAPER_SUBDIR = "scraper/";
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_LIST_DEFAULT = "default-display.cfg";
const char *FE_FILTER_DEFAULT = "default-filter.cfg";
@@ -1470,7 +1472,6 @@ namespace {
const char *game_extra_strings[] = {
"executable",
"args",
"overview",
NULL
};
};
@@ -1528,6 +1529,12 @@ bool FeSettings::load_game_extras(
if ( !in_file.is_open() )
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() )
{
std::string line, s, v;
@@ -1546,11 +1553,26 @@ bool FeSettings::load_game_extras(
}

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();

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;
}

@@ -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.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
@@ -2325,21 +2439,7 @@ 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<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" );
get_game_overview_absolute( filter_index, rom_index, rep );
break;

default:
@@ -143,8 +143,7 @@ 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
Overview
Arguments // custom arguments to override the configured emulator arguments
};

private:
@@ -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_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<FeDisplayInfo> m_displays;
std::vector<FePlugInfo> m_plugins;
@@ -251,6 +253,9 @@ class FeSettings : public FeBaseConfigurable
const std::string &romname,
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:
FeSettings( const std::string &config_dir,
const std::string &cmdln_font );
@@ -489,6 +494,11 @@ class FeSettings : public FeBaseConfigurable
void set_game_extra( GameExtra id, const std::string &value );
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
// A romlist named "<emu_name>.txt" is created in the romlist dir,
// overwriting any previous list of this name.
@@ -1228,6 +1228,27 @@ std::string url_escape( const std::string &raw )
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,
std::string &host,
std::string &req )
@@ -257,6 +257,9 @@ void print_ffmpeg_version_info();
#endif

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,
std::string &host,
@@ -2256,14 +2256,12 @@ const char *FeVM::cb_game_info( int index, int offset, int filter_offset )
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
//
int filter_index = fev->m_feSettings->get_filter_index_from_offset( filter_offset );

fev->m_feSettings->get_game_overview_absolute( filter_index,
fev->m_feSettings->get_rom_index( filter_index, offset ),
retval );

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

0 comments on commit 88595c8

Please sign in to comment.
You can’t perform that action at this time.