Skip to content

Commit

Permalink
Various scraper/list generation fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickelson committed May 5, 2015
1 parent e32f7aa commit e323a5f
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 67 deletions.
69 changes: 42 additions & 27 deletions src/fe_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ bool FeSettings::mamedb_scraper( FeImporterContext &c )
if ( id < 0 )
{
if ( id == -1 )
{
std::cout << " + Downloaded: " << result << std::endl;
c.download_count++;
}

done++;
}
Expand Down Expand Up @@ -399,7 +402,10 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c )

if ( status != sf::Http::Response::Ok )
{
std::cout << "[thegamesdb.net scraper] Error getting platform list. Code: " << status << std::endl;
get_resource( "Error getting platform list from thegamesdb.net. Code: $1",
as_str( status ), c.user_message );

std::cout << " * " << c.user_message << std::endl;
return true;
}

Expand All @@ -417,7 +423,7 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
if ( gdbpp.m_set.find( *itr ) != gdbpp.m_set.end() )
system_list.push_back( *itr );
else
std::cout << "[thegamesdb.net scraper] System identifier '" << (*itr) << "' not recognized by "
std::cout << " * System identifier '" << (*itr) << "' not recognized by "
<< HOSTNAME << std::endl;
}

Expand All @@ -432,7 +438,10 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
system_list.push_back( "PC" );
else
{
std::cout << "[thegamesdb.net scraper] Error, no valid system identifier found." << std::endl;
get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.",
c.user_message );

std::cout << " * " << c.user_message << std::endl;
return true;
}
}
Expand All @@ -459,31 +468,30 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
const int NUM_ARTS=5; // the number of scrape-able artwork types
int done_count( 0 );

std::string base_req_string = GAME_REQ;

//
// If we aren't scraping wheel artwork, then add the specific platform to our request
// If we are scraping wheels, we want to be able to grab them where the game name (but
// not the system) matches
//
if (( system_list.size() == 1 )
&& ( !c.scrape_art || !m_scrape_wheels ))
{
base_req_string += "&platform=";
base_req_string += url_escape( system_list.front() );
}

//
// Set up our initial queue of network tasks
//
for ( unsigned int i=0; i<worklist.size(); i++ )
{
std::string req_string = base_req_string;
std::string req_string = GAME_REQ;

std::string game = url_escape(
name_with_brackets_stripped( worklist[i]->get_info( FeRomInfo::Title ) ) );

perform_substitution( req_string, "$1", game );

//
// If we don't need to scrape a wheel artwork, then add the specific platform to our request
// If we are scraping a wheel, we want to be able to grab them where the game name (but
// not the system) matches, so we don't limit ourselves by system...
//
if (( system_list.size() == 1 )
&& ( !c.scrape_art || !m_scrape_wheels || has_artwork( *(worklist[i]), "wheel" ) ))
{
req_string += "&platform=";
req_string += url_escape( system_list.front() );
}

q.add_buffer_task( HOSTNAME, req_string, i );
}

Expand All @@ -508,7 +516,10 @@ bool FeSettings::thegamesdb_scraper( FeImporterContext &c )
if ( id < 0 )
{
if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask ))
std::cout << " * Downloaded: " << result << std::endl;
{
std::cout << " + Downloaded: " << result << std::endl;
c.download_count++;
}

if ( id == FeNetTask::FileTask ) // we don't increment if id = FeNetTask::SpecialFileTask
done_count++;
Expand Down Expand Up @@ -645,13 +656,13 @@ void FeSettings::apply_xml_import( FeImporterContext &c )
{
std::cout << " - Obtaining -listxml info...";
FeMameXMLParser mamep( c );
mamep.parse( base_command );
std::cout << std::endl;
if ( !mamep.parse( base_command ) )
std::cout << "No XML output found, command: " << base_command << " -listxml" << std::endl;
}
else if ( source.compare( "mess" ) == 0 )
{
std::string system_name = c.emulator.get_info( FeEmulatorInfo::System );
if ( system_name.empty() )
const std::vector < std::string > &system_names = c.emulator.get_systems();
if ( system_names.empty() )
{
std::cout << "Note: No system configured for emulator: "
<< c.emulator.get_info( FeEmulatorInfo::Name )
Expand All @@ -660,10 +671,8 @@ void FeSettings::apply_xml_import( FeImporterContext &c )
return;
}

std::cout << " - Obtaining -listsoftware info...";
FeMessXMLParser messp( c );
messp.parse( base_command, system_name );
std::cout << std::endl;
messp.parse( base_command, system_names );
}
else if ( source.compare( "steam" ) == 0 )
{
Expand Down Expand Up @@ -997,7 +1006,7 @@ bool FeSettings::build_romlist( const std::string &emu_name, UiUpdate uiu, void
return true;
}

bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid )
bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid, std::string &msg )
{
FeEmulatorInfo *emu = m_rl.get_emulator( emu_name );
if ( emu == NULL )
Expand Down Expand Up @@ -1050,5 +1059,11 @@ bool FeSettings::scrape_artwork( const std::string &emu_name, UiUpdate uiu, void
uiu( uid, 100 );

std::cout << "*** Scraping done." << std::endl;

if ( ctx.user_message.empty() )
get_resource( "Scraped $1 artwork file(s)", as_str( ctx.download_count ), msg );
else
msg = ctx.user_message;

return true;
}
4 changes: 2 additions & 2 deletions src/fe_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ bool FeEmulatorEditMenu::on_option_select(
m_parent_save = true;
}
break;
case 4: // Generate Romlist
case 4: // Scrape Artwork
{
std::string emu_name = m_emulator->get_info( FeEmulatorInfo::Name );
ctx.fe_settings.scrape_artwork( emu_name, scrape_ui_update, &ctx );
ctx.fe_settings.scrape_artwork( emu_name, scrape_ui_update, &ctx, ctx.help_msg );
}
break;
case 5: // Delete this Emulator
Expand Down
2 changes: 1 addition & 1 deletion src/fe_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ FeTextPrimative *FeListBox::setEditMode( bool e, sf::Color c )
{
m_texts[ sel ].setColor( c );
m_texts[ sel ].setOutlineColor( c );
m_texts[ sel ].setOutlineThickness( -2 );
m_texts[ sel ].setOutlineThickness( -1 );

return &(m_texts[ sel ]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fe_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class FeSettings : public FeBaseConfigurable
//
typedef bool (*UiUpdate) ( void *, int );
bool build_romlist( const std::string &emu_name, UiUpdate, void *, int & );
bool scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid );
bool scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid, std::string &msg );

FeEmulatorInfo *get_emulator( const std::string & );
FeEmulatorInfo *create_emulator( const std::string & );
Expand Down
82 changes: 54 additions & 28 deletions src/fe_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ FeImporterContext::FeImporterContext( const FeEmulatorInfo &e, FeRomInfoListType
uiupdatedata( NULL ),
full( false ),
progress_past( 0 ),
progress_range( 100 )
progress_range( 100 ),
download_count( 0 )
{
}

Expand Down Expand Up @@ -426,6 +427,10 @@ bool FeMameXMLParser::parse( const std::string &prog )
FeRomInfoListType::iterator itr;
m_percent=m_count=0;

// special case for mess parsing
if ( m_ctx.romlist.size() == 1 )
return ( parse_internal( prog, base_args + " " + m_ctx.romlist.front().get_info( FeRomInfo::Romname ) ) );

//
// run "mame -listxml" and find each rom.
//
Expand All @@ -438,15 +443,15 @@ bool FeMameXMLParser::parse( const std::string &prog )

if ( parse_internal( prog, base_args ) == false )
{
std::cout << "No XML output found, command: " << prog << " "
<< base_args << std::endl;
std::cout << std::endl;
return false;
}

std::cout << std::endl;

if ( !m_discarded.empty() )
{
std::cout << "Discarded " << m_discarded.size()
std::cout << " - Discarded " << m_discarded.size()
<< " entries based on xml info: ";
std::vector<FeRomInfoListType::iterator>::iterator itr;
for ( itr = m_discarded.begin(); itr != m_discarded.end(); ++itr )
Expand Down Expand Up @@ -604,43 +609,64 @@ void FeMessXMLParser::set_info_values( FeRomInfo &r )
}

bool FeMessXMLParser::parse( const std::string &prog,
const std::string &system_name )
const std::vector < std::string > &system_names )
{
// First get our machine -listxml settings
//
FeRomInfoListType temp_list;
temp_list.push_back( FeRomInfo( system_name ) );

FeEmulatorInfo ignored;
FeImporterContext temp( ignored, temp_list );
FeMameXMLParser listxml( temp );
listxml.parse( prog );

std::string system_name;
FeRomInfoListType::iterator itr;
if ( !temp_list.empty() )

for ( std::vector<std::string>::const_iterator its=system_names.begin(); its!=system_names.end(); ++its )
{
const FeRomInfo &ri = temp_list.front();
for ( itr=m_ctx.romlist.begin(); itr!=m_ctx.romlist.end(); ++itr )
FeRomInfoListType temp_list;
temp_list.push_back( FeRomInfo( *its ) );

FeEmulatorInfo ignored;
FeImporterContext temp( ignored, temp_list );
FeMameXMLParser listxml( temp );

if (( listxml.parse( prog ) )
&& ( !temp_list.empty() ))
{
(*itr).set_info( FeRomInfo::Players, ri.get_info( FeRomInfo::Players ));
(*itr).set_info( FeRomInfo::Rotation, ri.get_info( FeRomInfo::Rotation ));
(*itr).set_info( FeRomInfo::Control, ri.get_info( FeRomInfo::Control ));
(*itr).set_info( FeRomInfo::Status, ri.get_info( FeRomInfo::Status ));
(*itr).set_info( FeRomInfo::DisplayCount, ri.get_info( FeRomInfo::DisplayCount ));
(*itr).set_info( FeRomInfo::DisplayType, ri.get_info( FeRomInfo::DisplayType ));

// A bit of a hack here: the Category field gets repurposed for this stage of a MESS
// import...We temporarily store a "fuzzy" match romname
//
(*itr).set_info( FeRomInfo::BuildScratchPad,
get_fuzzy( (*itr).get_info( FeRomInfo::Romname ) ) );
const FeRomInfo &ri = temp_list.front();
for ( itr=m_ctx.romlist.begin(); itr!=m_ctx.romlist.end(); ++itr )
{
(*itr).set_info( FeRomInfo::Players, ri.get_info( FeRomInfo::Players ));
(*itr).set_info( FeRomInfo::Rotation, ri.get_info( FeRomInfo::Rotation ));
(*itr).set_info( FeRomInfo::Control, ri.get_info( FeRomInfo::Control ));
(*itr).set_info( FeRomInfo::Status, ri.get_info( FeRomInfo::Status ));
(*itr).set_info( FeRomInfo::DisplayCount, ri.get_info( FeRomInfo::DisplayCount ));
(*itr).set_info( FeRomInfo::DisplayType, ri.get_info( FeRomInfo::DisplayType ));

// A bit of a hack here: the Category field gets repurposed for this stage of a MESS
// import...We temporarily store a "fuzzy" match romname
//
(*itr).set_info( FeRomInfo::BuildScratchPad,
get_fuzzy( (*itr).get_info( FeRomInfo::Romname ) ) );
}
system_name=(*its);
break;
}
}

if ( system_name.empty() )
{
std::cerr << " * Error: No system identifier found that is recognized by MESS -listxml" << std::endl;
return false;
}

std::cout << " - Obtaining -listsoftware info [" << system_name << "]" << std::endl;

// Now get the individual game -listsoftware settings
//
int retval=parse_internal( prog, system_name + " -listsoftware" );

if ( !retval )
{
std::cout << " * Error: No XML output found, command: " << prog << " "
<< system_name + " -listsoftware" << std::endl;
}

// We're done with our "fuzzy" matching, so clear where we were storing them
//
for ( itr=m_ctx.romlist.begin(); itr!=m_ctx.romlist.end(); ++itr )
Expand Down
4 changes: 3 additions & 1 deletion src/fe_xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class FeImporterContext
bool full;
int progress_past;
int progress_range;
int download_count;
std::string user_message;
};

class FeMameXMLParser : private FeXMLParser
Expand Down Expand Up @@ -110,7 +112,7 @@ class FeMessXMLParser : private FeXMLParser
{
public:
FeMessXMLParser( FeImporterContext &ctx );
bool parse( const std::string &command, const std::string &args );
bool parse( const std::string &command, const std::vector < std::string > &system_names );

private:
FeImporterContext &m_ctx;
Expand Down
15 changes: 8 additions & 7 deletions src/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ void FeSprite::updateGeometry()
float right = left + m_textureRect.width;
float top = static_cast<float>(m_textureRect.top);
float bottom = top + m_textureRect.height;
sf::Color vert_colour = m_vertices[0].color;

if (( m_pinch.x != 0.f ) || ( m_pinch.y != 0.f ))
{
Expand All @@ -267,7 +268,6 @@ void FeSprite::updateGeometry()
float sys = (float)m_skew.y / SLICES;
float bpxs = bws - (float)m_pinch.x * 2 / SLICES;

sf::Color vert_colour = m_vertices[0].color;
m_vertices.resize( SLICES + 3 );
m_vertices.setPrimitiveType( sf::TrianglesStrip );

Expand Down Expand Up @@ -309,12 +309,6 @@ void FeSprite::updateGeometry()

m_vertices[SLICES + 1].texCoords = sf::Vector2f(right, top );
m_vertices[SLICES + 2].texCoords = sf::Vector2f(right, bottom );

//
// And finally the vertex colour
//
for ( unsigned int i=0; i< m_vertices.getVertexCount(); i++ )
m_vertices[i].color = vert_colour;
}
else
{
Expand All @@ -334,4 +328,11 @@ void FeSprite::updateGeometry()
m_vertices[2].texCoords = sf::Vector2f(right, top);
m_vertices[3].texCoords = sf::Vector2f(right, bottom);
}

//
// Finally, update the vertex colour
//
for ( unsigned int i=0; i< m_vertices.getVertexCount(); i++ )
m_vertices[i].color = vert_colour;

}

0 comments on commit e323a5f

Please sign in to comment.