Card Database converter (#3694)

* Database converter

* Fix win compilation and NSIS installer

* Maybe fix windows again

* Re-fix windows
This commit is contained in:
ctrlaltca 2019-05-31 17:48:30 +02:00 committed by Zach H
parent 8682367b52
commit ada13f6578
8 changed files with 301 additions and 1 deletions

67
dbconverter/src/main.cpp Normal file
View file

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2019 by Fabio Bas *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QFileInfo>
#include <QtGlobal>
#include <QDebug>
#include "version_string.h"
#include "mocks.h"
#include "main.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
app.setOrganizationName("Cockatrice");
app.setApplicationName("Dbconverter");
app.setApplicationVersion(VERSION_STRING);
QCommandLineParser parser;
parser.addPositionalArgument("olddb", "Read existing card database from <file>");
parser.addPositionalArgument("newdb", "Write new card database to <file>");
parser.addHelpOption();
parser.addVersionOption();
parser.process(app);
QString oldDbPath;
QString newDbPath;
QStringList args = parser.positionalArguments();
if (args.count() == 2)
{
oldDbPath = QFileInfo(args.at(0)).absoluteFilePath();
newDbPath = QFileInfo(args.at(1)).absoluteFilePath();
} else {
qCritical() << "Usage: dbconverter <olddb> <newdb>";
parser.showHelp(1);
exit(0);
}
settingsCache = new SettingsCache;
CardDatabaseConverter *db = new CardDatabaseConverter;
qInfo() << "---------------------------------------------";
qInfo() << "Loading cards from" << oldDbPath;
db->loadCardDatabase(oldDbPath);
qInfo() << "---------------------------------------------";
qInfo() << "Saving cards to" << newDbPath;
db->saveCardDatabase(newDbPath);
qInfo() << "---------------------------------------------";
}

20
dbconverter/src/main.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef MAIN_H
#define MAIN_H
#include "../../cockatrice/src/carddatabase.h"
#include "../../cockatrice/src/carddbparser/cockatricexml4.h"
class CardDatabaseConverter : public CardDatabase
{
public:
LoadStatus loadCardDatabase(const QString &path) {
return CardDatabase::loadCardDatabase(path);
}
bool saveCardDatabase(const QString &fileName) {
CockatriceXml4Parser parser;
return parser.saveToFile(sets, cards, fileName);
}
};
#endif

53
dbconverter/src/mocks.cpp Normal file
View file

@ -0,0 +1,53 @@
#include "mocks.h"
void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */){};
void CardDatabaseSettings::setEnabled(QString /* shortName */, bool /* enabled */){};
void CardDatabaseSettings::setIsKnown(QString /* shortName */, bool /* isknown */){};
unsigned int CardDatabaseSettings::getSortKey(QString /* shortName */)
{
return 0;
};
bool CardDatabaseSettings::isEnabled(QString /* shortName */)
{
return true;
};
bool CardDatabaseSettings::isKnown(QString /* shortName */)
{
return true;
};
SettingsCache::SettingsCache()
{
cardDatabaseSettings = new CardDatabaseSettings();
};
SettingsCache::~SettingsCache()
{
delete cardDatabaseSettings;
};
QString SettingsCache::getCustomCardDatabasePath() const
{
return "";
}
QString SettingsCache::getCardDatabasePath() const
{
return "";
}
QString SettingsCache::getTokenDatabasePath() const
{
return "";
}
QString SettingsCache::getSpoilerCardDatabasePath() const
{
return "";
}
CardDatabaseSettings &SettingsCache::cardDatabase() const
{
return *cardDatabaseSettings;
}
void PictureLoader::clearPixmapCache(CardInfoPtr /* card */)
{
}
SettingsCache *settingsCache;

50
dbconverter/src/mocks.h Normal file
View file

@ -0,0 +1,50 @@
/*
* Beware of this preprocessor hack used to redefine the settingCache class
* instead of including it and all of its dependencies.
*/
#include <QObject>
#include <QString>
#define SETTINGSCACHE_H
#define PICTURELOADER_H
#include "../../cockatrice/src/carddatabase.h"
class CardDatabaseSettings
{
public:
void setSortKey(QString shortName, unsigned int sortKey);
void setEnabled(QString shortName, bool enabled);
void setIsKnown(QString shortName, bool isknown);
unsigned int getSortKey(QString shortName);
bool isEnabled(QString shortName);
bool isKnown(QString shortName);
};
class SettingsCache : public QObject
{
Q_OBJECT
private:
CardDatabaseSettings *cardDatabaseSettings;
public:
SettingsCache();
~SettingsCache();
QString getCustomCardDatabasePath() const;
QString getCardDatabasePath() const;
QString getTokenDatabasePath() const;
QString getSpoilerCardDatabasePath() const;
CardDatabaseSettings &cardDatabase() const;
signals:
void cardDatabasePathChanged();
};
extern SettingsCache *settingsCache;
class PictureLoader
{
public:
static void clearPixmapCache(CardInfoPtr card);
};