From: <man...@us...> - 2013-11-16 20:28:26
|
Revision: 3243 http://sourceforge.net/p/modplug/code/3243 Author: manxorist Date: 2013-11-16 20:28:19 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Fix] Convert error message formatting to type-safe message formatting API in PluginManager.cpp. Correct reporting for unicode filenames. [Ref] Use unicode filenames in plugin cache. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-16 20:28:19 UTC (rev 3243) @@ -160,6 +160,9 @@ }; +MPT_DEPRECATED_PATH static inline std::string ToString(const mpt::PathString & x) { return mpt::ToLocale(x.ToWide()); } +static inline std::wstring ToWString(const mpt::PathString & x) { return x.ToWide(); } + } // namespace mpt #if defined(WIN32) Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 20:28:19 UTC (rev 3243) @@ -1935,7 +1935,7 @@ #endif - CString nonFoundPlugs; + std::wstring nonFoundPlugs; const mpt::PathString failedPlugin = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", "FailedPlugin", MPT_PATHSTRING("")); for(size_t plug = 0; plug < numPlugins; plug++) @@ -1958,10 +1958,9 @@ m_pPluginManager->AddPlugin(plugPath, true, true, &nonFoundPlugs); } } - if(nonFoundPlugs.GetLength() > 0) + if(!nonFoundPlugs.empty()) { - nonFoundPlugs.Insert(0, "Problems were encountered with plugins:\n"); - Reporting::Notification(nonFoundPlugs); + Reporting::Notification(L"Problems were encountered with plugins:\n" + nonFoundPlugs); } return FALSE; } Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-16 20:28:19 UTC (rev 3243) @@ -331,11 +331,13 @@ public: VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } bool IsValidPlugin(const VSTPluginLib *pLib); - VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); + VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, std::wstring* const errStr = nullptr); bool RemovePlugin(VSTPluginLib *); bool CreateMixPlugin(SNDMIXPLUGIN &, CSoundFile &); void OnIdle(); static void ReportPlugException(LPCSTR format,...); + static void ReportPlugException(const std::wstring &msg); + static void ReportPlugException(const std::string &msg); protected: void EnumerateDirectXDMOs(); Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 20:28:19 UTC (rev 3243) @@ -193,7 +193,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath.ToLocale().c_str()); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception caught in LoadLibrary (%1)", pluginPath)); } if(library != nullptr && library != INVALID_HANDLE_VALUE) @@ -250,8 +250,8 @@ // ID100000ID200000 = FullDllPath // ID100000ID200000.Flags = Plugin Flags (isInstrument + category). -VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) -//---------------------------------------------------------------------------------------------------------------------------------------------- +VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, std::wstring *const errStr) +//--------------------------------------------------------------------------------------------------------------------------------------------------- { const mpt::PathString fileName = dllPath.GetFileName(); @@ -259,8 +259,8 @@ { if(errStr) { - *errStr += "\nUnable to find "; - *errStr += dllPath.ToCString(); + *errStr += L"\nUnable to find "; + *errStr += dllPath.ToWide(); } } @@ -274,8 +274,9 @@ if(fromCache) { SettingsContainer & cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; - const std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName.ToLocale(), ""); + const char *const cacheSection = "PluginCache"; + const wchar_t *const cacheSectionW = L"PluginCache"; + const std::string IDs = cacheFile.Read<std::string>(cacheSectionW, fileName.ToWide(), ""); if(IDs.length() >= 16) { @@ -383,7 +384,7 @@ FreeLibrary(hLib); } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to load plugin \"%1\"!\n", p->libraryName)); } // Now it should be safe to assume that this plugin loaded properly. :) @@ -393,7 +394,8 @@ if(validPlug) { SettingsContainer &cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; + const char *const cacheSection = "PluginCache"; + const wchar_t *const cacheSectionW = L"PluginCache"; const std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); const std::string flagsKey = mpt::String::Format("%s.Flags", IDs); @@ -405,7 +407,7 @@ cacheFile.Write<mpt::PathString>(cacheSection, IDs, writePath); cacheFile.Write<mpt::PathString>(cacheSection, IDs, dllPath); - cacheFile.Write<std::string>(cacheSection, p->libraryName.ToLocale(), IDs); + cacheFile.Write<std::string>(cacheSectionW, p->libraryName.ToWide(), IDs); cacheFile.Write<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); } else { @@ -441,7 +443,7 @@ delete p; } catch (...) { - CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to release plugin \"%1\"!\n", pFactory->libraryName)); } return true; @@ -563,7 +565,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to create plugin \"%1\"!\n", pFound->libraryName)); } return validPlugin; @@ -629,4 +631,20 @@ va_end(va); } +void CVstPluginManager::ReportPlugException(const std::string &msg) +{ + Reporting::Notification(msg.c_str()); +#ifdef VST_LOG + Log("%s", msg.c_str()); +#endif +} + +void CVstPluginManager::ReportPlugException(const std::wstring &msg) +{ + Reporting::Notification(msg); +#ifdef VST_LOG + Log("%s", mpt::ToLocale(msg).c_str()); +#endif +} + #endif // NO_VST This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |