Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to specify game in multi-romset #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions Src/GameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ void GameLoader::IdentifyGamesInZipArchive(

void GameLoader::ChooseGameInZipArchive(std::string *chosen_game, bool *missing_parent_roms, const ZipArchive &zip, const std::string &zipfilename) const
{
chosen_game->clear();
*missing_parent_roms = false;

// Find complete unmerged games (those that do not need to be merged with a
Expand Down Expand Up @@ -725,6 +724,25 @@ void GameLoader::ChooseGameInZipArchive(std::string *chosen_game, bool *missing_
ErrorLog("Ignoring game '%s' in '%s' because it is missing files.", v.first.c_str(), zipfilename.c_str());
}

std::set<std::string> candidates(complete_games);
candidates.insert(complete_merged_games.begin(), complete_merged_games.end());
candidates.insert(incomplete_child_games.begin(), incomplete_child_games.end());

// If named game requested, is it valid and complete?
if (!chosen_game->empty()) {
if (candidates.count(chosen_game->c_str()) < 1) {
auto it = m_game_info_by_game.find(chosen_game->c_str());
if (it == m_game_info_by_game.end())
{
ErrorLog("Cannot find unknown game '%s'. Is it defined in '%s'?", chosen_game->c_str(), m_xml_filename.c_str());
} else {
ErrorLog("Complete '%s' Model 3 game not found in '%s'.", chosen_game->c_str(), zipfilename.c_str());
}
chosen_game->clear();
}
return;
}

// Choose game: complete merged game > incomplete child game > complete
// unmerged game
if (!complete_merged_games.empty())
Expand All @@ -744,9 +762,6 @@ void GameLoader::ChooseGameInZipArchive(std::string *chosen_game, bool *missing_
}

// Print out which game we chose from valid candidates in the zip file
std::set<std::string> candidates(complete_games);
candidates.insert(complete_merged_games.begin(), complete_merged_games.end());
candidates.insert(incomplete_child_games.begin(), incomplete_child_games.end());
if (candidates.size() > 1)
ErrorLog("Multiple games found in '%s' (%s). Loading '%s'.", zipfilename.c_str(), Util::Format(", ").Join(candidates).str().c_str(), chosen_game->c_str());
}
Expand Down Expand Up @@ -968,7 +983,7 @@ std::string StripFilename(const std::string &filepath)
return std::string(filepath, 0, last_slash + 1);
}

bool GameLoader::Load(Game *game, ROMSet *rom_set, const std::string &zipfilename) const
bool GameLoader::Load(Game *game, ROMSet *rom_set, const std::string &zipfilename, const std::string &game_name) const
{
*game = Game();

Expand All @@ -978,7 +993,7 @@ bool GameLoader::Load(Game *game, ROMSet *rom_set, const std::string &zipfilenam
return true;

// Pick the game to load (there could be multiple ROM sets in a zip file)
std::string chosen_game;
std::string chosen_game = game_name;
bool missing_parent_roms = false;
ChooseGameInZipArchive(&chosen_game, &missing_parent_roms, zip, zipfilename);
if (chosen_game.empty())
Expand Down
2 changes: 1 addition & 1 deletion Src/GameLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class GameLoader

public:
GameLoader(const std::string &xml_file);
bool Load(Game *game, ROMSet *rom_set, const std::string &zipfilename) const;
bool Load(Game *game, ROMSet *rom_set, const std::string &zipfilename, const std::string &game_name) const;
const std::map<std::string, Game> &GetGames() const
{
return m_game_info_by_game;
Expand Down
15 changes: 14 additions & 1 deletion Src/OSD/SDL/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ static void Help(void)
printf(" -game-xml-file=<file> ROM set definition file [Default: %s]\n", s_gameXMLFilePath.c_str());
printf(" -log-output=<outputs> Log output destination(s) [Default: %s]\n", s_logFilePath.c_str());
puts(" -log-level=<level> Logging threshold [Default: info]");
puts(" -game=<name> Specific game to start in multi-romset");
puts("");
puts("Core Options:");
puts(" -ppc-frequency=<mhz> PowerPC frequency (default varies by stepping)");
Expand Down Expand Up @@ -1645,6 +1646,7 @@ struct ParsedCommandLine
{
Util::Config::Node config = Util::Config::Node("CommandLine");
std::vector<std::string> rom_files;
std::string game_name;
bool error = false;
bool print_help = false;
bool print_games = false;
Expand Down Expand Up @@ -1880,6 +1882,17 @@ static ParsedCommandLine ParseCommandLine(int argc, char **argv)
cmd_line.gfx_state = parts[1];
}
#endif
else if (arg == "-game" || arg.find("-game=") == 0)
{
std::vector<std::string> parts = Util::Format(arg).Split('=');
if (parts.size() != 2)
{
ErrorLog("'-game' requires a name.");
cmd_line.error = true;
}
else
cmd_line.game_name = parts[1];
}
else
{
ErrorLog("Ignoring unrecognized option: %s", argv[i]);
Expand Down Expand Up @@ -1973,7 +1986,7 @@ int main(int argc, char **argv)
PrintGameList(xml_file, loader.GetGames());
return 0;
}
if (loader.Load(&game, &rom_set, *cmd_line.rom_files.begin()))
if (loader.Load(&game, &rom_set, *cmd_line.rom_files.begin(), cmd_line.game_name))
return 1;
Util::Config::MergeINISections(&config4, config3, fileConfig[game.name]); // apply game-specific config
}
Expand Down