From 4e09d6357ea1fcac85b90b0d72e13635bc570d06 Mon Sep 17 00:00:00 2001 From: Sude Date: Fri, 6 Aug 2021 11:46:07 +0300 Subject: [PATCH] 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 --- main.cpp | 2 +- src/util.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index c951c03..0df9004 100644 --- a/main.cpp +++ b/main.cpp @@ -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 + "'"; // 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 std::string include_options_text; diff --git a/src/util.cpp b/src/util.cpp index fefb937..7650b21 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -410,6 +410,16 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g 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, "%dlcname%", dlcname)); while (Util::replaceString(str, "%platform%", platform));