Config: Fix preceeding '/' in deducted game title

Also factor out the common code path
This commit is contained in:
Jonas Kulla 2014-01-05 10:31:15 +01:00
parent 19dc83a5d5
commit e9cf77dbce
1 changed files with 12 additions and 11 deletions

View File

@ -108,15 +108,21 @@ void Config::read()
#undef PO_DESC_ALL
}
static std::string baseName(const std::string &path)
{
size_t pos = path.find_last_of("/\\") + 1;
if (pos == path.npos)
pos = 0;
return path.substr(pos);
}
void Config::readGameINI()
{
if (!customScript.empty())
{
size_t pos = customScript.find_last_of("/\\");
if (pos == customScript.npos)
pos = 0;
game.title = customScript.substr(pos);
game.title = baseName(customScript);
return;
}
@ -143,10 +149,5 @@ void Config::readGameINI()
strReplace(game.scripts, '\\', '/');
if (game.title.empty())
{
size_t pos = gameFolder.find_last_of("/\\");
if (pos == gameFolder.npos)
pos = 0;
game.title = gameFolder.substr(pos);
}
game.title = baseName(gameFolder);
}