From: <man...@us...> - 2015-05-26 08:38:21
|
Revision: 5189 http://sourceforge.net/p/modplug/code/5189 Author: manxorist Date: 2015-05-26 08:38:15 +0000 (Tue, 26 May 2015) Log Message: ----------- [Ref] Consolidate PluginBridge availability check und knowledge about its filename to a single place into a Component class. Modified Paths: -------------- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp trunk/OpenMPT/pluginBridge/BridgeWrapper.h Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2015-05-26 08:37:32 UTC (rev 5188) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2015-05-26 08:38:15 UTC (rev 5189) @@ -62,9 +62,6 @@ m_pModDoc = pModDoc; m_nPlugSlot = nPlugSlot; - hasBridge32 = (theApp.GetAppDirPath() + MPT_PATHSTRING("PluginBridge32.exe")).IsFile(); - hasBridge64 = (theApp.GetAppDirPath() + MPT_PATHSTRING("PluginBridge64.exe")).IsFile(); - if(m_pModDoc) { if(0 <= m_nPlugSlot && m_nPlugSlot < MAX_MIXPLUGINS) @@ -452,7 +449,11 @@ ::SetDlgItemTextW(m_hWnd, IDC_TEXT_CURRENT_VSTPLUG, pPlug->dllPath.ToWide().c_str()); if(pPlug->pluginId1 == kEffectMagic) { - bool isBridgeAvailable = (hasBridge32 && pPlug->GetDllBits() == 32) || (hasBridge64 && pPlug->GetDllBits() == 64); + bool isBridgeAvailable = + ((pPlug->GetDllBits() == 32) && IsComponentAvailable(pluginBridge32)) + || + ((pPlug->GetDllBits() == 64) && IsComponentAvailable(pluginBridge64)) + ; if(TrackerSettings::Instance().bridgeAllPlugins || !isBridgeAvailable) { m_chkBridge.EnableWindow(FALSE); Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2015-05-26 08:37:32 UTC (rev 5188) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2015-05-26 08:38:15 UTC (rev 5189) @@ -12,12 +12,15 @@ #pragma once #include "CTreeCtrl.h" +#include "../common/ComponentManager.h" OPENMPT_NAMESPACE_BEGIN class CModDoc; struct SNDMIXPLUGIN; struct VSTPluginLib; +class ComponentPluginBridge32; +class ComponentPluginBridge64; //==================================== class CSelectPluginDlg: public CDialog @@ -30,7 +33,8 @@ CTreeCtrlW m_treePlugins; CButton m_chkBridge, m_chkShare; std::wstring m_nameFilter; - bool hasBridge32, hasBridge64; + ComponentHandle<ComponentPluginBridge32> pluginBridge32; + ComponentHandle<ComponentPluginBridge64> pluginBridge64; HTREEITEM AddTreeItem(const WCHAR *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); Modified: trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2015-05-26 08:37:32 UTC (rev 5188) +++ trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2015-05-26 08:38:15 UTC (rev 5189) @@ -24,6 +24,56 @@ OPENMPT_NAMESPACE_BEGIN +ComponentPluginBridge::ComponentPluginBridge(int bitness) + : ComponentBase(ComponentTypeBundled) + , bitness(bitness) + , availability(AvailabilityUnknown) +{ + return; +} + + +bool ComponentPluginBridge::DoInitialize() +{ + if(bitness != 32 && bitness != 64) + { + return false; + } + exeName = theApp.GetAppDirPath(); + if(bitness == 32) + { + exeName = exeName + MPT_PATHSTRING("PluginBridge32.exe"); + } + if(bitness == 64) + { + exeName = exeName + MPT_PATHSTRING("PluginBridge64.exe"); + } + // First, check for validity of the bridge executable. + if(!exeName.IsFile()) + { + availability = AvailabilityMissing; + return false; + } + WCHAR exePath[MAX_PATH]; + GetModuleFileNameW(0, exePath, CountOf(exePath)); + mpt::String::SetNullTerminator(exePath); + uint64 mptVersion = BridgeWrapper::GetFileVersion(exePath); + uint64 bridgeVersion = BridgeWrapper::GetFileVersion(exeName.AsNative().c_str()); + if(bridgeVersion != mptVersion) + { + availability = AvailabilityWrongVersion; + return false; + } + availability = AvailabilityOK; + return true; +} + + +MPT_REGISTERED_COMPONENT(ComponentPluginBridge32) + +MPT_REGISTERED_COMPONENT(ComponentPluginBridge64) + + // Check whether we need to load a 32-bit or 64-bit wrapper. BridgeWrapper::BinaryType BridgeWrapper::GetPluginBinaryType(const mpt::PathString &pluginPath) { @@ -144,28 +194,27 @@ return false; } - const mpt::PathString exeName = theApp.GetAppDirPath() + (binType == bin64Bit ? MPT_PATHSTRING("PluginBridge64.exe") : MPT_PATHSTRING("PluginBridge32.exe")); - - // First, check for validity of the bridge executable. - static uint64 mptVersion = 0; - if(!mptVersion) + const bool available = (binType == bin32Bit) ? IsComponentAvailable(pluginBridge32) : IsComponentAvailable(pluginBridge64); + if(!available) { - WCHAR exePath[_MAX_PATH]; - GetModuleFileNameW(0, exePath, CountOf(exePath)); - mpt::String::SetNullTerminator(exePath); - mptVersion = GetFileVersion(exePath); + ComponentPluginBridge::Availability availability = (binType == bin32Bit) ? pluginBridge32->GetAvailability() : pluginBridge64->GetAvailability(); + switch(availability) + { + case ComponentPluginBridge::AvailabilityMissing: + // Silently fail if bridge is missing. + throw BridgeNotFoundException(); + break; + case ComponentPluginBridge::AvailabilityWrongVersion: + throw BridgeException("The plugin bridge version does not match your OpenMPT version."); + break; + default: + throw BridgeNotFoundException(); + break; + } } - uint64 bridgeVersion = GetFileVersion(exeName.AsNative().c_str()); - if(bridgeVersion == 0) - { - // Silently fail if bridge is missing. - throw BridgeNotFoundException(); - } else if(bridgeVersion != mptVersion) - { - throw BridgeException("The plugin bridge version does not match your OpenMPT version."); - return nullptr; - } + const mpt::PathString exeName = (binType == bin32Bit) ? pluginBridge32->GetFileName() : pluginBridge64->GetFileName(); + otherPtrSize = binType; // Command-line must be a modifiable string... Modified: trunk/OpenMPT/pluginBridge/BridgeWrapper.h =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeWrapper.h 2015-05-26 08:37:32 UTC (rev 5188) +++ trunk/OpenMPT/pluginBridge/BridgeWrapper.h 2015-05-26 08:38:15 UTC (rev 5189) @@ -11,11 +11,54 @@ #pragma once #include "BridgeCommon.h" +#include "../common/ComponentManager.h" OPENMPT_NAMESPACE_BEGIN struct VSTPluginLib; +class ComponentPluginBridge + : public ComponentBase +{ +public: + enum Availability + { + AvailabilityUnknown = 0, + AvailabilityOK = 1, + AvailabilityMissing = -1, + AvailabilityWrongVersion = -2, + }; +private: + const int bitness; + mpt::PathString exeName; + Availability availability; +protected: + ComponentPluginBridge(int bitness); +protected: + virtual bool DoInitialize(); +public: + Availability GetAvailability() const { return availability; } + mpt::PathString GetFileName() const { return exeName; } +}; + +class ComponentPluginBridge32 + : public ComponentPluginBridge +{ + MPT_DECLARE_COMPONENT_MEMBERS +public: + ComponentPluginBridge32() : ComponentPluginBridge(32) { } + std::string GetSettingsKey() const { return "PluginBridge32"; } +}; + +class ComponentPluginBridge64 + : public ComponentPluginBridge +{ + MPT_DECLARE_COMPONENT_MEMBERS +public: + ComponentPluginBridge64() : ComponentPluginBridge(64) { } + std::string GetSettingsKey() const { return "PluginBridge64"; } +}; + class BridgeWrapper : protected BridgeCommon { protected: @@ -25,6 +68,9 @@ ERect editRect; VstSpeakerArrangement speakers[2]; + ComponentHandle<ComponentPluginBridge32> pluginBridge32; + ComponentHandle<ComponentPluginBridge64> pluginBridge64; + public: enum BinaryType { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |