Skip to content

Commit b227f5a

Browse files
Paulchen PantherredPanther
authored andcommitted
Overwrite custom created effect config when effect name is exist (#335)
* Overwrite exist Effects * move find_schema and find_effect struct to include file
1 parent a724fd1 commit b227f5a

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

libsrc/jsonserver/JsonClientConnection.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,6 @@ void JsonClientConnection::handleEffectCommand(const QJsonObject& message, const
449449

450450
void JsonClientConnection::handleCreateEffectCommand(const QJsonObject& message, const QString &command, const int tan)
451451
{
452-
struct find_schema: std::unary_function<EffectSchema, bool>
453-
{
454-
QString pyFile;
455-
find_schema(QString pyFile):pyFile(pyFile) { }
456-
bool operator()(EffectSchema const& schema) const
457-
{
458-
return schema.pyFile == pyFile;
459-
}
460-
};
461-
462452
if(message.size() > 0)
463453
{
464454
if (!message["args"].toObject().isEmpty())
@@ -497,11 +487,26 @@ void JsonClientConnection::handleCreateEffectCommand(const QJsonObject& message,
497487
effectJson["script"] = message["script"].toString();
498488
effectJson["args"] = message["args"].toObject();
499489

500-
QFileInfo newFileName(effectArray[0].toString() + QDir::separator() + message["name"].toString().replace(QString(" "), QString("")) + QString(".json"));
490+
std::list<EffectDefinition> availableEffects = _hyperion->getEffects();
491+
std::list<EffectDefinition>::iterator iter = std::find_if(availableEffects.begin(), availableEffects.end(), find_effect(message["name"].toString()));
501492

502-
while(newFileName.exists())
493+
QFileInfo newFileName;
494+
if (iter != availableEffects.end())
495+
{
496+
newFileName.setFile(iter->file);
497+
if (newFileName.absoluteFilePath().mid(0, 1) == ":")
498+
{
499+
sendErrorReply("The effect name '" + message["name"].toString() + "' is assigned to an internal effect. Please rename your effekt.", command, tan);
500+
return;
501+
}
502+
} else
503503
{
504-
newFileName.setFile(effectArray[0].toString() + QDir::separator() + newFileName.baseName() + QString::number(qrand() % ((10) - 0) + 0) + QString(".json"));
504+
newFileName.setFile(effectArray[0].toString() + QDir::separator() + message["name"].toString().replace(QString(" "), QString("")) + QString(".json"));
505+
506+
while(newFileName.exists())
507+
{
508+
newFileName.setFile(effectArray[0].toString() + QDir::separator() + newFileName.baseName() + QString::number(qrand() % ((10) - 0) + 0) + QString(".json"));
509+
}
505510
}
506511

507512
QJsonFactory::writeJson(newFileName.absoluteFilePath(), effectJson);
@@ -523,16 +528,6 @@ void JsonClientConnection::handleCreateEffectCommand(const QJsonObject& message,
523528

524529
void JsonClientConnection::handleDeleteEffectCommand(const QJsonObject& message, const QString& command, const int tan)
525530
{
526-
struct find_effect: std::unary_function<EffectDefinition, bool>
527-
{
528-
QString effectName;
529-
find_effect(QString effectName) :effectName(effectName) { }
530-
bool operator()(EffectDefinition const& effectDefinition) const
531-
{
532-
return effectDefinition.name == effectName;
533-
}
534-
};
535-
536531
if(message.size() > 0)
537532
{
538533
QString effectName = message["name"].toString();

libsrc/jsonserver/JsonClientConnection.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,25 @@ namespace OPCODE {
7272
}
7373
}
7474

75+
struct find_schema: std::unary_function<EffectSchema, bool>
76+
{
77+
QString pyFile;
78+
find_schema(QString pyFile):pyFile(pyFile) { }
79+
bool operator()(EffectSchema const& schema) const
80+
{
81+
return schema.pyFile == pyFile;
82+
}
83+
};
7584

85+
struct find_effect: std::unary_function<EffectDefinition, bool>
86+
{
87+
QString effectName;
88+
find_effect(QString effectName) :effectName(effectName) { }
89+
bool operator()(EffectDefinition const& effectDefinition) const
90+
{
91+
return effectDefinition.name == effectName;
92+
}
93+
};
7694

7795
///
7896
/// The Connection object created by \a JsonServer when a new connection is establshed

0 commit comments

Comments
 (0)