From: <sag...@us...> - 2013-11-10 00:28:08
|
Revision: 3160 http://sourceforge.net/p/modplug/code/3160 Author: saga-games Date: 2013-11-10 00:27:57 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Update VST plugin paths to mpt::PathString. Loading plugins and presets from unicode paths works perfectly now. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/plugins/JBridge.cpp trunk/OpenMPT/soundlib/plugins/JBridge.h Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -326,6 +326,12 @@ SplitPath(nullptr, &dir, nullptr, nullptr); return dir; } +PathString PathString::GetPath() const +{ + PathString drive, dir; + SplitPath(&drive, &dir, nullptr, nullptr); + return drive + dir; +} PathString PathString::GetFileName() const { PathString fname; Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/common/mptString.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -259,9 +259,24 @@ void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; PathString GetDrive() const; PathString GetDir() const; + PathString GetPath() const; PathString GetFileName() const; PathString GetFileExt() const; + bool HasTrailingSlash() const + { + if(empty()) + return false; +#if defined(WIN32) + if(path.back() == L'\\' || path.back() == L'/') + return true; +#else + if(path.back() == '/') + return true; +#endif + return false; + } + #endif // MODPLUG_TRACKER public: Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -81,7 +81,7 @@ CVstPluginManager *pPluginManager = theApp.GetPluginManager(); if (pPluginManager) { - pPluginManager->AddPlugin(path); + pPluginManager->AddPlugin(mpt::PathString::FromCString(path)); return NULL; } } @@ -1943,8 +1943,6 @@ BOOL CTrackApp::InitializeDXPlugins() //----------------------------------- { - TCHAR s[_MAX_PATH], tmp[32]; - m_pPluginManager = new CVstPluginManager; if(!m_pPluginManager) return FALSE; const size_t numPlugins = theApp.GetSettings().Read<int32>("VST Plugins", "NumPlugins", 0); @@ -1968,26 +1966,26 @@ CString nonFoundPlugs; - const CString failedPlugin = theApp.GetSettings().Read<CString>("VST Plugins", "FailedPlugin", ""); + const mpt::PathString failedPlugin = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", "FailedPlugin", MPT_PATHSTRING("")); for(size_t plug = 0; plug < numPlugins; plug++) { - s[0] = 0; + char tmp[32]; wsprintf(tmp, "Plugin%d", plug); - mpt::String::Copy(s, theApp.GetSettings().Read<std::string>("VST Plugins", tmp, "")); - if (s[0]) + mpt::PathString plugPath = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", tmp, MPT_PATHSTRING("")); + if(!plugPath.empty()) { - RelativePathToAbsolute(s); + RelativePathToAbsolute(plugPath); - if(!failedPlugin.Compare(s)) + if(plugPath == failedPlugin) { - const CString text = "The following plugin has previously crashed OpenMPT during initialisation:\n\n" + failedPlugin + "\n\nDo you still want to load it?"; + const CString text = "The following plugin has previously crashed OpenMPT during initialisation:\n\n" + failedPlugin.ToCString() + "\n\nDo you still want to load it?"; if(Reporting::Confirm(text, false, true) == cnfNo) { continue; } } - m_pPluginManager->AddPlugin(s, true, true, &nonFoundPlugs); + m_pPluginManager->AddPlugin(plugPath, true, true, &nonFoundPlugs); } } if(nonFoundPlugs.GetLength() > 0) @@ -2005,23 +2003,22 @@ if(!m_pPluginManager) return FALSE; #ifndef NO_VST - TCHAR s[_MAX_PATH], tmp[32]; VSTPluginLib *pPlug; pPlug = m_pPluginManager->GetFirstPlugin(); size_t plug = 0; while(pPlug) { - if(pPlug->dwPluginId1 != kDmoMagic) + if(pPlug->pluginId1 != kDmoMagic) { - s[0] = 0; + char tmp[32]; wsprintf(tmp, "Plugin%d", plug); - strcpy(s, pPlug->szDllPath); + mpt::PathString plugPath = pPlug->dllPath; if(theApp.IsPortableMode()) { - AbsolutePathToRelative(s); + AbsolutePathToRelative(plugPath); } - theApp.GetSettings().Write<std::string>("VST Plugins", tmp, s); + theApp.GetSettings().Write<mpt::PathString>("VST Plugins", tmp, plugPath); plug++; } pPlug = pPlug->pNext; Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -138,8 +138,8 @@ // Initialize plugin info MemsetZero(m_pPlugin->Info); - m_pPlugin->Info.dwPluginId1 = pFactory->dwPluginId1; - m_pPlugin->Info.dwPluginId2 = pFactory->dwPluginId2; + m_pPlugin->Info.dwPluginId1 = pFactory->pluginId1; + m_pPlugin->Info.dwPluginId2 = pFactory->pluginId2; switch(m_pPlugin->Info.dwPluginId2) { @@ -149,8 +149,9 @@ break; } - mpt::String::Copy(m_pPlugin->Info.szName, pFactory->szLibraryName); - mpt::String::Copy(m_pPlugin->Info.szLibraryName, pFactory->szLibraryName); + const std::string libraryName = pFactory->libraryName.ToLocale(); + mpt::String::Copy(m_pPlugin->Info.szName, libraryName); + mpt::String::Copy(m_pPlugin->Info.szLibraryName, libraryName); cs.Leave(); @@ -165,7 +166,6 @@ s[0] = 0; if ((p->GetDefaultEffectName(s)) && (s[0])) { - s[31] = 0; mpt::String::Copy(m_pPlugin->Info.szName, s); } } @@ -291,7 +291,7 @@ if(nameFilterActive) { // Apply name filter - CString displayName = p->szLibraryName; + CString displayName = p->libraryName.ToCString(); if (displayName.MakeLower().Find(m_sNameFilter) == -1) { p = p->pNext; @@ -299,7 +299,7 @@ } } - HTREEITEM h = AddTreeItem(p->szLibraryName, p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); + HTREEITEM h = AddTreeItem(p->libraryName.ToCString(), p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); categoryUsed[p->category] = true; if(nameFilterActive) @@ -317,7 +317,7 @@ { //Which plugin should be selected? - if(forceSelect != 0 && p->dwPluginId2 == forceSelect) + if(forceSelect != 0 && p->pluginId2 == forceSelect) { //forced selection (e.g. just after add plugin) currentPlug = h; @@ -332,12 +332,12 @@ } else if(m_pPlugin->Info.dwPluginId1 != 0 || m_pPlugin->Info.dwPluginId2 != 0) { //Plugin with matching ID to current slot's plug - if(p->dwPluginId1 == m_pPlugin->Info.dwPluginId1 - && p->dwPluginId2 == m_pPlugin->Info.dwPluginId2) + if(p->pluginId1 == m_pPlugin->Info.dwPluginId1 + && p->pluginId2 == m_pPlugin->Info.dwPluginId2) { currentPlug = h; } - } else if(p->dwPluginId2 == TrackerSettings::Instance().gnPlugWindowLast) + } else if(p->pluginId2 == TrackerSettings::Instance().gnPlugWindowLast) { // Previously selected plugin currentPlug = h; @@ -375,9 +375,18 @@ } -HTREEITEM CSelectPluginDlg::AddTreeItem(const char *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) -//---------------------------------------------------------------------------------------------------------------- +HTREEITEM CSelectPluginDlg::AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) +//----------------------------------------------------------------------------------------------------------------- { + /*TVINSERTSTRUCTW tvi; + MemsetZero(tvi); + tvi.hInsertAfter = (sort ? TVI_SORT : TVI_FIRST); + tvi.hParent = hParent; + tvi.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT; + tvi.item.iImage = tvi.item.iSelectedImage = image; + tvi.item.pszText = title; + tvi.item.lParam = lParam; + return (HTREEITEM)::SendMessage(m_treePlugins.m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvi);*/ return m_treePlugins.InsertItem( TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT, title, @@ -410,7 +419,7 @@ VSTPluginLib *pPlug = (VSTPluginLib *)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); if ((pManager) && (pManager->IsValidPlugin(pPlug))) { - SetDlgItemText(IDC_TEXT_CURRENT_VSTPLUG, pPlug->szDllPath); + SetDlgItemTextW(m_hWnd, IDC_TEXT_CURRENT_VSTPLUG, pPlug->dllPath.ToWide().c_str()); } else { SetDlgItemText(IDC_TEXT_CURRENT_VSTPLUG, ""); @@ -439,7 +448,7 @@ for(size_t p = 0; p < CountOf(problemPlugs); p++) { - if(problemPlugs[p].id2 == plug->dwPluginId2 /*&& gProblemPlugs[p].id1 == plug->dwPluginId1*/) + if(problemPlugs[p].id2 == plug->pluginId2 /*&& gProblemPlugs[p].id1 == plug->dwPluginId1*/) { CString s; s.Format("WARNING: This plugin has been identified as %s,\nwhich is known to have the following problem with OpenMPT:\n\n%s\n\nWould you still like to add this plugin to the library?", problemPlugs[p].name, problemPlugs[p].problem); @@ -470,12 +479,9 @@ const FileDialog::PathList &files = dlg.GetFilenames(); for(size_t counter = 0; counter < files.size(); counter++) { - - CString sFilename = files[counter].ToCString(); - if (pManager) { - plugLib = pManager->AddPlugin(sFilename, false); + plugLib = pManager->AddPlugin(files[counter], false); if (plugLib) { bOk = true; @@ -489,7 +495,7 @@ if (bOk) { // Force selection to last added plug. - UpdatePluginsList(plugLib ? plugLib->dwPluginId2 : 0); + UpdatePluginsList(plugLib ? plugLib->pluginId2 : 0); } else { Reporting::Error("At least one selected file was not a valid VST Plugin."); Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -26,7 +26,7 @@ CTreeCtrl m_treePlugins; CString m_sNameFilter; - HTREEITEM AddTreeItem(const char *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); + HTREEITEM AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); public: CSelectPluginDlg(CModDoc *pModDoc, int nPlugSlot, CWnd *parent); Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -128,9 +128,7 @@ //-------------------------------------------- { HKEY hkEnum; - CHAR keyname[128]; - CHAR s[256]; - WCHAR w[100]; + WCHAR keyname[128]; LONG cr; DWORD index; @@ -138,36 +136,31 @@ index = 0; while (cr == ERROR_SUCCESS) { - if ((cr = RegEnumKey(hkEnum, index, (LPTSTR)keyname, sizeof(keyname))) == ERROR_SUCCESS) + if ((cr = RegEnumKeyW(hkEnum, index, keyname, CountOf(keyname))) == ERROR_SUCCESS) { CLSID clsid; - - wsprintf(s, "{%s}", keyname); - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)s,-1,(LPWSTR)w,98); - if (CLSIDFromString(w, &clsid) == S_OK) + std::wstring formattedKey = std::wstring(L"{") + std::wstring(keyname) + std::wstring(L"}"); + if(CLSIDFromString(formattedKey.c_str(), &clsid) == S_OK) { HKEY hksub; - - wsprintf(s, "software\\classes\\DirectShow\\MediaObjects\\%s", keyname); - if (RegOpenKey(HKEY_LOCAL_MACHINE, s, &hksub) == ERROR_SUCCESS) + formattedKey = std::wstring(L"software\\classes\\DirectShow\\MediaObjects\\") + std::wstring(keyname); + if (RegOpenKeyW(HKEY_LOCAL_MACHINE, formattedKey.c_str(), &hksub) == ERROR_SUCCESS) { + WCHAR name[64]; DWORD datatype = REG_SZ; - DWORD datasize = 64; + DWORD datasize = sizeof(name); - if (ERROR_SUCCESS == RegQueryValueEx(hksub, nullptr, 0, &datatype, (LPBYTE)s, &datasize)) + if(ERROR_SUCCESS == RegQueryValueExW(hksub, nullptr, 0, &datatype, (LPBYTE)name, &datasize)) { - VSTPluginLib *p = new VSTPluginLib(); + StringFromGUID2(clsid, keyname, 100); + + VSTPluginLib *p = new VSTPluginLib(mpt::PathString::FromWide(keyname), mpt::PathString::FromWide(name)); p->pNext = m_pVstHead; - p->dwPluginId1 = kDmoMagic; - p->dwPluginId2 = clsid.Data1; + p->pluginId1 = kDmoMagic; + p->pluginId2 = clsid.Data1; p->category = VSTPluginLib::catDMO; - mpt::String::Copy(p->szLibraryName, s); - - StringFromGUID2(clsid, w, 100); - WideCharToMultiByte(CP_ACP, 0, w, -1, p->szDllPath, sizeof(p->szDllPath), nullptr, nullptr); - mpt::String::SetNullTerminator(p->szDllPath); #ifdef DMO_LOG - Log("Found \"%s\" clsid=%s\n", p->szLibraryName, p->szDllPath); + Log("Found \"%s\" clsid=%s\n", p->libraryName.AsNative().c_str(), p->dllPath.AsNative().c_str()); #endif if (m_pVstHead) m_pVstHead->pPrev = p; m_pVstHead = p; @@ -182,15 +175,15 @@ } -void CVstPluginManager::LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library) -//---------------------------------------------------------------------------------------------- +void CVstPluginManager::LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library) +//--------------------------------------------------------------------------------------------------------- { library = nullptr; effect = nullptr; try { - library = LoadLibrary(pluginPath); + library = LoadLibraryW(pluginPath.ToWide().c_str()); if(library == nullptr) { @@ -213,7 +206,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath); + CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath.ToLocale().c_str()); } if(library != nullptr && library != INVALID_HANDLE_VALUE) @@ -269,52 +262,47 @@ // ID100000ID200000 = FullDllPath // ID100000ID200000.Flags = Plugin Flags (isInstrument + category). -VSTPluginLib *CVstPluginManager::AddPlugin(LPCSTR pszDllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) -//--------------------------------------------------------------------------------------------------------------------------------- +VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) +//---------------------------------------------------------------------------------------------------------------------------------------------- { - TCHAR szPath[_MAX_PATH]; - - if(checkFileExistence && (PathFileExists(pszDllPath) == FALSE)) + const mpt::PathString fileName = dllPath.GetFileName(); + + if(checkFileExistence && (PathFileExistsW(dllPath.AsNative().c_str()) == FALSE)) { if(errStr) { *errStr += "\nUnable to find "; - *errStr += pszDllPath; + *errStr += dllPath.ToCString(); } } VSTPluginLib *pDup = m_pVstHead; while(pDup != nullptr) { - if (!lstrcmpi(pszDllPath, pDup->szDllPath)) return pDup; + if(!dllPath.CompareNoCase(dllPath, pDup->dllPath)) return pDup; pDup = pDup->pNext; } // Look if the plugin info is stored in the PluginCache if(fromCache) { - const std::string cacheSection = "PluginCache"; + const char *cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - char fileName[_MAX_PATH]; - _splitpath(pszDllPath, nullptr, nullptr, fileName, nullptr); - std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName, ""); + std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName.ToLocale(), ""); - if (IDs.length() >= 16) + if(IDs.length() >= 16) { // Get path from cache file - mpt::String::Copy(szPath, cacheFile.Read<std::string>(cacheSection, IDs, "")); - mpt::String::SetNullTerminator(szPath); - theApp.RelativePathToAbsolute(szPath); + mpt::PathString realPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); + realPath = theApp.RelativePathToAbsolute(realPath); - if ((szPath[0]) && (!lstrcmpi(szPath, pszDllPath))) + if(!realPath.empty() && !dllPath.CompareNoCase(realPath, dllPath)) { - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); if(p == nullptr) { return nullptr; } - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = '\0'; p->pNext = m_pVstHead; if (m_pVstHead) m_pVstHead->pPrev = p; m_pVstHead = p; @@ -327,10 +315,10 @@ n &= 0x0f; if (i < 8) { - p->dwPluginId1 = (p->dwPluginId1 << 4) | n; + p->pluginId1 = (p->pluginId1 << 4) | n; } else { - p->dwPluginId2 = (p->dwPluginId2 << 4) | n; + p->pluginId2 = (p->pluginId2 << 4) | n; } } @@ -338,43 +326,41 @@ p->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); #ifdef VST_USE_ALTERNATIVE_MAGIC - if( p->dwPluginId1 == kEffectMagic ) + if( p->pluginId1 == kEffectMagic ) { - p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure (for VSTs with same UID) + p->pluginId1 = CalculateCRC32fromFilename(p->libraryName); // Make Plugin ID unique for sure (for VSTs with same UID) }; #endif // VST_USE_ALTERNATIVE_MAGIC #ifdef VST_LOG - Log("Plugin \"%s\" found in PluginCache\n", p->szLibraryName); + Log("Plugin \"%s\" found in PluginCache\n", p->libraryName); #endif // VST_LOG return p; } else { #ifdef VST_LOG - Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, pszDllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath); + Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, dllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath); #endif // VST_LOG } } } // If this key contains a file name on program launch, a plugin previously crashed OpenMPT. - theApp.GetSettings().Write<std::string>("VST Plugins", "FailedPlugin", pszDllPath); + theApp.GetSettings().Write<mpt::PathString>("VST Plugins", "FailedPlugin", dllPath); AEffect *pEffect; HINSTANCE hLib; bool validPlug = false; - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); if(p == nullptr) { return nullptr; } - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = 0; p->pNext = m_pVstHead; try { - LoadPlugin(pszDllPath, pEffect, hLib); + LoadPlugin(dllPath, pEffect, hLib); if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr) { @@ -384,11 +370,11 @@ m_pVstHead = p; #ifdef VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure + p->pluginId1 = CalculateCRC32fromFilename(p->libraryName); // Make Plugin ID unique for sure #else - p->dwPluginId1 = pEffect->magic; + p->pluginId1 = pEffect->magic; #endif // VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId2 = pEffect->uniqueID; + p->pluginId2 = pEffect->uniqueID; GetPluginInformation(pEffect, *p); @@ -396,7 +382,7 @@ int nver = pEffect->dispatcher(pEffect, effGetVstVersion, 0,0, nullptr, 0); if (!nver) nver = pEffect->version; Log("%-20s: v%d.0, %d in, %d out, %2d programs, %2d params, flags=0x%04X realQ=%d offQ=%d\n", - p->szLibraryName, nver, + p->libraryName, nver, pEffect->numInputs, pEffect->numOutputs, pEffect->numPrograms, pEffect->numParams, pEffect->flags, pEffect->realQualities, pEffect->offQualities); @@ -410,7 +396,7 @@ FreeLibrary(hLib); } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->libraryName); } // Now it should be safe to assume that this plugin loaded properly. :) @@ -421,19 +407,18 @@ { const std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string IDs = mpt::String::Format("%08X%08X", p->dwPluginId1, p->dwPluginId2); + std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); std::string flagsKey = mpt::String::Format("%s.Flags", IDs); - _tcsncpy(szPath, pszDllPath, CountOf(szPath) - 1); + mpt::PathString writePath = dllPath; if(theApp.IsPortableMode()) { - theApp.AbsolutePathToRelative(szPath); + theApp.AbsolutePathToRelative(writePath); } - mpt::String::SetNullTerminator(szPath); - cacheFile.Write<std::string>(cacheSection, IDs, szPath); - cacheFile.Write<CString>(cacheSection, IDs, pszDllPath); - cacheFile.Write<std::string>(cacheSection, p->szLibraryName, IDs); + 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<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); } else { @@ -469,7 +454,7 @@ delete p; } catch (...) { - CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->libraryName); } return true; @@ -488,29 +473,29 @@ VSTPluginLib *p = m_pVstHead; - while (p) + while(p) { bool b1 = false, b2 = false; - if ((p->dwPluginId1 == mixPlugin.Info.dwPluginId1) - && (p->dwPluginId2 == mixPlugin.Info.dwPluginId2)) + if((p->pluginId1 == mixPlugin.Info.dwPluginId1) + && (p->pluginId2 == mixPlugin.Info.dwPluginId2)) { b1 = true; } - if (!mpt::strnicmp(p->szLibraryName, mixPlugin.GetLibraryName(), 64)) + if(!mpt::strnicmp(p->libraryName.ToLocale().c_str(), mixPlugin.GetLibraryName(), 64)) { b2 = true; } - if ((b1) && (b2)) + if((b1) && (b2)) { nMatch = 3; pFound = p; } else - if ((b1) && (nMatch < 2)) + if((b1) && (nMatch < 2)) { nMatch = 2; pFound = p; } else - if ((b2) && (nMatch < 1)) + if((b2) && (nMatch < 1)) { nMatch = 1; pFound = p; @@ -518,7 +503,7 @@ p = p->pNext; } - if (mixPlugin.Info.dwPluginId1 == kDmoMagic) + if(mixPlugin.Info.dwPluginId1 == kDmoMagic) { if (!pFound) return FALSE; AEffect *pEffect = DmoToVst(pFound); @@ -534,35 +519,31 @@ } } - if ((!pFound) && strcmp(mixPlugin.GetLibraryName(), "")) + if((!pFound) && strcmp(mixPlugin.GetLibraryName(), "")) { // Try finding the plugin DLL in the plugin directory instead. - CHAR s[_MAX_PATH]; - mpt::String::Copy(s, TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS).ToLocale()); - if(!s[0]) + mpt::PathString fullPath; + fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS); + if(fullPath.empty()) { - mpt::String::CopyN(s, theApp.GetAppDirPath().ToLocale().c_str()); + fullPath = theApp.GetAppDirPath() + MPT_PATHSTRING("Plugins\\"); } - size_t len = strlen(s); - if((len > 0) && (s[len - 1] != '\\') && (s[len - 1] != '/')) + if(!fullPath.HasTrailingSlash()) { - strcat(s, "\\"); + fullPath += MPT_PATHSTRING("\\"); } - strncat(s, mixPlugin.GetLibraryName(), CountOf(s)); - strncat(s, ".dll", CountOf(s)); + fullPath += mpt::PathString::FromLocale(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll"); - mpt::String::SetNullTerminator(s); - - pFound = AddPlugin(s); - if (!pFound) + pFound = AddPlugin(fullPath); + if(!pFound) { std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); std::string IDs = cacheFile.Read<std::string>(cacheSection, mixPlugin.GetLibraryName(), ""); if (IDs.length() >= 16) { - CString strFullPath = cacheFile.Read<CString>(cacheSection, IDs, ""); - if ((strFullPath) && (strFullPath[0])) pFound = AddPlugin(strFullPath); + fullPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); + if(!fullPath.empty()) pFound = AddPlugin(fullPath); } } } @@ -576,7 +557,7 @@ try { - LoadPlugin(pFound->szDllPath, pEffect, hLibrary); + LoadPlugin(pFound->dllPath, pEffect, hLibrary); if(pEffect != nullptr && pEffect->dispatcher != nullptr && pEffect->magic == kEffectMagic) { @@ -592,7 +573,7 @@ // Update cached information const std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->dwPluginId1, pFound->dwPluginId2); + std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->pluginId1, pFound->pluginId2); cacheFile.Write<int32>(cacheSection, flagsKey, pFound->EncodeCacheFlags()); } @@ -609,7 +590,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->libraryName); } return validPlugin; @@ -1396,7 +1377,7 @@ #ifdef VST_LOG Log("%s: vst ver %d.0, flags=%04X, %d programs, %d parameters\n", - m_Factory.szLibraryName, (m_bIsVst2) ? 2 : 1, m_Effect.flags, + m_Factory.libraryName, (m_bIsVst2) ? 2 : 1, m_Effect.flags, m_Effect.numPrograms, m_Effect.numParams); #endif @@ -1592,12 +1573,11 @@ bool CVstPlugin::SaveProgram() //---------------------------- { - std::string defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS).ToLocale(); + mpt::PathString defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS); bool useDefaultDir = !defaultDir.empty(); if(!useDefaultDir) { - defaultDir = m_Factory.szDllPath; - defaultDir = defaultDir.substr(0, defaultDir.find_last_of("\\/")); + defaultDir = m_Factory.dllPath.GetPath(); } char rawname[MAX(kVstMaxProgNameLen + 1, 256)] = ""; // kVstMaxProgNameLen is 24... @@ -1610,7 +1590,7 @@ .DefaultFilename(rawname) .ExtensionFilter("VST Plugin Programs (*.fxp)|*.fxp|" "VST Plugin Banks (*.fxb)|*.fxb||") - .WorkingDirectory(mpt::PathString::FromLocale(defaultDir)); + .WorkingDirectory(defaultDir); if(!dlg.Show()) return false; if(useDefaultDir) @@ -1636,12 +1616,11 @@ bool CVstPlugin::LoadProgram() //---------------------------- { - std::string defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS).ToLocale(); + mpt::PathString defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS); bool useDefaultDir = !defaultDir.empty(); if(!useDefaultDir) { - defaultDir = m_Factory.szDllPath; - defaultDir = defaultDir.substr(0, defaultDir.find_last_of("\\/")); + defaultDir = m_Factory.dllPath.GetPath(); } FileDialog dlg = OpenFileDialog() @@ -1650,7 +1629,7 @@ "VST Plugin Programs (*.fxp)|*.fxp|" "VST Plugin Banks (*.fxb)|*.fxb|" "All Files|*.*||") - .WorkingDirectory(mpt::PathString::FromLocale(defaultDir)); + .WorkingDirectory(defaultDir); if(!dlg.Show()) return false; if(useDefaultDir) @@ -1694,13 +1673,13 @@ if(m_Effect.dispatcher != nullptr) { #ifdef VST_LOG - Log("About to Dispatch(%d) (Plugin=\"%s\"), index: %d, value: %d, value: %h, value: %f!\n", opCode, m_Factory.szLibraryName, index, value, ptr, opt); + Log("About to Dispatch(%d) (Plugin=\"%s\"), index: %d, value: %d, value: %h, value: %f!\n", opCode, m_Factory.libraryName, index, value, ptr, opt); #endif result = m_Effect.dispatcher(&m_Effect, opCode, index, value, ptr, opt); } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Dispatch(%d) (Plugin=\"%s\")!\n", opCode, m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Dispatch(%d) (Plugin=\"%s\")!\n", opCode, m_Factory.libraryName); } return result; @@ -1819,7 +1798,7 @@ } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in SetParameter(%d, 0.%03d) (Plugin=%s)\n", nIndex, (int)(fValue*1000), m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in SetParameter(%d, 0.%03d) (Plugin=%s)\n", nIndex, (int)(fValue*1000), m_Factory.libraryName); } } @@ -1923,7 +1902,7 @@ m_bPlugResumed = true; } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Resume() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Resume() (Plugin=%s)\n", m_Factory.libraryName); } } @@ -1940,7 +1919,7 @@ m_bPlugResumed = false; } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_Factory.libraryName); } } } @@ -1959,7 +1938,7 @@ } catch (...) { CVstPluginManager::ReportPlugException("Exception in ProcessVSTEvents() (Plugin=%s, numEvents:%d)\n", - m_Factory.szLibraryName, vstEvents.GetNumEvents()); + m_Factory.libraryName, vstEvents.GetNumEvents()); } } } @@ -2801,7 +2780,7 @@ } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in ToggleEditor() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in ToggleEditor() (Plugin=%s)\n", m_Factory.libraryName); } } @@ -3471,12 +3450,9 @@ AEffect *DmoToVst(VSTPluginLib *pLib) //----------------------------------- { - WCHAR w[100]; CLSID clsid; - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pLib->szDllPath, -1, (LPWSTR)w, CountOf(w)); - w[99] = 0; - if (CLSIDFromString(w, &clsid) == S_OK) + if (CLSIDFromString(pLib->dllPath.ToWide().c_str(), &clsid) == S_OK) { IMediaObject *pMO = nullptr; IMediaObjectInPlace *pMOIP = nullptr; @@ -3496,11 +3472,11 @@ return (p) ? p->GetEffect() : nullptr; } #ifdef DMO_LOG - Log("%s: Unable to use this DMO\n", pLib->szLibraryName); + Log("%s: Unable to use this DMO\n", pLib->libraryName); #endif } #ifdef DMO_LOG - else Log("%s: Failed to get IMediaObject & IMediaObjectInPlace interfaces\n", pLib->szLibraryName); + else Log("%s: Failed to get IMediaObject & IMediaObjectInPlace interfaces\n", pLib->libraryName); #endif if (pMO) pMO->Release(); if (pMOIP) pMOIP->Release(); Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -62,24 +62,20 @@ VSTPluginLib *pPrev, *pNext; CVstPlugin *pPluginsList; - VstInt32 dwPluginId1; - VstInt32 dwPluginId2; + mpt::PathString libraryName; // Display name + mpt::PathString dllPath; // Full path name + VstInt32 pluginId1; + VstInt32 pluginId2; PluginCategory category; bool isInstrument; - CHAR szLibraryName[_MAX_FNAME]; - CHAR szDllPath[_MAX_PATH]; - VSTPluginLib(const CHAR *dllPath = nullptr) + VSTPluginLib(const mpt::PathString &dllPath, const mpt::PathString &libraryName) + : pPrev(nullptr), pNext(nullptr), pPluginsList(nullptr), + libraryName(libraryName), dllPath(dllPath), + pluginId1(0), pluginId2(0), + category(catUnknown), + isInstrument(false) { - pPrev = pNext = nullptr; - dwPluginId1 = dwPluginId2 = 0; - isInstrument = false; - pPluginsList = nullptr; - category = catUnknown; - if(dllPath != nullptr) - { - mpt::String::CopyN(szDllPath, dllPath); - } } uint32 EncodeCacheFlags() @@ -336,7 +332,7 @@ public: VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } bool IsValidPlugin(const VSTPluginLib *pLib); - VSTPluginLib *AddPlugin(LPCSTR pszDllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); + VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); bool RemovePlugin(VSTPluginLib *); bool CreateMixPlugin(SNDMIXPLUGIN &, CSoundFile &); void OnIdle(); @@ -344,7 +340,7 @@ protected: void EnumerateDirectXDMOs(); - void LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library); + void LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library); protected: VstIntPtr VstCallback(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt); @@ -360,7 +356,7 @@ #else // NO_VST public: - VSTPluginLib *AddPlugin(LPCSTR, bool = true, const bool = false, CString* const = 0) {return 0;} + VSTPluginLib *AddPlugin(const mpt::PathString &, bool = true, const bool = false, CString* const = 0) {return 0;} VSTPluginLib *GetFirstPlugin() const { return 0; } void OnIdle() {} #endif // NO_VST Modified: trunk/OpenMPT/soundlib/plugins/JBridge.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -36,12 +36,12 @@ //Check if it's a plugin_name.xx.dll -bool IsBootStrapDll(const char *path) -//----------------------------------- +bool IsBootStrapDll(const mpt::PathString &path) +//---------------------------------------------- { bool ret = false; - HMODULE hModule = LoadLibrary(path); + HMODULE hModule = LoadLibraryW(path.ToWide().c_str()); if(!hModule) { // Some error... @@ -61,8 +61,8 @@ } -AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const char *pluginPath) -//--------------------------------------------------------------------------------- +AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const mpt::PathString &pluginPath) +//-------------------------------------------------------------------------------------------- { // Ignore JBridge bootstrap DLLs if(IsBootStrapDll(pluginPath)) @@ -105,7 +105,7 @@ return nullptr; } - return pfnBridgeMain(audioMaster, pluginPath); + return pfnBridgeMain(audioMaster, pluginPath.ToLocale().c_str()); } } Modified: trunk/OpenMPT/soundlib/plugins/JBridge.h =================================================================== --- trunk/OpenMPT/soundlib/plugins/JBridge.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/soundlib/plugins/JBridge.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -18,8 +18,8 @@ namespace JBridge { #ifdef ENABLE_JBRIDGE - AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const char *pluginPath); + AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const mpt::PathString &pluginPath); #else - inline void *LoadBridgedPlugin(void *, const char *) { return nullptr; } + inline void *LoadBridgedPlugin(void *, const mpt::PathString &) { return nullptr; } #endif // ENABLE_JBRIDGE } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |