Skip to content

Commit

Permalink
MeasurePlugin: Add plugin loading/unloading debug messages (only in d…
Browse files Browse the repository at this point in the history
…ebug mode)
  • Loading branch information
brianferguson committed Mar 22, 2022
1 parent ba2a2cf commit 46afc80
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Library/MeasurePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Export.h"
#include "System.h"

std::unordered_map<std::wstring, UINT> MeasurePlugin::s_PluginReferences;

MeasurePlugin::MeasurePlugin(Skin* skin, const WCHAR* name) : Measure(skin, name),
m_Plugin(),
m_ReloadFunc(),
Expand Down Expand Up @@ -40,6 +42,27 @@ MeasurePlugin::~MeasurePlugin()
}
}

WCHAR pluginPath[MAX_PATH];
if (GetModuleFileName(m_Plugin, pluginPath, MAX_PATH) > 0UL)
{
std::wstring tmpStr = pluginPath;
StringUtil::ToLowerCase(tmpStr);

auto iter = s_PluginReferences.find(tmpStr);
if (iter != s_PluginReferences.end())
{
--iter->second;
if (iter->second == 0)
{
if (GetRainmeter().GetDebug())
{
LogDebugF(L"Plugin unloaded: %s", pluginPath);
}
s_PluginReferences.erase(tmpStr);
}
}
}

FreeLibrary(m_Plugin);
m_Plugin = nullptr;
}
Expand Down Expand Up @@ -129,6 +152,53 @@ void MeasurePlugin::ReadOptions(ConfigParser& parser, const WCHAR* section)
}
}

// Log plugin references
{
WCHAR pluginPath[MAX_PATH];
if (GetModuleFileName(m_Plugin, pluginPath, MAX_PATH) > 0UL)
{
std::wstring tmpStr = pluginPath;
StringUtil::ToLowerCase(tmpStr);

auto iter = s_PluginReferences.find(tmpStr);
if (iter == s_PluginReferences.end())
{
s_PluginReferences.insert(std::make_pair<std::wstring&, UINT>(tmpStr, 1U));
if (GetRainmeter().GetDebug())
{
LogDebugF(L"Plugin loaded: %s", pluginPath);
}
}
else
{
++iter->second;
}
}

/*size_t pluginNameSize = pluginFile.size();
if (pluginNameSize > 3 && pluginFile.substr(pluginFile.size() - 4) != L".dll")
{
pluginFile += L".dll";
}
WCHAR plugin[MAX_PATH];
wcsncpy_s(plugin, MAX_PATH, pluginFile.c_str(), pluginFile.size());
auto iter = s_PluginReferences.find(plugin);
if (iter == s_PluginReferences.end())
{
s_PluginReferences.insert(std::make_pair<std::wstring, UINT>(plugin, 1U));
if (GetRainmeter().GetDebug())
{
LogDebugF(this, L"Plugin loaded: &s", plugin);
}
}
else
{
++iter->second;
}*/
}

FARPROC initializeFunc = GetProcAddress(m_Plugin, "Initialize");
m_ReloadFunc = GetProcAddress(m_Plugin, "Reload");
m_UpdateFunc = GetProcAddress(m_Plugin, "Update");
Expand Down
2 changes: 2 additions & 0 deletions Library/MeasurePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class MeasurePlugin : public Measure
void* m_UpdateFunc;
void* m_GetStringFunc;
void* m_ExecuteBangFunc;

static std::unordered_map<std::wstring, UINT> s_PluginReferences;
};

#endif

0 comments on commit 46afc80

Please sign in to comment.