more error handling for styles
This commit is contained in:
@@ -22,11 +22,11 @@
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
|
||||
#include "game_defs.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
CardDeckStyleReader::CardDeckStyleReader(ConfigFile *c, gameTableImpl *w) : myConfig(c), myW(w), fallBack(0)
|
||||
CardDeckStyleReader::CardDeckStyleReader(ConfigFile *c, QWidget *w) : myConfig(c), myW(w), fallBack(0), loadedSuccessfull(0)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -74,52 +74,75 @@ void CardDeckStyleReader::readStyleFile(QString file) {
|
||||
else if (itemsList->ValueStr() == "Preview") { Preview = currentDir+QString::fromUtf8(tempString1.c_str()); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else { qDebug() << "could not load card deck file: " << tinyFileName.c_str(); }
|
||||
//check if style items are left and show warning
|
||||
leftItems.clear();
|
||||
|
||||
//check if style items are left and show warning
|
||||
leftItems.clear();
|
||||
if(StyleDescription == "") { leftItems << "StyleDescription"; }
|
||||
if(StyleMaintainerName == "") { leftItems << "StyleMaintainerName"; }
|
||||
if(StyleMaintainerEMail == "") { leftItems << "StyleMaintainerEMail"; }
|
||||
if(StyleCreateDate == "") { leftItems << "StyleCreateDate"; }
|
||||
if(PokerTHStyleFileVersion == "") { leftItems << "PokerTHStyleFileVersion"; }
|
||||
|
||||
if(StyleDescription == "") { leftItems << "StyleDescription"; }
|
||||
if(StyleMaintainerName == "") { leftItems << "StyleMaintainerName"; }
|
||||
if(StyleMaintainerEMail == "") { leftItems << "StyleMaintainerEMail"; }
|
||||
if(StyleCreateDate == "") { leftItems << "StyleCreateDate"; }
|
||||
if(PokerTHStyleFileVersion == "") { leftItems << "PokerTHStyleFileVersion"; }
|
||||
//check if all files are there
|
||||
cardsLeft.clear();
|
||||
int i;
|
||||
for(i=0; i<52; i++) {
|
||||
QString cardString(QString::number(i)+".png");
|
||||
if(!QDir(currentDir).exists(cardString)) {
|
||||
cardsLeft << cardString;
|
||||
}
|
||||
}
|
||||
if(!QDir(currentDir).exists("flipside.png")) {
|
||||
cardsLeft << "flipside.png";
|
||||
}
|
||||
|
||||
// set loadedSuccessfull TRUE if everything works
|
||||
if(leftItems.isEmpty() && cardsLeft.isEmpty() && PokerTHStyleFileVersion != "" && PokerTHStyleFileVersion.toInt() == POKERTH_CD_STYLE_FILE_VERSION)
|
||||
loadedSuccessfull = 1;
|
||||
else
|
||||
loadedSuccessfull = 0;
|
||||
|
||||
if(!leftItems.isEmpty() && myW != 0) showLeftItemsErrorMessage(StyleDescription, leftItems, StyleMaintainerEMail);
|
||||
else {
|
||||
if(!cardsLeft.isEmpty() && myW != 0) showCardsLeftErrorMessage(StyleDescription, cardsLeft, StyleMaintainerEMail);
|
||||
//check for style file version
|
||||
if(PokerTHStyleFileVersion != "" && PokerTHStyleFileVersion.toInt() != POKERTH_CD_STYLE_FILE_VERSION) {
|
||||
QString EMail;
|
||||
if(StyleMaintainerEMail != "NULL") EMail = StyleMaintainerEMail;
|
||||
QMessageBox::warning(myW, tr("Card Deck Style Error"),
|
||||
tr("Selected card deck style \"%1\" seems to be outdated. \n The current PokerTH card deck style version is \"%2\", but this style has version \"%3\" set. \n\nPlease contact the game table style builder %4.").arg(StyleDescription).arg(POKERTH_CD_STYLE_FILE_VERSION).arg(PokerTHStyleFileVersion).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
loadedSuccessfull = 0;
|
||||
QMessageBox::warning(myW, tr("Card Deck Style Error"),
|
||||
tr("Can not load card deck style file: %1 \n\nPlease check the style file or choose another style!").arg(tinyFileName.c_str()),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
|
||||
//check if all files are there
|
||||
cardsLeft.clear();
|
||||
int i;
|
||||
for(i=0; i<52; i++) {
|
||||
QString cardString(QString::number(i)+".png");
|
||||
if(!QDir(currentDir).exists(cardString)) {
|
||||
cardsLeft << cardString;
|
||||
}
|
||||
}
|
||||
if(!QDir(currentDir).exists("flipside.png")) {
|
||||
cardsLeft << "flipside.png";
|
||||
}
|
||||
|
||||
if(!leftItems.isEmpty() && myW != 0) showLeftItemsErrorMessage(StyleDescription, leftItems, StyleMaintainerEMail);
|
||||
else {
|
||||
if(!cardsLeft.isEmpty() && myW != 0) showCardsLeftErrorMessage(StyleDescription, cardsLeft, StyleMaintainerEMail);
|
||||
}
|
||||
}
|
||||
|
||||
void CardDeckStyleReader::showLeftItemsErrorMessage(QString style, QStringList failedItems, QString email)
|
||||
{
|
||||
QString items = failedItems.join(", ");
|
||||
QString EMail;
|
||||
if(email != "NULL") EMail = email;
|
||||
|
||||
QMessageBox::warning(myW, tr("Card Deck Style Error"),
|
||||
tr("Selected card deck style \"%1\" seems to be incomplete or defective. \n\nThe value(s) of \"%2\" is/are missing. \n\nPlease contact the game table style builder %3.").arg(style).arg(items).arg(email),
|
||||
tr("Selected card deck style \"%1\" seems to be incomplete or defective. \n\nThe value(s) of \"%2\" is/are missing. \n\nPlease contact the game table style builder %3.").arg(style).arg(items).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
|
||||
void CardDeckStyleReader::showCardsLeftErrorMessage(QString style, QStringList failedItems, QString email)
|
||||
{
|
||||
QString items = failedItems.join(", ");
|
||||
QString EMail;
|
||||
if(email != "NULL") EMail = email;
|
||||
|
||||
QMessageBox::warning(myW, tr("Card Deck Style Error"),
|
||||
tr("Selected card deck style \"%1\" seems to be incomplete or defective. \nThe card picture(s) \"%2\" is/are not available. \n\nPlease contact the card deck style builder %3.").arg(style).arg(items).arg(email),
|
||||
tr("Selected card deck style \"%1\" seems to be incomplete or defective. \nThe card picture(s) \"%2\" is/are not available. \n\nPlease contact the card deck style builder %3.").arg(style).arg(items).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#define CARDDECKSTYLEREADER_H
|
||||
|
||||
#include "tinyxml.h"
|
||||
#include "gametableimpl.h"
|
||||
#include "configfile.h"
|
||||
#include <string>
|
||||
#include <QtCore>
|
||||
@@ -30,7 +29,7 @@
|
||||
class CardDeckStyleReader : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CardDeckStyleReader(ConfigFile *c, gameTableImpl *w =0 );
|
||||
CardDeckStyleReader(ConfigFile *c, QWidget *w );
|
||||
~CardDeckStyleReader();
|
||||
|
||||
void readStyleFile(QString);
|
||||
@@ -46,6 +45,8 @@ public:
|
||||
QString getPreview() const { return Preview; }
|
||||
|
||||
bool getFallBack() const { return fallBack; }
|
||||
bool getLoadedSuccessfull() const { return loadedSuccessfull; }
|
||||
|
||||
void showLeftItemsErrorMessage(QString, QStringList, QString);
|
||||
void showCardsLeftErrorMessage(QString, QStringList, QString);
|
||||
|
||||
@@ -65,9 +66,10 @@ private:
|
||||
QStringList leftItems;
|
||||
|
||||
ConfigFile *myConfig;
|
||||
gameTableImpl *myW;
|
||||
QWidget *myW;
|
||||
|
||||
bool fallBack;
|
||||
bool loadedSuccessfull;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
GameTableStyleReader::GameTableStyleReader(ConfigFile *c, gameTableImpl *w) : myConfig(c), myW(w), fallBack(0)
|
||||
GameTableStyleReader::GameTableStyleReader(ConfigFile *c, QWidget *w) : myConfig(c), myW(w), fallBack(0), loadedSuccessfull(0)
|
||||
{
|
||||
|
||||
//set fonts and font sizes
|
||||
@@ -454,20 +454,30 @@ void GameTableStyleReader::readStyleFile(QString file) {
|
||||
// SIZE
|
||||
if(ChatLogTextSize == "") { leftItems << "ChatLogTextSize"; }
|
||||
|
||||
//set loadedSuccessfull TRUE if everything works
|
||||
if(leftItems.isEmpty() && itemPicsLeft.isEmpty() && PokerTHStyleFileVersion != "" && PokerTHStyleFileVersion.toInt() == POKERTH_GT_STYLE_FILE_VERSION)
|
||||
loadedSuccessfull = 1;
|
||||
else
|
||||
loadedSuccessfull = 0;
|
||||
|
||||
//if one or more items are left show detailed error message
|
||||
if(!leftItems.isEmpty() && myW != 0) showLeftItemsErrorMessage(StyleDescription, leftItems, StyleMaintainerEMail);
|
||||
else {
|
||||
//if one or more pictures where not found show detailed error message
|
||||
if(!itemPicsLeft.isEmpty() && myW != 0) showItemPicsLeftErrorMessage(StyleDescription, itemPicsLeft, StyleMaintainerEMail);
|
||||
//check for style file version
|
||||
if(!PokerTHStyleFileVersion.isEmpty() && PokerTHStyleFileVersion.toInt() != PokerTH_STYLE_FILE_VERSION) {
|
||||
if(PokerTHStyleFileVersion != "" && PokerTHStyleFileVersion.toInt() != POKERTH_GT_STYLE_FILE_VERSION) {
|
||||
QString EMail;
|
||||
if(StyleMaintainerEMail != "NULL") EMail = StyleMaintainerEMail;
|
||||
QMessageBox::warning(myW, tr("Game Table Style Error"),
|
||||
tr("Selected game table style \"%1\" seems to be outdated. \n The current PokerTH game table style version is \"%2\", but this style has version \"%3\" set. \n\nPlease contact the game table style builder %4.").arg(StyleDescription).arg(PokerTH_STYLE_FILE_VERSION).arg(PokerTHStyleFileVersion).arg(StyleMaintainerEMail),
|
||||
tr("Selected game table style \"%1\" seems to be outdated. \n The current PokerTH game table style version is \"%2\", but this style has version \"%3\" set. \n\nPlease contact the game table style builder %4.").arg(StyleDescription).arg(POKERTH_GT_STYLE_FILE_VERSION).arg(PokerTHStyleFileVersion).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { QMessageBox::warning(myW, tr("Game Table Style Error"),
|
||||
else {
|
||||
loadedSuccessfull = 0;
|
||||
QMessageBox::warning(myW, tr("Game Table Style Error"),
|
||||
tr("Can not load game table style file: %1 \n\nPlease check the style file or choose another style!").arg(tinyFileName.c_str()),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
@@ -476,18 +486,22 @@ void GameTableStyleReader::readStyleFile(QString file) {
|
||||
void GameTableStyleReader::showLeftItemsErrorMessage(QString style, QStringList failedItems, QString email)
|
||||
{
|
||||
QString items = failedItems.join(", ");
|
||||
QString EMail;
|
||||
if(email != "NULL") EMail = email;
|
||||
|
||||
QMessageBox::warning(myW, tr("Game Table Style Error"),
|
||||
tr("Selected game table style \"%1\" seems to be incomplete or defective. \n\nThe value(s) of \"%2\" is/are missing. \n\nPlease contact the game table style builder %3.").arg(style).arg(items).arg(email),
|
||||
tr("Selected game table style \"%1\" seems to be incomplete or defective. \n\nThe value(s) of \"%2\" is/are missing. \n\nPlease contact the game table style builder %3.").arg(style).arg(items).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
|
||||
void GameTableStyleReader::showItemPicsLeftErrorMessage(QString style, QStringList picsLeft, QString email)
|
||||
{
|
||||
QString pics = picsLeft.join("\n");
|
||||
QString pics = picsLeft.join("\n");
|
||||
QString EMail;
|
||||
if(email != "NULL") EMail = email;
|
||||
|
||||
QMessageBox::warning(myW, tr("Game Table Style Error"),
|
||||
tr("One or more pictures from current game table style \"%1\" where not found: \n\n\"%2\" \n\nPlease contact the game table style builder %3.").arg(style).arg(pics).arg(email),
|
||||
tr("One or more pictures from current game table style \"%1\" where not found: \n\n\"%2\" \n\nPlease contact the game table style builder %3.").arg(style).arg(pics).arg(EMail),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#define GAMETABLESTYLEREADER_H
|
||||
|
||||
#include "tinyxml.h"
|
||||
#include "gametableimpl.h"
|
||||
#include "configfile.h"
|
||||
#include "gametableimpl.h"
|
||||
#include <string>
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
@@ -32,7 +32,7 @@ class gameTableImpl;
|
||||
class GameTableStyleReader : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GameTableStyleReader(ConfigFile *c, gameTableImpl *w =0 );
|
||||
GameTableStyleReader(ConfigFile *c, QWidget *w);
|
||||
~GameTableStyleReader();
|
||||
|
||||
void readStyleFile(QString);
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
QString getIfFixedWindowSize() const { return IfFixedWindowSize; }
|
||||
|
||||
bool getFallBack() const { return fallBack; }
|
||||
bool getLoadedSuccessfull() const { return loadedSuccessfull; }
|
||||
|
||||
//set pictures
|
||||
void setTableBackground(gameTableImpl*);
|
||||
@@ -277,9 +278,10 @@ private:
|
||||
QStringList itemPicsLeft;
|
||||
|
||||
ConfigFile *myConfig;
|
||||
gameTableImpl *myW;
|
||||
QWidget *myW;
|
||||
|
||||
bool fallBack;
|
||||
bool fallBack;
|
||||
bool loadedSuccessfull;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user