diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..07f05b95 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: cpp +compiler: + - gcc + - clang +script: mkdir build && cd build && cmake .. && make +before_install: + - sudo apt-get update -qq + - sudo apt-get install -y qtmobility-dev libprotobuf-dev protobuf-compiler libqt4-dev build-essential +cache: apt diff --git a/CMakeLists.txt b/CMakeLists.txt index 86a10e7f..16e2f0ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,11 +89,51 @@ set(CMAKE_AUTOMOC TRUE) # Find other needed libraries FIND_PACKAGE(Protobuf REQUIRED) +# Package builder +set(CPACK_PACKAGE_CONTACT "Daenyth+github@gmail.com") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}) +set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") + +if(UNIX) + if(APPLE) + set(CPACK_GENERATOR DragNDrop ${CPACK_GENERATOR}) + set(CPACK_GENERATOR "DragNDrop") + set(CPACK_DMG_FORMAT "UDBZ") + set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}") + set(CPACK_SYSTEM_NAME "OSX") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") + set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cockatrice/resources/appicon.icns") + else() + # linux + set(CPACK_GENERATOR DEB ${CPACK_GENERATOR}) + set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}/${PROJECT_VERSION}") + set(CPACK_STRIP_FILES "bin/${PROJECT_NAME}") + set(CPACK_SOURCE_STRIP_FILES "") + endif() +elseif(WIN32) + set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) + set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}\\\\${PROJECT_VERSION}") + set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${PROJECT_NAME}.exe") + set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}") + set(CPACK_NSIS_HELP_LINK "https://github.com/Daenyth/Cockatrice") + set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/Daenyth/Cockatrice") + set(CPACK_NSIS_CONTACT "Daenyth+github@gmail.com") + set(CPACK_NSIS_MODIFY_PATH ON) +endif() + +include(CPack) + # Compile servatrice (default off) option(WITH_SERVER "build servatrice" OFF) add_subdirectory(common) if(WITH_SERVER) add_subdirectory(servatrice) + SET(CPACK_INSTALL_CMAKE_PROJECTS "servatrice;servatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() # Compile cockatrice (default on) @@ -102,10 +142,12 @@ if(WITH_CLIENT) add_subdirectory(cockatrice) add_subdirectory(sounds) add_subdirectory(zonebg) + SET(CPACK_INSTALL_CMAKE_PROJECTS "cockatrice;cockatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() # Compile oracle (default on) option(WITH_ORACLE "build oracle" ON) if(WITH_ORACLE) add_subdirectory(oracle) + SET(CPACK_INSTALL_CMAKE_PROJECTS "release/oracle.app;oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() diff --git a/README.md b/README.md index 957a0249..ca8796b4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Cockatrice +[![Build Status](https://travis-ci.org/Daenyth/Cockatrice.svg?branch=master)](https://travis-ci.org/Daenyth/Cockatrice) + Cockatrice is an open-source multiplatform software for playing card games, such as Magic: The Gathering, over a network. It is fully client-server based to prevent any kind of cheating, though it supports single-player games without diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index e02f9e2c..92586891 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -130,6 +130,7 @@ set(COCKATRICE_LIBS) # Qt4 stuff if(Qt4_FOUND) if (NOT QT_QTMULTIMEDIA_FOUND) + SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) FIND_PACKAGE(QtMobility REQUIRED) endif (NOT QT_QTMULTIMEDIA_FOUND) @@ -255,8 +256,9 @@ add_custom_command( ) if(APPLE) - set(plugin_dest_dir ./cockatrice.app/Contents/Plugins) - set(qtconf_dest_dir ./cockatrice.app/Contents/Resources) + # these needs to be relative to CMAKE_INSTALL_PREFIX + set(plugin_dest_dir cockatrice.app/Contents/Plugins) + set(qtconf_dest_dir cockatrice.app/Contents/Resources) # note: no codecs in qt5 # note: phonon_backend => mediaservice @@ -271,13 +273,16 @@ if(APPLE) endif() install(CODE " - file(WRITE \"${qtconf_dest_dir}/qt.conf\" \"[Paths] -Plugins = Plugins\") - " COMPONENT Runtime) + file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] +Plugins = Plugins +Translations = Resources/translations +Data = Resources\") + " COMPONENT Runtime) install(CODE " file(GLOB_RECURSE QTPLUGINS - \"${plugin_dest_dir}/*.dylib\") + \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\") + set(BU_CHMOD_BUNDLE_ITEMS ON) include(BundleUtilities) fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") " COMPONENT Runtime) diff --git a/cockatrice/src/abstractgraphicsitem.h b/cockatrice/src/abstractgraphicsitem.h index 83cbf0db..f838dcd3 100644 --- a/cockatrice/src/abstractgraphicsitem.h +++ b/cockatrice/src/abstractgraphicsitem.h @@ -14,6 +14,7 @@ enum GraphicsItemType { class AbstractGraphicsItem : public QObject, public QGraphicsItem { Q_OBJECT + Q_INTERFACES(QGraphicsItem) protected: void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter); public: diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index c47eb7bc..395f25c1 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -105,15 +105,6 @@ int main(int argc, char *argv[]) qInstallMessageHandler(myMessageOutput); #endif } -#ifdef Q_OS_MAC - QDir baseDir(app.applicationDirPath()); - baseDir.cdUp(); - baseDir.cdUp(); - baseDir.cdUp(); - QDir pluginsDir = baseDir; - pluginsDir.cd("PlugIns"); - app.addLibraryPath(pluginsDir.absolutePath()); -#endif #ifdef Q_OS_WIN app.addLibraryPath(app.applicationDirPath() + "/plugins"); #endif @@ -129,11 +120,8 @@ int main(int argc, char *argv[]) if (translationPath.isEmpty()) { #ifdef Q_OS_MAC - QDir translationsDir = baseDir; - translationsDir.cd("translations"); - translationPath = translationsDir.absolutePath(); -#endif -#ifdef Q_OS_WIN + translationPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); +#elif Q_OS_WIN translationPath = app.applicationDirPath() + "/translations"; #endif } @@ -171,6 +159,43 @@ int main(int argc, char *argv[]) QDir().mkpath(dataDir + "/pics"); settingsCache->setPicsPath(dataDir + "/pics"); } + +#ifdef Q_OS_MAC + if(settingsCache->getHandBgPath().isEmpty() && + settingsCache->getStackBgPath().isEmpty() && + settingsCache->getTableBgPath().isEmpty() && + settingsCache->getPlayerBgPath().isEmpty()) + { + QString srcDir = QLibraryInfo::location(QLibraryInfo::DataPath); + QString destDir = dataDir + "/zonebg"; + QDir tmpDir(destDir); + if(!tmpDir.exists()) + { + // try to install the default images for the current user and set the settigs value + settingsCache->copyPath(srcDir + "/zonebg", destDir); + + settingsCache->setHandBgPath(destDir + "/fabric_green.png"); + settingsCache->setStackBgPath(destDir + "/fabric_red.png"); + settingsCache->setTableBgPath(destDir + "/fabric_blue.png"); + settingsCache->setPlayerBgPath(destDir + "/fabric_gray.png"); + } + } + + if(settingsCache->getSoundPath().isEmpty()) + { + QString srcDir = QLibraryInfo::location(QLibraryInfo::DataPath); + QString destDir = dataDir + "/sounds"; + QDir tmpDir(destDir); + if(!tmpDir.exists()) + { + // try to install the default sounds for the current user and set the settigs value + settingsCache->copyPath(srcDir + "/sounds", destDir); + + settingsCache->setSoundPath(destDir); + } + } +#endif + if (!settingsValid() || db->getLoadStatus() != Ok) { qDebug("main(): invalid settings or load status"); DlgSettings dlgSettings; diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 10dad8c9..892630f5 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -1,5 +1,7 @@ #include "settingscache.h" #include +#include +#include SettingsCache::SettingsCache() { @@ -257,3 +259,31 @@ void SettingsCache::setMainWindowGeometry(const QByteArray &_mainWindowGeometry) mainWindowGeometry = _mainWindowGeometry; settings->setValue("interface/main_window_geometry", mainWindowGeometry); } + +void SettingsCache::copyPath(const QString &src, const QString &dst) +{ + // test source && return if inexistent + QDir dir(src); + if (! dir.exists()) + return; + // test destination && create if inexistent + QDir tmpDir(dst); + if (!tmpDir.exists()) + { + tmpDir.setPath(QDir::rootPath()); + if (!tmpDir.mkdir(dst) && !tmpDir.exists()) { + // TODO: this is probably not good. + qDebug() << "copyPath(): Failed to create dir: " << dst; + } + } + + foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { + QString dst_path = dst + QDir::separator() + d; + dir.mkpath(dst_path); + copyPath(src+ QDir::separator() + d, dst_path); + } + + foreach (QString f, dir.entryList(QDir::Files)) { + QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f); + } +} diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index a9b9ce49..68b5129e 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -90,6 +90,7 @@ public: bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; } QString getPicUrl() const { return picUrl; } QString getPicUrlHq() const { return picUrlHq; } + void copyPath(const QString &src, const QString &dst); public slots: void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); void setLang(const QString &_lang); diff --git a/oracle/CMakeLists.txt b/oracle/CMakeLists.txt index 12dc6406..99abc4d1 100644 --- a/oracle/CMakeLists.txt +++ b/oracle/CMakeLists.txt @@ -97,8 +97,9 @@ IF (NOT WIN32 AND NOT APPLE) ENDIF (NOT WIN32 AND NOT APPLE) if(APPLE) - set(plugin_dest_dir ./oracle.app/Contents/Plugins) - set(qtconf_dest_dir ./oracle.app/Contents/Resources) + # these needs to be relative to CMAKE_INSTALL_PREFIX + set(plugin_dest_dir oracle.app/Contents/Plugins) + set(qtconf_dest_dir oracle.app/Contents/Resources) # note: no codecs in qt5 # note: phonon_backend => mediaservice @@ -113,13 +114,15 @@ if(APPLE) endif() install(CODE " - file(WRITE \"${qtconf_dest_dir}/qt.conf\" \"[Paths] -Plugins = Plugins\") - " COMPONENT Runtime) + file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] +Plugins = Plugins +Translations = Resources/translations\") + " COMPONENT Runtime) install(CODE " file(GLOB_RECURSE QTPLUGINS - \"${plugin_dest_dir}/*.dylib\") + \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\") + set(BU_CHMOD_BUNDLE_ITEMS ON) include(BundleUtilities) fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") " COMPONENT Runtime) diff --git a/prepareMacRelease.sh b/prepareMacRelease.sh deleted file mode 100644 index d1f58e26..00000000 --- a/prepareMacRelease.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -FRAMEWORKS="Core Gui Multimedia Network Svg Xml" -DATE=`date '+%Y%m%d'` -#QTDIR="/Users/brukie/QtSDK/Desktop/Qt/474/gcc" -QTLIB="/Users/brukie/qt_leopard/lib" -QTPLUGINS="/Users/brukie/qt_leopard/plugins" -PROTOBUF="/Users/brukie/protobuf_leopard" -DIR=cockatrice_mac_$DATE -if [ -d $DIR ]; then echo "delete old dir first"; exit 1; fi - -mkdir $DIR - -cp -R build/cockatrice/cockatrice.app $DIR -cp -R build/oracle/oracle.app $DIR -mkdir $DIR/Frameworks -cp -R sounds zonebg $DIR -mkdir $DIR/translations -cp build/cockatrice/*.qm $DIR/translations -cp -R $QTPLUGINS $DIR/PlugIns -for f in $FRAMEWORKS; do - cp -R $QTLIB/Qt"$f".framework $DIR/Frameworks -done -find $DIR/Frameworks -name '*debug*'|xargs -n 1 rm -f -find $DIR/Frameworks -name 'Headers'|xargs -n 1 rm -rf -find $DIR/PlugIns -name '*debug*'|xargs -n 1 rm -f -cp $PROTOBUF/lib/libprotobuf.7.dylib $DIR/Frameworks - -cd $DIR -for f in $FRAMEWORKS; do - echo "Framework $f" - echo "step 1" - install_name_tool -id @executable_path/../../../Frameworks/Qt"$f".framework/Versions/4/Qt"$f" Frameworks/Qt"$f".framework/Versions/4/Qt"$f" - for g in $FRAMEWORKS; do - install_name_tool -change $QTLIB/Qt"$f".framework/Versions/4/Qt"$f" @executable_path/../../../Frameworks/Qt"$f".framework/Versions/4/Qt"$f" Frameworks/Qt"$g".framework/Versions/4/Qt"$g" - done - echo "step 2" - for g in cockatrice oracle; do - install_name_tool -change $QTLIB/Qt"$f".framework/Versions/4/Qt"$f" @executable_path/../../../Frameworks/Qt"$f".framework/Versions/4/Qt"$f" "$g".app/Contents/MacOS/$g - done - echo "step 3" - for g in `find . -name '*.dylib'`; do - install_name_tool -change $QTLIB/Qt"$f".framework/Versions/4/Qt"$f" @executable_path/../../../Frameworks/Qt"$f".framework/Versions/4/Qt"$f" "$g" - done -done - -install_name_tool -id @executable_path/../../../libprotobuf.7.dylib Frameworks/libprotobuf.7.dylib -install_name_tool -change $PROTOBUF/lib/libprotobuf.7.dylib @executable_path/../../../Frameworks/libprotobuf.7.dylib cockatrice.app/Contents/MacOS/cockatrice - -cd .. - -VOL=cockatrice_mac_${DATE} -DMG="tmp-$VOL.dmg" - -SIZE=`du -sk $DIR | cut -f1` -SIZE=$((${SIZE}/1000+10)) -hdiutil create "$DMG" -megabytes ${SIZE} -ov -type UDIF -fs HFS+ -volname "$VOL" - -hdid "$DMG" -cp -R "${DIR}" "/Volumes/$VOL" -hdiutil detach "/Volumes/$VOL" -#osascript -e "tell application "Finder" to eject disk "$VOL"" && - -# convert to compressed image, delete temp image -rm -f "${VOL}.dmg" -hdiutil convert "$DMG" -format UDZO -o "${VOL}.dmg" -rm -f "$DMG" diff --git a/servatrice/CMakeLists.txt b/servatrice/CMakeLists.txt index ff403e23..b1fc00c8 100644 --- a/servatrice/CMakeLists.txt +++ b/servatrice/CMakeLists.txt @@ -94,8 +94,9 @@ elseif(WIN32) endif() if(APPLE) - set(plugin_dest_dir ./servatrice.app/Contents/Plugins) - set(qtconf_dest_dir ./servatrice.app/Contents/Resources) + # these needs to be relative to CMAKE_INSTALL_PREFIX + set(plugin_dest_dir servatrice.app/Contents/Plugins) + set(qtconf_dest_dir servatrice.app/Contents/Resources) # note: no codecs in qt5 # note: phonon_backend => mediaservice @@ -110,13 +111,15 @@ if(APPLE) endif() install(CODE " - file(WRITE \"${qtconf_dest_dir}/qt.conf\" \"[Paths] -Plugins = Plugins\") + file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] +Plugins = Plugins +Translations = Resources/translations\") " COMPONENT Runtime) install(CODE " file(GLOB_RECURSE QTPLUGINS - \"${plugin_dest_dir}/*.dylib\") + \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\") + set(BU_CHMOD_BUNDLE_ITEMS ON) include(BundleUtilities) fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") " COMPONENT Runtime) diff --git a/sounds/CMakeLists.txt b/sounds/CMakeLists.txt index e38c9090..cd9f6c33 100644 --- a/sounds/CMakeLists.txt +++ b/sounds/CMakeLists.txt @@ -6,7 +6,7 @@ FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.raw") if(UNIX) if(APPLE) - INSTALL(FILES ${sounds} DESTINATION sounds/) + INSTALL(FILES ${sounds} DESTINATION cockatrice.app/Contents/Resources/sounds/) else() # Assume linux INSTALL(FILES ${sounds} DESTINATION share/cockatrice/sounds/) diff --git a/zonebg/CMakeLists.txt b/zonebg/CMakeLists.txt index 961c4e12..b250a44b 100644 --- a/zonebg/CMakeLists.txt +++ b/zonebg/CMakeLists.txt @@ -2,11 +2,11 @@ # # Installs default "zone background" files -FILE(GLOB zonebg "${CMAKE_CURRENT_SOURCE_DIR}/*.*") +FILE(GLOB zonebg "${CMAKE_CURRENT_SOURCE_DIR}/*.png" "${CMAKE_CURRENT_SOURCE_DIR}/*.jpg") if(UNIX) if(APPLE) - INSTALL(FILES ${zonebg} DESTINATION zonebg/) + INSTALL(FILES ${zonebg} DESTINATION cockatrice.app/Contents/Resources/zonebg/) else() # Assume linux INSTALL(FILES ${zonebg} DESTINATION share/cockatrice/zonebg/)