@@ -449,16 +449,6 @@ void JsonClientConnection::handleEffectCommand(const QJsonObject& message, const
449449
450450void 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
524529void 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 ();
0 commit comments