From: <man...@us...> - 2013-11-09 15:35:19
|
Revision: 3151 http://sourceforge.net/p/modplug/code/3151 Author: manxorist Date: 2013-11-09 15:35:10 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Add case-insensitive comparison function to mpt::PathString (windows only). [Ref] Convert CDlsBank to mpt::PathString. [Ref] Related cleanups and conversions. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_ins.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/Dlsbank.h Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -245,6 +245,13 @@ return path; } +#if defined(WIN32) + static int CompareNoCase(const PathString & a, const PathString & b) + { + return lstrcmpiW(a.ToWide().c_str(), b.ToWide().c_str()); + } +#endif + public: #if defined(MODPLUG_TRACKER) Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -1857,7 +1857,7 @@ const FileDialog::PathList &files = dlg.GetFilenames(); for(size_t counter = 0; counter < files.size(); counter++) { - CTrackApp::AddDLSBank(files[counter].ToLocale().c_str()); + CTrackApp::AddDLSBank(files[counter]); } m_wndTree.RefreshDlsBanks(); EndWaitCursor(); @@ -1876,7 +1876,7 @@ if(!dlg.Show()) return; BeginWaitCursor(); - CTrackApp::ImportMidiConfig(dlg.GetFirstFile().ToLocale().c_str()); + CTrackApp::ImportMidiConfig(dlg.GetFirstFile()); m_wndTree.RefreshMidiLibrary(); EndWaitCursor(); } @@ -2527,7 +2527,7 @@ for(size_t i = 0; i < 2; i++) // 0: app items, 1: user items { // To avoid duplicates, check whether app path and config path are the same. - if (i == 1 && _tcsicmp(CTrackApp::GetAppDirPath().ToCString(), theApp.GetConfigPath().ToCString()) == 0) + if (i == 1 && mpt::PathString::CompareNoCase(CTrackApp::GetAppDirPath(), theApp.GetConfigPath()) == 0) break; CFileFind fileFind; CFixedStringT<CString, MAX_PATH> sPath; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -250,10 +250,10 @@ CDLSBank *pCachedBank = NULL, *pEmbeddedBank = NULL; CHAR szCachedBankFile[_MAX_PATH] = ""; - if (CDLSBank::IsDLSBank(lpszPathName)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString(lpszPathName))) { pEmbeddedBank = new CDLSBank(); - pEmbeddedBank->Open(lpszPathName); + pEmbeddedBank->Open(mpt::PathString::FromCString(lpszPathName)); } m_SndFile.ChangeModTypeTo(MOD_TYPE_IT); BeginWaitCursor(); @@ -300,7 +300,7 @@ if ((pszMidiMapName) && (pszMidiMapName[0]) && (!bEmbedded)) { // Load From DLS Bank - if (CDLSBank::IsDLSBank(pszMidiMapName)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromLocale(pszMidiMapName))) { CDLSBank *pDLSBank = NULL; @@ -312,7 +312,7 @@ if (pCachedBank) delete pCachedBank; pCachedBank = new CDLSBank; strcpy(szCachedBankFile, pszMidiMapName); - if (pCachedBank->Open(pszMidiMapName)) pDLSBank = pCachedBank; + if (pCachedBank->Open(mpt::PathString::FromLocale(pszMidiMapName))) pDLSBank = pCachedBank; } if (pDLSBank) { Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -304,10 +304,10 @@ LPMIDILIBSTRUCT CTrackApp::glpMidiLibrary = NULL; -BOOL CTrackApp::ImportMidiConfig(LPCSTR lpszConfigFile, BOOL bNoWarn) -//------------------------------------------------------------------- +BOOL CTrackApp::ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarn) +//----------------------------------------------------------------------------- { - if ((!lpszConfigFile) || (!lpszConfigFile[0])) return FALSE; + if(filename.empty()) return FALSE; if (!glpMidiLibrary) { @@ -316,7 +316,7 @@ MemsetZero(*glpMidiLibrary); } - if (CDLSBank::IsDLSBank(lpszConfigFile)) + if (CDLSBank::IsDLSBank(filename)) { ConfirmAnswer result = cnfYes; if (!bNoWarn) @@ -328,7 +328,7 @@ if (result == cnfCancel) return FALSE; const bool bReplaceAll = (result == cnfNo); CDLSBank dlsbank; - if (dlsbank.Open(lpszConfigFile)) + if (dlsbank.Open(filename)) { for (UINT iIns=0; iIns<256; iIns++) { @@ -343,7 +343,7 @@ { if ((glpMidiLibrary->MidiMap[iIns] = new CHAR[_MAX_PATH]) == NULL) break; } - strcpy(glpMidiLibrary->MidiMap[iIns], lpszConfigFile); + strcpy(glpMidiLibrary->MidiMap[iIns], filename.ToLocale().c_str()); } } } @@ -351,7 +351,7 @@ return TRUE; } - IniFileSettingsContainer file(mpt::PathString::FromLocale(lpszConfigFile)); + IniFileSettingsContainer file(filename); return ImportMidiConfig(file); } @@ -414,11 +414,11 @@ } -BOOL CTrackApp::ExportMidiConfig(LPCSTR lpszConfigFile) -//----------------------------------------------------- +BOOL CTrackApp::ExportMidiConfig(const mpt::PathString &filename) +//--------------------------------------------------------------- { - if ((!glpMidiLibrary) || (!lpszConfigFile) || (!lpszConfigFile[0])) return FALSE; - IniFileSettingsContainer file(mpt::PathString::FromLocale(lpszConfigFile)); + if((!glpMidiLibrary) || filename.empty()) return FALSE; + IniFileSettingsContainer file(filename); return ExportMidiConfig(file); } @@ -458,8 +458,7 @@ BOOL CTrackApp::LoadDefaultDLSBanks() //----------------------------------- { - CHAR szFileName[MAX_PATH]; - HKEY key; + mpt::PathString filename; CString storedVersion = theApp.GetSettings().Read<CString>("Version", "Version", ""); //If version number stored in INI is 1.17.02.40 or later, load DLS from INI file. @@ -471,10 +470,9 @@ for(size_t i = 0; i < numBanks; i++) { wsprintf(s, _T("Bank%d"), i + 1); - TCHAR szPath[_MAX_PATH]; - mpt::String::Copy(szPath, theApp.GetSettings().Read<std::string>("DLS Banks", s, "")); - theApp.RelativePathToAbsolute(szPath); - AddDLSBank(szPath); + mpt::PathString path = theApp.GetSettings().Read<mpt::PathString>("DLS Banks", s, mpt::PathString()); + path = theApp.RelativePathToAbsolute(path); + AddDLSBank(path); } } else { @@ -483,29 +481,35 @@ SaveDefaultDLSBanks(); // This will avoid a crash the next time if we crash while loading the bank - szFileName[0] = 0; - GetSystemDirectory(szFileName, CountOf(szFileName)); - lstrcat(szFileName, "\\GM.DLS"); - if (!AddDLSBank(szFileName)) + WCHAR szFileNameW[MAX_PATH]; + szFileNameW[0] = 0; + GetSystemDirectoryW(szFileNameW, CountOf(szFileNameW)); + filename = mpt::PathString::FromNative(szFileNameW); + filename += MPT_PATHSTRING("\\GM.DLS"); + if(!AddDLSBank(filename)) { - GetWindowsDirectory(szFileName, CountOf(szFileName)); - lstrcat(szFileName, "\\SYSTEM32\\DRIVERS\\GM.DLS"); - if (!AddDLSBank(szFileName)) + szFileNameW[0] = 0; + GetWindowsDirectoryW(szFileNameW, CountOf(szFileNameW)); + filename = mpt::PathString::FromNative(szFileNameW); + filename += MPT_PATHSTRING("\\SYSTEM32\\DRIVERS\\GM.DLS"); + if(!AddDLSBank(filename)) { + HKEY key; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic", 0, KEY_READ, &key) == ERROR_SUCCESS) { + CHAR szFileName[MAX_PATH]; DWORD dwRegType = REG_SZ; DWORD dwSize = sizeof(szFileName); szFileName[0] = 0; if (RegQueryValueEx(key, "GMFilePath", NULL, &dwRegType, (LPBYTE)&szFileName, &dwSize) == ERROR_SUCCESS) { - AddDLSBank(szFileName); + AddDLSBank(mpt::PathString::FromLocale(szFileName)); } RegCloseKey(key); } } } - if (glpMidiLibrary) ImportMidiConfig(szFileName, TRUE); + if(glpMidiLibrary) ImportMidiConfig(filename, TRUE); return TRUE; } @@ -531,7 +535,7 @@ dwRegType = REG_SZ; dwSize = sizeof(szFileNameX); RegQueryValueEx(keyX, s, NULL, &dwRegType, (LPBYTE)szFileNameX, &dwSize); - AddDLSBank(szFileNameX); + AddDLSBank(mpt::PathString::FromLocale(szFileNameX)); } } RegCloseKey(keyX); @@ -543,22 +547,21 @@ //----------------------------------- { TCHAR s[64]; - TCHAR szPath[_MAX_PATH]; DWORD nBanks = 0; for(size_t i = 0; i < gpDLSBanks.size(); i++) { - if(!gpDLSBanks[i] || !gpDLSBanks[i]->GetFileName() || !gpDLSBanks[i]->GetFileName()[0]) + if(!gpDLSBanks[i] || gpDLSBanks[i]->GetFileName().empty()) continue; - _tcsncpy(szPath, gpDLSBanks[i]->GetFileName(), CountOf(szPath) - 1); + mpt::PathString path = gpDLSBanks[i]->GetFileName(); if(theApp.IsPortableMode()) { - theApp.AbsolutePathToRelative(szPath); + path = theApp.AbsolutePathToRelative(path); } wsprintf(s, _T("Bank%d"), nBanks+1); - theApp.GetSettings().Write<std::string>("DLS Banks", s, szPath); + theApp.GetSettings().Write<mpt::PathString>("DLS Banks", s, path); nBanks++; } @@ -578,17 +581,17 @@ } -BOOL CTrackApp::AddDLSBank(LPCSTR lpszFileName) -//--------------------------------------------- +BOOL CTrackApp::AddDLSBank(const mpt::PathString &filename) +//--------------------------------------------------------- { - if(!lpszFileName || !lpszFileName[0] || !CDLSBank::IsDLSBank(lpszFileName)) return FALSE; + if(filename.empty() || !CDLSBank::IsDLSBank(filename)) return FALSE; // Check for dupes for(size_t i = 0; i < gpDLSBanks.size(); i++) { - if(gpDLSBanks[i] && !lstrcmpi(lpszFileName, gpDLSBanks[i]->GetFileName())) return TRUE; + if(gpDLSBanks[i] && !mpt::PathString::CompareNoCase(filename, gpDLSBanks[i]->GetFileName())) return TRUE; } CDLSBank *bank = new CDLSBank; - if(bank->Open(lpszFileName)) + if(bank->Open(filename)) { gpDLSBanks.push_back(bank); return TRUE; Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -138,15 +138,15 @@ static MODTYPE GetDefaultDocType() { return m_nDefaultDocType; } static void SetDefaultDocType(MODTYPE n) { m_nDefaultDocType = n; } static LPMIDILIBSTRUCT GetMidiLibrary() { return glpMidiLibrary; } - static BOOL ImportMidiConfig(LPCSTR lpszFileName, BOOL bNoWarning=FALSE); - static BOOL ExportMidiConfig(LPCSTR lpszFileName); + static BOOL ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarning=FALSE); + static BOOL ExportMidiConfig(const mpt::PathString &filename); static BOOL ImportMidiConfig(SettingsContainer &file); static BOOL ExportMidiConfig(SettingsContainer &file); static void RegisterExtensions(); static BOOL LoadDefaultDLSBanks(); static BOOL SaveDefaultDLSBanks(); static BOOL RemoveDLSBank(UINT nBank); - static BOOL AddDLSBank(LPCSTR); + static BOOL AddDLSBank(const mpt::PathString &filename); static bool OpenURL(const char *url); static bool OpenURL(const std::string &url); static bool OpenURL(const CString &url); Modified: trunk/OpenMPT/mptrack/View_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -2059,10 +2059,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank((LPCSTR)lpDropInfo->lDropParam)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { CDLSBank dlsbank; - if (dlsbank.Open((LPCSTR)lpDropInfo->lDropParam)) + if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -2296,10 +2296,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank((LPCSTR)lpDropInfo->lDropParam)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { CDLSBank dlsbank; - if (dlsbank.Open((LPCSTR)lpDropInfo->lDropParam)) + if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -503,7 +503,7 @@ TV_SORTCB tvs; CDLSBank *pDlsBank = CTrackApp::gpDLSBanks[iDls]; // Add DLS file folder - _splitpath(pDlsBank->GetFileName(), NULL, NULL, szName, szExt); + _splitpath(pDlsBank->GetFileName().ToLocale().c_str(), NULL, NULL, szName, szExt); strcat(szName, szExt); m_tiDLS[iDls] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, szName, IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, iDls, TVI_ROOT, hDlsRoot); @@ -3155,7 +3155,7 @@ "All Files (*.*)|*.*||"); if(!dlg.Show()) return; - CTrackApp::ExportMidiConfig(dlg.GetFirstFile().ToLocale().c_str()); + CTrackApp::ExportMidiConfig(dlg.GetFirstFile()); } Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -500,13 +500,13 @@ } -BOOL CDLSBank::IsDLSBank(const char *lpszFileName) -//------------------------------------------------ +BOOL CDLSBank::IsDLSBank(const mpt::PathString &filename) +//------------------------------------------------------- { RIFFCHUNKID riff; FILE *f; - if ((!lpszFileName) || (!lpszFileName[0])) return FALSE; - if ((f = fopen(lpszFileName, "rb")) == NULL) return FALSE; + if(filename.empty()) return FALSE; + if((f = mpt_fopen(filename, "rb")) == NULL) return FALSE; MemsetZero(riff); fread(&riff, sizeof(RIFFCHUNKID), 1, f); // Check for embedded DLS sections @@ -1138,8 +1138,8 @@ /////////////////////////////////////////////////////////////// // Open: opens a DLS bank -BOOL CDLSBank::Open(const char *lpszFileName) -//------------------------------------------- +BOOL CDLSBank::Open(const mpt::PathString &filename) +//-------------------------------------------------- { SF2LOADERINFO sf2info; const BYTE *lpMemFile; // Pointer to memory-mapped file @@ -1147,12 +1147,12 @@ DWORD dwMemPos, dwMemLength; UINT nInsDef; - if ((!lpszFileName) || (!lpszFileName[0])) return FALSE; - strcpy(m_szFileName, lpszFileName); + if(filename.empty()) return FALSE; + m_szFileName = filename; lpMemFile = NULL; // Memory-Mapped file CMappedFile MapFile; - if (!MapFile.Open(lpszFileName)) return FALSE; + if (!MapFile.Open(filename.ToLocale().c_str())) return FALSE; dwMemLength = MapFile.GetLength(); if (dwMemLength >= 256) lpMemFile = (const BYTE *)MapFile.Lock(); if (!lpMemFile) @@ -1450,7 +1450,7 @@ return FALSE; } dwOffset = m_pWaveForms[nWaveLink] + m_dwWavePoolOffset; - if ((f = fopen(m_szFileName, "rb")) == NULL) return FALSE; + if((f = mpt_fopen(m_szFileName, "rb")) == NULL) return FALSE; if (fseek(f, dwOffset, SEEK_SET) == 0) { if (m_nType & SOUNDBANK_TYPE_SF2) Modified: trunk/OpenMPT/soundlib/Dlsbank.h =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/soundlib/Dlsbank.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -115,7 +115,7 @@ { protected: SOUNDBANKINFO m_BankInfo; - CHAR m_szFileName[_MAX_PATH]; + mpt::PathString m_szFileName; UINT m_nType; DWORD m_dwWavePoolOffset; // DLS Information @@ -129,13 +129,13 @@ CDLSBank(); virtual ~CDLSBank(); void Destroy(); - static BOOL IsDLSBank(const char *lpszFileName); + static BOOL IsDLSBank(const mpt::PathString &filename); static DWORD MakeMelodicCode(UINT bank, UINT instr) { return ((bank << 16) | (instr));} static DWORD MakeDrumCode(UINT rgn, UINT instr) { return (0x80000000 | (rgn << 16) | (instr));} public: - BOOL Open(const char *lpszFileName); - const char *GetFileName() const { return m_szFileName; } + BOOL Open(const mpt::PathString &filename); + mpt::PathString GetFileName() const { return m_szFileName; } UINT GetBankType() const { return m_nType; } UINT GetBankInfo(SOUNDBANKINFO *pBankInfo=NULL) const { if (pBankInfo) *pBankInfo = m_BankInfo; return m_nType; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |