Skip to content

Commit

Permalink
Avoid plugin caching
Browse files Browse the repository at this point in the history
  • Loading branch information
AlienCowEatCake committed Jan 7, 2023
1 parent 1446807 commit 2b336f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(qfiletransport VERSION 0.1 LANGUAGES CXX)
project(qfiletransport VERSION 0.2 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -48,3 +48,4 @@ add_library(${CMAKE_PROJECT_NAME} SHARED qfiletransport.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt5::Core audcore)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "EXPORT=__declspec(dllexport)")
25 changes: 24 additions & 1 deletion qfiletransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QRegularExpression>
#include <QString>
#include <QUrl>

Expand Down Expand Up @@ -111,6 +112,28 @@ class QFileTransport : public TransportPlugin
installUriSchemeHook();
}

void cleanup() Q_DECL_OVERRIDE
{
/// @note Clear timestamp from plugin registry to avoid plugin caching
/// Cached plugins is lazy-loaded, but we need to install hook
StringBuf path =
filename_build({aud_get_path(AudPath::UserDir), "plugin-registry"});
QFile file((QString(path)));
if (!file.open(QFile::ReadWrite | QFile::Text))
return;

QString registryData = QString::fromUtf8(file.readAll());
const QRegularExpression re("(qfiletransport\\.dll[\r\n]stamp )[0-9]*",
QRegularExpression::MultilineOption);
const QRegularExpressionMatch match = re.match(registryData);
if (match.hasMatch())
registryData.replace(re, match.captured(1) + "0");
file.seek(0);
file.resize(0);
file.write(registryData.toUtf8());
file.close();
}

VFSImpl * fopen(const char * path, const char * mode,
String & error) Q_DECL_OVERRIDE
{
Expand Down Expand Up @@ -289,4 +312,4 @@ class QFileTransport : public TransportPlugin
};
};

__declspec(dllexport) QFileTransport aud_plugin_instance;
EXPORT QFileTransport aud_plugin_instance;

0 comments on commit 2b336f0

Please sign in to comment.