From 9cdde97dc303350fa349d6a169ce761c55824832 Mon Sep 17 00:00:00 2001 From: wangshaohui Date: Wed, 5 Jan 2022 17:03:43 +0800 Subject: [PATCH] obs-vst: Check hash before applying "chunk_data" --- VSTPlugin.cpp | 5 +++++ headers/VSTPlugin.h | 1 + obs-vst.cpp | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/VSTPlugin.cpp b/VSTPlugin.cpp index 3a699d3f..9f79c5df 100644 --- a/VSTPlugin.cpp +++ b/VSTPlugin.cpp @@ -258,6 +258,11 @@ intptr_t VSTPlugin::hostCallback(AEffect *effect, int32_t opcode, int32_t index, return result; } +std::string VSTPlugin::getEffectPath() +{ + return pluginPath; +} + std::string VSTPlugin::getChunk() { if (!effect) { diff --git a/headers/VSTPlugin.h b/headers/VSTPlugin.h index d31475fc..dfed7317 100644 --- a/headers/VSTPlugin.h +++ b/headers/VSTPlugin.h @@ -95,6 +95,7 @@ class VSTPlugin : public QObject { ~VSTPlugin(); void loadEffectFromPath(std::string path); void unloadEffect(); + std::string getEffectPath(); std::string getChunk(); void setChunk(std::string data); void setProgram(const int programNumber); diff --git a/obs-vst.cpp b/obs-vst.cpp index 129ea7de..45e48b82 100644 --- a/obs-vst.cpp +++ b/obs-vst.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . *****************************************************************************/ #include "headers/VSTPlugin.h" +#include #define OPEN_VST_SETTINGS "open_vst_settings" #define CLOSE_VST_SETTINGS "close_vst_settings" @@ -64,6 +65,18 @@ static bool close_editor_button_clicked(obs_properties_t *props, obs_property_t return true; } +std::string getFileMD5(const char *file) +{ + QFile f(file); + if (f.open(QFile::ReadOnly)) { + QCryptographicHash hash(QCryptographicHash::Md5); + if (hash.addData(&f)) + return std::string(hash.result().toHex()); + } + + return std::string(); +} + static const char *vst_name(void *unused) { UNUSED_PARAMETER(unused); @@ -90,8 +103,10 @@ static void vst_update(void *data, obs_data_t *settings) } vstPlugin->loadEffectFromPath(std::string(path)); + std::string hash = getFileMD5(path); + const char *chunkHash = obs_data_get_string(settings, "chunk_hash"); const char *chunkData = obs_data_get_string(settings, "chunk_data"); - if (chunkData && strlen(chunkData) > 0) { + if (chunkData && strlen(chunkData) > 0 && chunkHash && strlen(chunkHash) > 0 && 0 == hash.compare(chunkHash)) { vstPlugin->setChunk(std::string(chunkData)); } } @@ -107,8 +122,8 @@ static void *vst_create(obs_data_t *settings, obs_source_t *filter) static void vst_save(void *data, obs_data_t *settings) { VSTPlugin *vstPlugin = (VSTPlugin *)data; - obs_data_set_string(settings, "chunk_data", vstPlugin->getChunk().c_str()); + obs_data_set_string(settings, "chunk_hash", getFileMD5(vstPlugin->getEffectPath().c_str()).c_str()); } static struct obs_audio_data *vst_filter_audio(void *data, struct obs_audio_data *audio)