Card Database converter (#3694)
* Database converter * Fix win compilation and NSIS installer * Maybe fix windows again * Re-fix windows
This commit is contained in:
parent
8682367b52
commit
ada13f6578
8 changed files with 301 additions and 1 deletions
|
@ -255,6 +255,13 @@ if(WITH_ORACLE)
|
|||
SET(CPACK_INSTALL_CMAKE_PROJECTS "Oracle;Oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS})
|
||||
endif()
|
||||
|
||||
# Compile dbconverter (default on)
|
||||
option(WITH_DBCONVERTER "build oracle" ON)
|
||||
if(WITH_DBCONVERTER)
|
||||
add_subdirectory(dbconverter)
|
||||
SET(CPACK_INSTALL_CMAKE_PROJECTS "Dbconverter;Dbconverter;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS})
|
||||
endif()
|
||||
|
||||
# Compile tests (default off)
|
||||
option(TEST "build tests" OFF)
|
||||
if(TEST)
|
||||
|
|
|
@ -213,6 +213,7 @@ ${AndIf} ${FileExists} "$INSTDIR\portable.dat"
|
|||
Delete "$INSTDIR\uninstall.exe"
|
||||
Delete "$INSTDIR\cockatrice.exe"
|
||||
Delete "$INSTDIR\oracle.exe"
|
||||
Delete "$INSTDIR\dbconverter.exe"
|
||||
Delete "$INSTDIR\servatrice.exe"
|
||||
Delete "$INSTDIR\Qt*.dll"
|
||||
Delete "$INSTDIR\libmysql.dll"
|
||||
|
|
|
@ -437,7 +437,7 @@ public slots:
|
|||
LoadStatus loadCardDatabases();
|
||||
void addCard(CardInfoPtr card);
|
||||
void addSet(CardSetPtr set);
|
||||
private slots:
|
||||
protected slots:
|
||||
LoadStatus loadCardDatabase(const QString &path);
|
||||
signals:
|
||||
void cardDatabaseLoadingFailed();
|
||||
|
|
102
dbconverter/CMakeLists.txt
Normal file
102
dbconverter/CMakeLists.txt
Normal file
|
@ -0,0 +1,102 @@
|
|||
# CMakeLists for dbconverter directory
|
||||
|
||||
PROJECT(Dbconverter VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
SET(dbconverter_SOURCES
|
||||
src/main.cpp
|
||||
src/mocks.cpp
|
||||
../cockatrice/src/carddatabase.cpp
|
||||
../cockatrice/src/carddbparser/carddatabaseparser.cpp
|
||||
../cockatrice/src/carddbparser/cockatricexml3.cpp
|
||||
../cockatrice/src/carddbparser/cockatricexml4.cpp
|
||||
${VERSION_STRING_CPP}
|
||||
)
|
||||
|
||||
# Qt5
|
||||
find_package(Qt5 COMPONENTS Network Widgets REQUIRED)
|
||||
set(dbconverter_QT_MODULES Qt5::Core Qt5::Network Qt5::Widgets)
|
||||
SET(QT_DONT_USE_QTGUI TRUE)
|
||||
|
||||
# Build servatrice binary and link it
|
||||
ADD_EXECUTABLE(dbconverter MACOSX_BUNDLE ${dbconverter_SOURCES} ${dbconverter_MOC_SRCS})
|
||||
|
||||
if(MSVC)
|
||||
TARGET_LINK_LIBRARIES(dbconverter ${dbconverter_QT_MODULES} Qt5::WinMain)
|
||||
else()
|
||||
TARGET_LINK_LIBRARIES(dbconverter ${dbconverter_QT_MODULES})
|
||||
endif()
|
||||
|
||||
# install rules
|
||||
if(UNIX)
|
||||
if(APPLE)
|
||||
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME}")
|
||||
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.cockatrice.${PROJECT_NAME}")
|
||||
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME}-${PROJECT_VERSION}")
|
||||
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
|
||||
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION})
|
||||
set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
|
||||
|
||||
INSTALL(TARGETS dbconverter BUNDLE DESTINATION ./)
|
||||
else()
|
||||
# Assume linux
|
||||
INSTALL(TARGETS dbconverter RUNTIME DESTINATION bin/)
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
INSTALL(TARGETS dbconverter RUNTIME DESTINATION ./)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir dbconverter.app/Contents/Plugins)
|
||||
set(qtconf_dest_dir dbconverter.app/Contents/Resources)
|
||||
get_filename_component(QT_LIBRARY_DIR "${QT_LIBRARY_DIR}/.." ABSOLUTE)
|
||||
|
||||
# qt5 plugins: platforms, sqldrivers/mysql
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING
|
||||
PATTERN "*.dSYM" EXCLUDE
|
||||
PATTERN "*_debug.dylib" EXCLUDE
|
||||
PATTERN "platforms/*.dylib"
|
||||
)
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
Plugins = Plugins
|
||||
Translations = Resources/translations\")
|
||||
" COMPONENT Runtime)
|
||||
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE QTPLUGINS
|
||||
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\")
|
||||
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
||||
include(BundleUtilities)
|
||||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/dbconverter.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR};${MYSQLCLIENT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir Plugins)
|
||||
set(qtconf_dest_dir .)
|
||||
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/" DESTINATION ./ FILES_MATCHING PATTERN "*.dll")
|
||||
|
||||
# qt5 plugins: platforms, sqldrivers/mysql
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(platforms/.*)\\.dll"
|
||||
REGEX ".*d\\.dll" EXCLUDE)
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
Plugins = Plugins
|
||||
Translations = Resources/translations\")
|
||||
" COMPONENT Runtime)
|
||||
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE QTPLUGINS
|
||||
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
|
||||
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
||||
include(BundleUtilities)
|
||||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/dbconverter.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
67
dbconverter/src/main.cpp
Normal file
67
dbconverter/src/main.cpp
Normal 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
20
dbconverter/src/main.h
Normal 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
53
dbconverter/src/mocks.cpp
Normal 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
50
dbconverter/src/mocks.h
Normal 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);
|
||||
};
|
Loading…
Reference in a new issue