From: <sag...@us...> - 2014-03-21 00:40:10
|
Revision: 3922 http://sourceforge.net/p/modplug/code/3922 Author: saga-games Date: 2014-03-21 00:40:00 +0000 (Fri, 21 Mar 2014) Log Message: ----------- [Imp] Plugin editor: For bridged plugin editors, ensure that the "create instrument" popup has proper focus [Imp] Plugin bridge: Prevent plugins from loading with the native plugin loader if something bad happened (or at least ask the user if he really wants to do that) Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp trunk/OpenMPT/pluginBridge/BridgeWrapper.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2014-03-20 20:00:47 UTC (rev 3921) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2014-03-21 00:40:00 UTC (rev 3922) @@ -451,9 +451,22 @@ { if(m_VstPlugin.CanRecieveMidiEvents()) { - SetForegroundWindow(); // Might have to steal focus from plugin bridge child window + CWnd *parent = this; + if(m_VstPlugin.isBridged) + { + // AllowSetForegroundWindow won't work reliably when calling it right when sending + // key messages from the bridged plugin, so stealing focus from plugin bridge child window + // can be kinda difficult. To prevent the following message box from not being focussed, + // we simply make it a child of the bridge window... + parent = GetWindow(GW_CHILD | GW_HWNDFIRST); // Plug container in custom GUIs + if(parent) parent = parent->GetWindow(GW_CHILD | GW_HWNDFIRST); // Bridge container + if(!parent) + { + parent = this; + } + } if(!m_VstPlugin.isInstrument() || m_VstPlugin.GetSoundFile().GetModSpecifications().instrumentsMax == 0 || - Reporting::Confirm(_T("You need to assign an instrument to this plugin before you can play notes from here.\nCreate a new instrument and assign this plugin to the instrument?"), false, false, this) == cnfNo) + Reporting::Confirm(_T("You need to assign an instrument to this plugin before you can play notes from here.\nCreate a new instrument and assign this plugin to the instrument?"), false, false, parent) == cnfNo) { return false; } else Modified: trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2014-03-20 20:00:47 UTC (rev 3921) +++ trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2014-03-21 00:40:00 UTC (rev 3922) @@ -79,7 +79,7 @@ // Create a plugin bridge object AEffect *BridgeWrapper::Create(const VSTPluginLib &plugin) { - BridgeWrapper *wrapper = new BridgeWrapper(); + BridgeWrapper *wrapper = new (std::nothrow) BridgeWrapper(); BridgeWrapper *sharedInstance = nullptr; // Should we share instances? @@ -98,12 +98,19 @@ } } - if(wrapper->Init(plugin.dllPath, sharedInstance) && wrapper->queueMem.Good()) + try { - return &wrapper->sharedMem->effect; + if(wrapper != nullptr && wrapper->Init(plugin.dllPath, sharedInstance) && wrapper->queueMem.Good()) + { + return &wrapper->sharedMem->effect; + } + delete wrapper; + return nullptr; + } catch(BridgeException &) + { + delete wrapper; + throw; } - delete wrapper; - return nullptr; } @@ -120,8 +127,7 @@ if(!queueMem.Create(mapName.c_str(), sizeof(SharedMemLayout)) || !CreateSignals(mapName.c_str())) { - Reporting::Error("Could not initialize plugin bridge memory."); - return false; + throw BridgeException("Could not initialize plugin bridge memory."); } sharedMem = reinterpret_cast<SharedMemLayout *>(queueMem.view); @@ -149,12 +155,11 @@ if(bridgeVersion == 0) { // Silently fail if bridge is missing. - //Reporting::Error("Could not open the plugin bridge executable."); - return false; + throw BridgeNotFoundException(); } else if(bridgeVersion != mptVersion) { - Reporting::Error("The plugin bridge version does not match your OpenMPT version."); - return false; + throw BridgeException("The plugin bridge version does not match your OpenMPT version."); + return nullptr; } otherPtrSize = binType; @@ -171,8 +176,7 @@ if(!CreateProcessW(exeName.AsNative().c_str(), cmdLine, NULL, NULL, FALSE, /*CREATE_NO_WINDOW */0, NULL, NULL, &info, &processInfo)) { - Reporting::Error("Failed to launch plugin bridge."); - return false; + throw BridgeException("Failed to launch plugin bridge."); } otherProcess = processInfo.hProcess; } else @@ -208,10 +212,10 @@ if(!SendToBridge(initMsg)) { - Reporting::Error("Could not initialize plugin bridge, it probably crashed."); + throw BridgeException("Could not initialize plugin bridge, it probably crashed."); } else if(initMsg.init.result != 1) { - Reporting::Error(mpt::ToLocale(initMsg.init.str).c_str()); + throw BridgeException(mpt::ToLocale(initMsg.init.str).c_str()); } else { if(sharedMem->effect.flags & effFlagsCanReplacing) sharedMem->effect.processReplacing = ProcessReplacing; Modified: trunk/OpenMPT/pluginBridge/BridgeWrapper.h =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeWrapper.h 2014-03-20 20:00:47 UTC (rev 3921) +++ trunk/OpenMPT/pluginBridge/BridgeWrapper.h 2014-03-21 00:40:00 UTC (rev 3922) @@ -31,6 +31,14 @@ bin64Bit = 64, }; + class BridgeException : public std::exception + { + public: + BridgeException(const char *str) : std::exception(str) { } + BridgeException() { } + }; + class BridgeNotFoundException : public BridgeException { }; + public: static BinaryType GetPluginBinaryType(const mpt::PathString &pluginPath); static bool IsPluginNative(const mpt::PathString &pluginPath) { return GetPluginBinaryType(pluginPath) == sizeof(void *) * 8; } Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2014-03-20 20:00:47 UTC (rev 3921) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2014-03-21 00:40:00 UTC (rev 3922) @@ -199,12 +199,38 @@ AEffect *effect = nullptr; library = nullptr; - if(forceBridge || plugin.useBridge || !BridgeWrapper::IsPluginNative(pluginPath)) + const bool isNative = BridgeWrapper::IsPluginNative(pluginPath); + if(forceBridge || plugin.useBridge || !isNative) { - effect = BridgeWrapper::Create(plugin); - if(effect != nullptr) + try { - return effect; + effect = BridgeWrapper::Create(plugin); + if(effect != nullptr) + { + return effect; + } + } catch(BridgeWrapper::BridgeNotFoundException &) + { + // Try normal loading + if(!isNative) + { + Reporting::Error("Could not locate the plugin bridge executable, which is required for running non-native plugins.", "OpenMPT Plugin Bridge"); + return false; + } + } catch(BridgeWrapper::BridgeException &e) + { + // If there was some error, don't try normal loading as well... unless the user really wants it. + if(isNative) + { + if(Reporting::Confirm((std::string(e.what()) + "\n\nDo you want to try to load the plugin natively?").c_str(), "OpenMPT Plugin Bridge", false, true) == cnfNo) + { + return nullptr; + } + } else + { + Reporting::Error(e.what(), "OpenMPT Plugin Bridge"); + return nullptr; + } } } @@ -256,14 +282,6 @@ } } - if(effect == nullptr) - { - // Re-try loading the plugin using our bridge instead. - FreeLibrary(library); - library = nullptr; - - effect = BridgeWrapper::Create(plugin); - } return effect; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |