From f348bc8796dbf2c726ba75963638d8a3a0b9f53a Mon Sep 17 00:00:00 2001 From: BlueAndi Date: Thu, 15 Aug 2024 15:31:08 +0200 Subject: [PATCH] Bugfix: Uploaded icons were not handled correct in IconTextLampPlugin and IconTextPlugin. --- .../src/IconTextLampPlugin.cpp | 20 ++++++++++++++++++- lib/IconTextPlugin/src/IconTextPlugin.cpp | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp b/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp index d7fb3d7f..666df5dd 100644 --- a/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp +++ b/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp @@ -248,7 +248,25 @@ bool IconTextLampPlugin::setTopic(const String& topic, const JsonObjectConst& va { String fullPath = jsonFullPath.as(); - isSuccessful = loadIcon(fullPath); + /* Clear always the icon indpended whether its requested by user. + * In case of an uploaded new icon, clearing will close the image + * file and makes it possible to overwrite the file. + */ + clearIcon(); + + if (false == fullPath.isEmpty()) + { + /* Rename uploaded icon by removing the file extension for temporary files. */ + String iconFullPathWithoutTmp = fullPath.substring(0, fullPath.length() - strlen(FILE_EXT_TMP)); + + FILESYSTEM.rename(fullPath, iconFullPathWithoutTmp); + + isSuccessful = loadIcon(iconFullPathWithoutTmp); + } + else + { + isSuccessful = true; + } } } else diff --git a/lib/IconTextPlugin/src/IconTextPlugin.cpp b/lib/IconTextPlugin/src/IconTextPlugin.cpp index 2ae86e0f..65db2502 100644 --- a/lib/IconTextPlugin/src/IconTextPlugin.cpp +++ b/lib/IconTextPlugin/src/IconTextPlugin.cpp @@ -175,7 +175,25 @@ bool IconTextPlugin::setTopic(const String& topic, const JsonObjectConst& value) { String fullPath = jsonFullPath.as(); - isSuccessful = loadIcon(fullPath); + /* Clear always the icon indpended whether its requested by user. + * In case of an uploaded new icon, clearing will close the image + * file and makes it possible to overwrite the file. + */ + clearIcon(); + + if (false == fullPath.isEmpty()) + { + /* Rename uploaded icon by removing the file extension for temporary files. */ + String iconFullPathWithoutTmp = fullPath.substring(0, fullPath.length() - strlen(FILE_EXT_TMP)); + + FILESYSTEM.rename(fullPath, iconFullPathWithoutTmp); + + isSuccessful = loadIcon(iconFullPathWithoutTmp); + } + else + { + isSuccessful = true; + } } } else