Add directory template %gamename_firstletter%

Feature request by "coffeecup" on GOG forums
Useful for sorting big libraries with --subdir-game option
Takes the first letter from %gamename%
If %gamename% begins with a number then 0 (zero) is used instead
This commit is contained in:
Sude 2021-08-06 11:46:07 +03:00
parent d307d22195
commit 4e09d6357e
2 changed files with 11 additions and 1 deletions

View File

@ -132,7 +132,7 @@ int main(int argc, char *argv[])
std::string check_orphans_text = "Check for orphaned files (files found on local filesystem that are not found on GOG servers). Sets regular expression filter (Perl syntax) for files to check. If no argument is given then the regex defaults to '" + orphans_regex_default + "'"; std::string check_orphans_text = "Check for orphaned files (files found on local filesystem that are not found on GOG servers). Sets regular expression filter (Perl syntax) for files to check. If no argument is given then the regex defaults to '" + orphans_regex_default + "'";
// Help text for subdir options // Help text for subdir options
std::string subdir_help_text = "\nTemplates:\n- %platform%\n- %gamename%\n- %dlcname%"; std::string subdir_help_text = "\nTemplates:\n- %platform%\n- %gamename%\n- %gamename_firstletter%\n- %dlcname%";
// Help text for include and exclude options // Help text for include and exclude options
std::string include_options_text; std::string include_options_text;

View File

@ -410,6 +410,16 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g
platform = "no_platform"; platform = "no_platform";
} }
std::string gamename_firstletter;
if (!gamename.empty())
{
if (std::isdigit(gamename.front()))
gamename_firstletter = "0";
else
gamename_firstletter = gamename.front();
}
while (Util::replaceString(str, "%gamename_firstletter%", gamename_firstletter));
while (Util::replaceString(str, "%gamename%", gamename)); while (Util::replaceString(str, "%gamename%", gamename));
while (Util::replaceString(str, "%dlcname%", dlcname)); while (Util::replaceString(str, "%dlcname%", dlcname));
while (Util::replaceString(str, "%platform%", platform)); while (Util::replaceString(str, "%platform%", platform));