mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Simplify loadCardDatabases.
Took 3 minutes Took 6 seconds
This commit is contained in:
parent
f6f4cb6ffd
commit
2b4e62ae41
2 changed files with 19 additions and 16 deletions
|
|
@ -290,8 +290,7 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path)
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadCardDatabases()
|
LoadStatus CardDatabase::loadCardDatabases()
|
||||||
{
|
{
|
||||||
reloadDatabaseMutex->lock();
|
QMutexLocker locker(reloadDatabaseMutex);
|
||||||
|
|
||||||
qCInfo(CardDatabaseLoadingLog) << "Card Database Loading Started";
|
qCInfo(CardDatabaseLoadingLog) << "Card Database Loading Started";
|
||||||
|
|
||||||
clear(); // remove old db
|
clear(); // remove old db
|
||||||
|
|
@ -302,24 +301,16 @@ LoadStatus CardDatabase::loadCardDatabases()
|
||||||
|
|
||||||
// find all custom card databases, recursively & following symlinks
|
// find all custom card databases, recursively & following symlinks
|
||||||
// then load them alphabetically
|
// then load them alphabetically
|
||||||
QDirIterator customDatabaseIterator(SettingsCache::instance().getCustomCardDatabasePath(), QStringList() << "*.xml",
|
for (int i = 0, n = collectCustomDatabasePaths().size(); i < n; ++i) {
|
||||||
QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
const auto &path = collectCustomDatabasePaths().at(i);
|
||||||
QStringList databasePaths;
|
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << path << ")";
|
||||||
while (customDatabaseIterator.hasNext()) {
|
loadCardDatabase(path);
|
||||||
customDatabaseIterator.next();
|
|
||||||
databasePaths.push_back(customDatabaseIterator.filePath());
|
|
||||||
}
|
|
||||||
databasePaths.sort();
|
|
||||||
|
|
||||||
for (auto i = 0; i < databasePaths.size(); ++i) {
|
|
||||||
const auto &databasePath = databasePaths.at(i);
|
|
||||||
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << databasePath << ")";
|
|
||||||
loadCardDatabase(databasePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AFTER all the cards have been loaded
|
// AFTER all the cards have been loaded
|
||||||
|
|
||||||
// resolve the reverse-related tags
|
// resolve the reverse-related tags
|
||||||
|
|
||||||
refreshCachedReverseRelatedCards();
|
refreshCachedReverseRelatedCards();
|
||||||
|
|
||||||
if (loadStatus == Ok) {
|
if (loadStatus == Ok) {
|
||||||
|
|
@ -331,10 +322,21 @@ LoadStatus CardDatabase::loadCardDatabases()
|
||||||
emit cardDatabaseLoadingFailed(); // bring up the settings dialog
|
emit cardDatabaseLoadingFailed(); // bring up the settings dialog
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadDatabaseMutex->unlock();
|
|
||||||
return loadStatus;
|
return loadStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList CardDatabase::collectCustomDatabasePaths()
|
||||||
|
{
|
||||||
|
QDirIterator it(SettingsCache::instance().getCustomCardDatabasePath(), {"*.xml"}, QDir::Files,
|
||||||
|
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
||||||
|
|
||||||
|
QStringList paths;
|
||||||
|
while (it.hasNext())
|
||||||
|
paths << it.next();
|
||||||
|
paths.sort();
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the card representing the preferred printing of the cardInfo
|
* Gets the card representing the preferred printing of the cardInfo
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ public:
|
||||||
void enableAllUnknownSets();
|
void enableAllUnknownSets();
|
||||||
void markAllSetsAsKnown();
|
void markAllSetsAsKnown();
|
||||||
void notifyEnabledSetsChanged();
|
void notifyEnabledSetsChanged();
|
||||||
|
static QStringList collectCustomDatabasePaths();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
LoadStatus loadCardDatabases();
|
LoadStatus loadCardDatabases();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue