Skip to content

Commit

Permalink
Refactorings cache help (#77)
Browse files Browse the repository at this point in the history
* Minor textual corrections

* refactorings for report:missing=help
  • Loading branch information
Gemba authored Jun 30, 2024
1 parent 1374279 commit da9532e
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 221 deletions.
79 changes: 26 additions & 53 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "cache.h"

#include "cli.h"
#include "nametools.h"
#include "queue.h"

Expand Down Expand Up @@ -61,26 +62,24 @@ static inline QStringList binTypes(bool withVideo = true,
return binTypes;
};

const QStringList Cache::getAllResourceTypes() {
return txtTypes() + binTypes();
}

Cache::Cache(const QString &cacheFolder) { cacheDir = QDir(cacheFolder); }

bool Cache::createFolders(const QString &scraper) {
if (scraper != "cache") {
for (auto const &f : binTypes()) {
if (!cacheDir.mkpath(
QString("%1/%2s/%3") // plural 's'
.arg(cacheDir.absolutePath(), f, scraper))) {
return false;
}
for (auto const &f : binTypes()) {
if (!cacheDir.mkpath(QString("%1/%2s/%3") // plural 's'
.arg(cacheDir.absolutePath(), f, scraper))) {
return false;
}
}

// Copy priorities.xml example file to cache folder if it doesn't already
// exist
if (!QFileInfo::exists(cacheDir.absolutePath() + "/priorities.xml")) {
QFile::copy("cache/priorities.xml.example",
cacheDir.absolutePath() + "/priorities.xml");
}

QFile::copy("cache/priorities.xml.example",
cacheDir.absolutePath() + "/priorities.xml");
return true;
}

Expand Down Expand Up @@ -862,7 +861,7 @@ QList<QFileInfo> Cache::getFileInfos(const QString &inputFolder,
printf("\nInput folder returned no entries...\n\n");
}
} else {
printf("Found less than 2 suffix filters. Something is wrong...\n");
printf("Found less than two suffix filters. Something is wrong...\n");
}
return fileInfos;
}
Expand Down Expand Up @@ -893,8 +892,9 @@ void Cache::assembleReport(const Settings &config, const QString filter) {
QString reportStr = config.cacheOptions;

if (!reportStr.contains("report:missing=")) {
printf("Don't understand report option, please check '--cache help' "
"for more info.\n");
printf("\033[1;31mAmbiguous cache report option '%s'.\n\033[0m",
reportStr.toStdString().c_str());
Cli::cacheReportMissingUsage();
return;
}
reportStr.replace("report:missing=", "");
Expand All @@ -906,56 +906,29 @@ void Cache::assembleReport(const Settings &config, const QString filter) {
} else {
if (missingOption == "all") {
resTypeList += txtTypes(false); // contains 'tags' instead 'genres'
resTypeList += binTypes();
resTypeList.sort();
QStringList bt = binTypes();
bt.sort();
resTypeList += bt;
} else if (missingOption == "textual") {
resTypeList += txtTypes(false);
resTypeList.sort();
} else if (missingOption == "artwork") {
resTypeList += binTypes(false, false); // w/o 'video' or 'manual'
resTypeList += binTypes(false, false); // w/o 'video' and 'manual'
resTypeList.sort();
} else if (missingOption == "media") {
resTypeList += binTypes();
resTypeList.sort();
} else {
resTypeList.append(missingOption); // If a single type is given
}
}
for (const auto &resType : resTypeList) {
if (!binTypes().contains(resType) &&
!txtTypes(false).contains(resType)) {
if (resType != "help") {
printf("\033[1;31mUnknown resource type '%s'!\033[0m\n",
resType.toStdString().c_str());
}
printf("Please use one of the following:\n");
printf(" \033[1;32mhelp\033[0m: Shows this help message\n");
printf(" \033[1;32mall\033[0m: Creates reports for all resource "
"types\n");
printf(" \033[1;32mtextual\033[0m: Creates reports for all "
"textual resource types\n");
printf(" \033[1;32martwork\033[0m: Creates reports for all "
"artwork related resource types excluding 'video'\n");
printf(" \033[1;32mmedia\033[0m: Creates reports for all media "
"resource types including 'video'\n");
printf(
" \033[1;32mtype1,type2,type3,...\033[0m: Creates reports for "
"selected types. Example: 'developer,screenshot,rating'\n");
printf("\nAvailable resource types:\n");
printf(" \033[1;32mtitle\033[0m\n");
printf(" \033[1;32mplatform\033[0m\n");
printf(" \033[1;32mdescription\033[0m\n");
printf(" \033[1;32mpublisher\033[0m\n");
printf(" \033[1;32mdeveloper\033[0m\n");
printf(" \033[1;32mplayers\033[0m\n");
printf(" \033[1;32mages\033[0m\n");
printf(" \033[1;32mtags\033[0m\n");
printf(" \033[1;32mrating\033[0m\n");
printf(" \033[1;32mreleasedate\033[0m\n");
printf(" \033[1;32mcover\033[0m\n");
printf(" \033[1;32mscreenshot\033[0m\n");
printf(" \033[1;32mwheel\033[0m\n");
printf(" \033[1;32mmarquee\033[0m\n");
printf(" \033[1;32mtexture\033[0m\n");
printf(" \033[1;32mvideo\033[0m\n");
printf(" \033[1;32mmanual\033[0m\n");
printf("\n");
printf("\033[1;31mUnknown resource type '%s'!\033[0m\n",
resType.toStdString().c_str());
Cli::cacheReportMissingUsage();
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct ResCounts {
class Cache {
public:
Cache(const QString &cacheFolder);
static const QStringList getAllResourceTypes();
bool createFolders(const QString &scraper);
bool read();
void printPriorities(QString cacheId);
Expand Down
23 changes: 22 additions & 1 deletion src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "cli.h"

#include "cache.h"
#include "strtools.h"

#include <QCommandLineOption>
Expand Down Expand Up @@ -378,7 +379,7 @@ QMap<QString, QString> Cli::getSubCommandOpts(const QString subCmd) {
"scraping module. Requires a scraping module set with "
"'-s'. Similar to '--refresh'."},
};
} else {
} else if (subCmd == "flags") {
m = {
{"help", "Prints this help and exits."},
{"forcefilename",
Expand Down Expand Up @@ -473,6 +474,26 @@ QMap<QString, QString> Cli::getSubCommandOpts(const QString subCmd) {
"Enables scraping and caching of manuals for the scraping modules "
"that support them."},
};
} else {
QStringList resTypes = Cache::getAllResourceTypes();
resTypes.sort();
m = {
{"help", "Shows this help message and exits."},
{"all", "Creates reports for all resource types."},
{"textual", "Creates reports for all textual resource types."},
{"artwork", "Creates reports for all artwork related resource "
"types excluding 'video' and 'manual'."},
{"media", "Creates reports for all media resource types including "
"'video' and 'manual'."},
{"type1,type2,type3,...",
"Creates reports for selected types. Example: "
"'developer,screenshot,rating'. Available resource types: " +
resTypes.join(", ")},
};
}
return m;
}

void Cli::cacheReportMissingUsage() {
subCommandUsage("cache report:missing=");
}
1 change: 1 addition & 0 deletions src/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Cli {
void createParser(QCommandLineParser *parser, const QString platforms);
void subCommandUsage(const QString subCmd);
QMap<QString, QString> getSubCommandOpts(const QString subCmd);
void cacheReportMissingUsage();
} // namespace Cli

#endif // CLI_H
17 changes: 11 additions & 6 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#endif

static inline bool isArcadePlatform(const QString &platform) {
const QStringList arcadePlaforms = {"arcade", "fba",
"mame-advmame", "mame-libretro",
"mame-mame4all", "neogeo"};
return arcadePlaforms.contains(platform);
const QStringList arcadePlatforms = {"arcade", "fba",
"mame-advmame", "mame-libretro",
"mame-mame4all", "neogeo"};
return arcadePlatforms.contains(platform);
}

RuntimeCfg::RuntimeCfg(Settings *config, const QCommandLineParser *parser) {
Expand All @@ -62,8 +62,9 @@ void RuntimeCfg::applyConfigIni(CfgType type, QSettings *settings,
// config.ini may set platform= in [main]
config->platform = settings->value("platform").toString();
} else {
bool cacheHelp =
parser->isSet("cache") && parser->value("cache") == "help";
bool cacheHelp = parser->isSet("cache") &&
(parser->value("cache") == "help" ||
parser->value("cache") == "report:missing=help");
QStringList flags = parseFlags();
if (!cacheHelp && !flags.contains("help")) {
if (parser->isSet("p")) {
Expand Down Expand Up @@ -585,9 +586,13 @@ void RuntimeCfg::applyCli(bool &inputFolderSet, bool &gameListFolderSet,
config->cacheOptions = parser->value("cache");
if (config->cacheOptions == "refresh") {
config->refresh = true;
config->cacheOptions = "";
} else if (config->cacheOptions == "help") {
Cli::subCommandUsage("cache");
exit(0);
} else if (config->cacheOptions == "report:missing=help") {
Cli::cacheReportMissingUsage();
exit(0);
}
}
if (parser->isSet("startat")) {
Expand Down
Loading

0 comments on commit da9532e

Please sign in to comment.