From: <man...@us...> - 2013-11-09 12:34:20
|
Revision: 3142 http://sourceforge.net/p/modplug/code/3142 Author: manxorist Date: 2013-11-09 12:34:09 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Convert almost all fopen to mpt_fopen which takes a mpt::Pathname filename. (Leave Dlsbank.* alone for now) [Ref] Convert CCommandSet to mpt::PathString. [Ref] Convert most of the CSoundFile interface to mpt::PathString. (Leave Dlsbank.* and instrument paths alone for now) [Ref] Convert most of test.cpp to mpt::PathString. [Ref] Related conversions. [Fix] IT Compression test cases should only run if we are in the source code directory. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/CommandSet.h trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/KeyConfigDlg.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Load_s3m.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/WAVTools.cpp trunk/OpenMPT/soundlib/WAVTools.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -268,6 +268,27 @@ #endif +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode) +//----------------------------------------------------------------- +{ + #if defined(WIN32) + return _wfopen(filename.AsNative().c_str(), mode ? mpt::String::Decode(mode, mpt::CharsetLocale).c_str() : nullptr); + #else // !WIN32 + return fopen(filename.AsNative().c_str(), mode); + #endif // WIN32 +} + +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode) +//-------------------------------------------------------------------- +{ + #if defined(WIN32) + return _wfopen(filename.AsNative().c_str(), mode); + #else // !WIN32 + return fopen(filename.AsNative().c_str(), mode ? mpt::String::Encode(mode, mpt::CharsetLocale).c_str() : nullptr); + #endif // WIN32 +} + + #if defined(MODPLUG_TRACKER) static inline char SanitizeFilenameChar(char c) Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -103,6 +103,18 @@ } +static inline std::wstring Replace(std::wstring str, const std::wstring &oldStr, const std::wstring &newStr) +{ + std::size_t pos = 0; + while((pos = str.find(oldStr, pos)) != std::string::npos) + { + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } + return str; +} + + } // namespace String @@ -282,6 +294,9 @@ } // namespace mpt +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode); +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode); + #if defined(MODPLUG_TRACKER) // Sanitize a filename (remove special chars) Modified: trunk/OpenMPT/common/typedefs.cpp =================================================================== --- trunk/OpenMPT/common/typedefs.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/typedefs.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -123,7 +123,7 @@ static FILE * s_logfile = nullptr; if(!s_logfile) { - s_logfile = fopen("mptrack.log", "a"); + s_logfile = mpt_fopen(mpt::PathString::FromUTF8("mptrack.log"), "a"); } if(s_logfile) { Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -247,7 +247,7 @@ // list with backups... hence we have duplicated code.. :( CSoundFile &sndFile = modDoc.GetrSoundFile(); - CString fileName = BuildFileName(modDoc).ToCString(); + mpt::PathString fileName = BuildFileName(modDoc); // We are acutally not going to show the log for autosaved files. ScopedLogCapturer logcapturer(modDoc, "", nullptr, false); Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1484,8 +1484,8 @@ } -bool CCommandSet::SaveFile(CString fileName) -//------------------------------------------ +bool CCommandSet::SaveFile(const mpt::PathString &filename) +//--------------------------------------------------------- { //TODO: Make C++ /* Layout: @@ -1500,7 +1500,7 @@ FILE *outStream; KeyCombination kc; - if( (outStream = fopen( fileName, "w" )) == NULL ) + if((outStream = mpt_fopen(filename, "w")) == NULL) { ErrorBox(IDS_CANT_OPEN_FILE_FOR_WRITING); return false; @@ -1541,8 +1541,8 @@ } -bool CCommandSet::LoadFile(std::istream& iStrm, LPCTSTR szFilename) -//----------------------------------------------------------------- +bool CCommandSet::LoadFile(std::istream& iStrm, const CString &filenameDescription) +//--------------------------------------------------------------------------------- { KeyCombination kc; CommandID cmd=kcNumCommands; @@ -1660,8 +1660,7 @@ } if(!errText.IsEmpty()) { - CString err; - err.Format("The following problems have been encountered while trying to load the key binding file %s:\n", szFilename); + CString err = TEXT("The following problems have been encountered while trying to load the key binding file ") + filenameDescription + TEXT(":\n"); err += errText; Reporting::Warning(err); } @@ -1675,19 +1674,19 @@ } -bool CCommandSet::LoadFile(CString fileName) -//------------------------------------------ +bool CCommandSet::LoadFile(const mpt::PathString &filename) +//--------------------------------------------------------- { - mpt::ifstream fin(fileName); + mpt::ifstream fin(filename.AsNative().c_str()); if (fin.fail()) { CString strMsg; - AfxFormatString1(strMsg, IDS_CANT_OPEN_KEYBINDING_FILE, fileName); + AfxFormatString1(strMsg, IDS_CANT_OPEN_KEYBINDING_FILE, filename.ToCString()); Reporting::Warning(strMsg); return false; } else - return LoadFile(fin, fileName); + return LoadFile(fin, filename.ToCString()); } Modified: trunk/OpenMPT/mptrack/CommandSet.h =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/CommandSet.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -1263,9 +1263,9 @@ //Pululation ;) void Copy(CCommandSet *source); // copy the contents of a commandset into this command set void GenKeyMap(KeyMap &km); // Generate a keymap from this command set - bool SaveFile(CString FileName); - bool LoadFile(CString FileName); - bool LoadFile(std::istream& iStrm, LPCTSTR szFilename); + bool SaveFile(const mpt::PathString &filename); + bool LoadFile(const mpt::PathString &filename); + bool LoadFile(std::istream& iStrm, const CString &filenameDescription); bool LoadDefaultKeymap(); void UpgradeKeymap(CCommandSet *pCommands, int oldVersion); Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1756,9 +1756,9 @@ _splitpath(dlg.GetFirstFile().ToLocale().c_str(), drive, path, NULL, ext); bool ok = false; if (!lstrcmpi(ext, ".iti")) - ok = m_sndFile.SaveITIInstrument(m_nInstrument, dlg.GetFirstFile().ToLocale().c_str(), index == (m_sndFile.GetType() == MOD_TYPE_XM ? 3 : 2)); + ok = m_sndFile.SaveITIInstrument(m_nInstrument, dlg.GetFirstFile(), index == (m_sndFile.GetType() == MOD_TYPE_XM ? 3 : 2)); else - ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile().ToLocale().c_str()); + ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile()); // -> CODE#0023 // -> DESC="IT project files (.itp)" Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1047,12 +1047,12 @@ BeginWaitCursor(); - TCHAR ext[_MAX_EXT]; - mpt::String::Copy(ext, dlg.GetFirstFile().GetFileExt().ToCString().GetString()); + CString ext = dlg.GetFirstFile().GetFileExt().ToCString(); bool bOk = false; SAMPLEINDEX iMinSmp = m_nSample, iMaxSmp = m_nSample; - CString sFilename = dlg.GetFirstFile().ToCString(), sNumberFormat; + mpt::PathString sFilename = dlg.GetFirstFile(); + CString sNumberFormat; if(doBatchSave) { iMinSmp = 1; @@ -1075,14 +1075,14 @@ SanitizeFilename(sSampleName); SanitizeFilename(sSampleFilename); - sFilename = dlg.GetFirstFile().ToCString(); - sFilename.Replace("%sample_number%", sSampleNumber); - sFilename.Replace("%sample_filename%", sSampleFilename); - sFilename.Replace("%sample_name%", sSampleName); + sFilename = dlg.GetFirstFile(); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_number%", mpt::String::FromCString(sSampleNumber))); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_filename%", mpt::String::FromCString(sSampleFilename))); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_name%", mpt::String::FromCString(sSampleName))); } - if(!lstrcmpi(ext, ".raw")) + if(!ext.CompareNoCase(".raw")) bOk = m_sndFile.SaveRAWSample(iSmp, sFilename); - else if(!lstrcmpi(ext, ".flac")) + else if(!ext.CompareNoCase(".flac")) bOk = m_sndFile.SaveFLACSample(iSmp, sFilename); else bOk = m_sndFile.SaveWAVSample(iSmp, sFilename); Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -30,9 +30,9 @@ //Init CommandSet and Load defaults activeCommandSet = new CCommandSet(); - CString sDefaultPath = theApp.GetConfigPath().ToCString() + TEXT("Keybindings.mkb"); - if (sDefaultPath.GetLength() > MAX_PATH - 1) - sDefaultPath = ""; + mpt::PathString sDefaultPath = theApp.GetConfigPath() + mpt::PathString::FromUTF8("Keybindings.mkb"); + if(sDefaultPath.AsNative().length() > MAX_PATH - 1) + sDefaultPath = mpt::PathString(); const bool bNoExistingKbdFileSetting = TrackerSettings::Instance().m_szKbdFile.empty(); @@ -42,12 +42,12 @@ // 4. If there were no keybinging setting already, create a keybinding file to default location // and set it's path to settings. - if (bNoExistingKbdFileSetting || !(activeCommandSet->LoadFile(TrackerSettings::Instance().m_szKbdFile.ToCString()))) + if (bNoExistingKbdFileSetting || !(activeCommandSet->LoadFile(TrackerSettings::Instance().m_szKbdFile))) { if (bNoExistingKbdFileSetting) - TrackerSettings::Instance().m_szKbdFile = mpt::PathString::FromCString(sDefaultPath); + TrackerSettings::Instance().m_szKbdFile = sDefaultPath; bool bSuccess = false; - if (PathFileExists(sDefaultPath) == TRUE) + if (PathFileExistsW(sDefaultPath.AsNative().c_str()) == TRUE) bSuccess = activeCommandSet->LoadFile(sDefaultPath); if (bSuccess == false) { @@ -56,14 +56,14 @@ bSuccess = activeCommandSet->LoadDefaultKeymap(); if (bSuccess && bNoExistingKbdFileSetting) { - activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile.ToCString()); + activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile); } } if (bSuccess == false) ErrorBox(IDS_UNABLE_TO_LOAD_KEYBINDINGS); } // We will only overwrite the default Keybindings.mkb file from now on. - TrackerSettings::Instance().m_szKbdFile = mpt::PathString::FromCString(sDefaultPath); + TrackerSettings::Instance().m_szKbdFile = sDefaultPath; //Get Keymap activeCommandSet->GenKeyMap(keyMap); Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -846,7 +846,7 @@ if(!dlg.Show()) return; m_sFullPathName = dlg.GetFirstFile(); - plocalCmdSet->LoadFile(m_sFullPathName.ToCString()); + plocalCmdSet->LoadFile(m_sFullPathName); ForceUpdateGUI(); //TentativeSetToDefaultFile(m_sFullPathName); } @@ -863,7 +863,7 @@ if(!dlg.Show()) return; m_sFullPathName = dlg.GetFirstFile(); - plocalCmdSet->SaveFile(m_sFullPathName.ToCString()); + plocalCmdSet->SaveFile(m_sFullPathName); //TentativeSetToDefaultFile(m_sFullPathName); } Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -467,7 +467,7 @@ if(m_InputHandler && m_InputHandler->activeCommandSet) { - m_InputHandler->activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile.ToCString()); + m_InputHandler->activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile); } EndWaitCursor(); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -428,13 +428,14 @@ } BeginWaitCursor(); FixNullStrings(); + const mpt::PathString filename = mpt::PathString::FromCString(lpszPathName); switch(type) { - case MOD_TYPE_MOD: bOk = m_SndFile.SaveMod(lpszPathName); break; - case MOD_TYPE_S3M: bOk = m_SndFile.SaveS3M(lpszPathName); break; - case MOD_TYPE_XM: bOk = m_SndFile.SaveXM(lpszPathName); break; - case MOD_TYPE_IT: bOk = (m_SndFile.m_SongFlags[SONG_ITPROJECT] ? m_SndFile.SaveITProject(lpszPathName) : m_SndFile.SaveIT(lpszPathName)); break; - case MOD_TYPE_MPT: bOk = m_SndFile.SaveIT(lpszPathName); break; + case MOD_TYPE_MOD: bOk = m_SndFile.SaveMod(filename); break; + case MOD_TYPE_S3M: bOk = m_SndFile.SaveS3M(filename); break; + case MOD_TYPE_XM: bOk = m_SndFile.SaveXM(filename); break; + case MOD_TYPE_IT: bOk = (m_SndFile.m_SongFlags[SONG_ITPROJECT] ? m_SndFile.SaveITProject(filename) : m_SndFile.SaveIT(filename)); break; + case MOD_TYPE_MPT: bOk = m_SndFile.SaveIT(filename); break; } EndWaitCursor(); if (bOk) @@ -511,9 +512,9 @@ const bool xi = !_stricmp(&m_SndFile.m_szInstrumentPath[instr][len - 2], "xi"); if(iti || (!xi && m_SndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT))) - success = m_SndFile.SaveITIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr].c_str(), false); + success = m_SndFile.SaveITIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr]), false); else - success = m_SndFile.SaveXIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr].c_str()); + success = m_SndFile.SaveXIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr])); if(success) m_bsInstrumentModified.reset(instr); @@ -1953,10 +1954,10 @@ switch (type) { case MOD_TYPE_XM: - m_SndFile.SaveXM(dlg.GetFirstFile().ToLocale().c_str(), true); + m_SndFile.SaveXM(dlg.GetFirstFile(), true); break; case MOD_TYPE_IT: - m_SndFile.SaveIT(dlg.GetFirstFile().ToLocale().c_str(), true); + m_SndFile.SaveIT(dlg.GetFirstFile(), true); break; } } Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1110,8 +1110,8 @@ #include "../mptrack/Mptrack.h" // For config filename #endif // MODPLUG_TRACKER -bool CSoundFile::SaveIT(const char *lpszFileName, bool compatibilityExport) -//------------------------------------------------------------------------- +bool CSoundFile::SaveIT(const mpt::PathString &filename, bool compatibilityExport) +//-------------------------------------------------------------------------------- { const CModSpecifications &specs = (GetType() == MOD_TYPE_MPT ? ModSpecs::mptm : (compatibilityExport ? ModSpecs::it : ModSpecs::itEx)); @@ -1120,7 +1120,7 @@ DWORD dwPos = 0, dwHdrPos = 0, dwExtra = 0; FILE *f; - if ((!lpszFileName) || ((f = fopen(lpszFileName, "wb")) == NULL)) return false; + if(filename.empty() || ((f = mpt_fopen(filename, "wb")) == NULL)) return false; // Writing Header MemsetZero(itHeader); Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -279,11 +279,11 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveITProject(const char *lpszFileName) -//------------------------------------------------------ +bool CSoundFile::SaveITProject(const mpt::PathString &filename) +//------------------------------------------------------------- { #ifndef MODPLUG_TRACKER - MPT_UNREFERENCED_PARAMETER(lpszFileName); + MPT_UNREFERENCED_PARAMETER(filename); return false; #else // MODPLUG_TRACKER @@ -299,7 +299,7 @@ FILE *f; - if((!lpszFileName) || ((f = fopen(lpszFileName, "wb")) == NULL)) return false; + if(filename.empty() || ((f = mpt_fopen(filename, "wb")) == NULL)) return false; // File ID Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1095,13 +1095,13 @@ #include "../mptrack/moddoc.h" #endif // MODPLUG_TRACKER -bool CSoundFile::SaveMod(const char *lpszFileName) const -//------------------------------------------------------ +bool CSoundFile::SaveMod(const mpt::PathString &filename) const +//------------------------------------------------------------- { FILE *f; - if(m_nChannels == 0 || lpszFileName == nullptr) return false; - if((f = fopen(lpszFileName, "wb")) == nullptr) return false; + if(m_nChannels == 0 || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == nullptr) return false; // Write song title { Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -539,8 +539,8 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveS3M(const char *lpszFileName) const -//------------------------------------------------------ +bool CSoundFile::SaveS3M(const mpt::PathString &filename) const +//------------------------------------------------------------- { static const uint8 filler[16] = { @@ -549,8 +549,8 @@ }; FILE *f; - if(m_nChannels == 0 || lpszFileName == nullptr) return false; - if((f = fopen(lpszFileName, "wb")) == nullptr) return false; + if(m_nChannels == 0 || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == nullptr) return false; S3MFileHeader fileHeader; MemsetZero(fileHeader); Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -651,11 +651,11 @@ #define str_pattern (GetStrI18N("pattern")) -bool CSoundFile::SaveXM(const char *lpszFileName, bool compatibilityExport) -//------------------------------------------------------------------------- +bool CSoundFile::SaveXM(const mpt::PathString &filename, bool compatibilityExport) +//-------------------------------------------------------------------------------- { FILE *f; - if(lpszFileName == nullptr || (f = fopen(lpszFileName, "wb")) == nullptr) + if(filename.empty() || (f = mpt_fopen(filename, "wb")) == nullptr) { return false; } Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -453,10 +453,10 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//--------------------------------------------------------------------------------- +bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------- { - WAVWriter file(lpszFileName); + WAVWriter file(filename); if(!file.IsValid()) { @@ -494,11 +494,11 @@ /////////////////////////////////////////////////////////////// // Save RAW -bool CSoundFile::SaveRAWSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//--------------------------------------------------------------------------------- +bool CSoundFile::SaveRAWSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------- { FILE *f; - if ((f = fopen(lpszFileName, "wb")) == NULL) return false; + if((f = mpt_fopen(filename, "wb")) == NULL) return false; const ModSample &sample = Samples[nSample]; SampleIO( @@ -953,17 +953,17 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveXIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName) const -//--------------------------------------------------------------------------------------- +bool CSoundFile::SaveXIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------------- { ModInstrument *pIns = Instruments[nInstr]; - if(pIns == nullptr || lpszFileName == nullptr) + if(pIns == nullptr || filename.empty()) { return false; } FILE *f; - if((f = fopen(lpszFileName, "wb")) == nullptr) + if((f = mpt_fopen(filename, "wb")) == nullptr) { return false; } @@ -1535,15 +1535,15 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveITIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName, bool compress) const -//------------------------------------------------------------------------------------------------------- +bool CSoundFile::SaveITIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename, bool compress) const +//-------------------------------------------------------------------------------------------------------------- { ITInstrumentEx iti; ModInstrument *pIns = Instruments[nInstr]; FILE *f; - if((!pIns) || (!lpszFileName)) return false; - if((f = fopen(lpszFileName, "wb")) == NULL) return false; + if((!pIns) || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == NULL) return false; size_t instSize = iti.ConvertToIT(*pIns, false, *this); @@ -2044,8 +2044,8 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveFLACSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//---------------------------------------------------------------------------------- +bool CSoundFile::SaveFLACSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//----------------------------------------------------------------------------------------- { #ifndef NO_FLAC FLAC__StreamEncoder *encoder = FLAC__stream_encoder_new(); @@ -2144,7 +2144,7 @@ FLAC__stream_encoder_set_compression_level(encoder, compression); #endif // MODPLUG_TRACKER - if(FLAC__stream_encoder_init_file(encoder, lpszFileName, nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + if(FLAC__stream_encoder_init_file(encoder, filename.ToLocale().c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { return false; } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -565,11 +565,11 @@ // Save Functions #ifndef MODPLUG_NO_FILESAVE - bool SaveXM(const char *lpszFileName, bool compatibilityExport = false); - bool SaveS3M(const char *lpszFileName) const; - bool SaveMod(const char *lpszFileName) const; - bool SaveIT(const char *lpszFileName, bool compatibilityExport = false); - bool SaveITProject(const char *lpszFileName); // -> CODE#0023 -> DESC="IT project files (.itp)" -! NEW_FEATURE#0023 + bool SaveXM(const mpt::PathString &filename, bool compatibilityExport = false); + bool SaveS3M(const mpt::PathString &filename) const; + bool SaveMod(const mpt::PathString &filename) const; + bool SaveIT(const mpt::PathString &filename, bool compatibilityExport = false); + bool SaveITProject(const mpt::PathString &filename); // -> CODE#0023 -> DESC="IT project files (.itp)" -! NEW_FEATURE#0023 UINT SaveMixPlugins(FILE *f=NULL, BOOL bUpdate=TRUE); void WriteInstrumentPropertyForAllInstruments(uint32 code, int16 size, FILE* f, UINT nInstruments) const; void SaveExtendedInstrumentProperties(UINT nInstruments, FILE* f) const; @@ -749,9 +749,9 @@ bool ReadFLACSample(SAMPLEINDEX sample, FileReader &file); bool ReadMP3Sample(SAMPLEINDEX sample, FileReader &file); #ifndef MODPLUG_NO_FILESAVE - bool SaveWAVSample(SAMPLEINDEX nSample, const char *lpszFileName) const; - bool SaveRAWSample(SAMPLEINDEX nSample, const char *lpszFileName) const; - bool SaveFLACSample(SAMPLEINDEX nSample, const char *lpszFileName) const; + bool SaveWAVSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; + bool SaveRAWSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; + bool SaveFLACSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; #endif // Instrument file I/O @@ -761,8 +761,8 @@ bool ReadPATInstrument(INSTRUMENTINDEX nInstr, const LPBYTE lpMemFile, DWORD dwFileLength); bool ReadSampleAsInstrument(INSTRUMENTINDEX nInstr, FileReader &file, bool mayNormalize=false); #ifndef MODPLUG_NO_FILESAVE - bool SaveXIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName) const; - bool SaveITIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName, bool compress) const; + bool SaveXIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename) const; + bool SaveITIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename, bool compress) const; #endif // I/O from another sound file Modified: trunk/OpenMPT/soundlib/WAVTools.cpp =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -252,10 +252,10 @@ // Output to file: Initialize with filename. -WAVWriter::WAVWriter(const char *filename) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0) -//---------------------------------------------------------------------------------------------------------------- +WAVWriter::WAVWriter(const mpt::PathString &filename) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0) +//--------------------------------------------------------------------------------------------------------------------------- { - f = fopen(filename, "w+b"); + f = mpt_fopen(filename, "w+b"); fileOwned = true; Init(); } Modified: trunk/OpenMPT/soundlib/WAVTools.h =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/WAVTools.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -404,7 +404,7 @@ public: // Output to file: Initialize with filename. The created FILE* is owned by this instance. - WAVWriter(const char *filename); + WAVWriter(const mpt::PathString &filename); // Output to file: Initialize with FILE*. WAVWriter(FILE *file); // Output to stream: Initialize with std::ostream*. Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/test/test.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1340,20 +1340,23 @@ #ifdef MODPLUG_TRACKER -static const char * debugPaths [] = { "mptrack\\Debug", "bin\\Win32-Debug", "bin\\x64-Debug" }; +static const char * debugPaths [] = { "mptrack\\Debug\\", "bin\\Win32-Debug\\", "bin\\x64-Debug\\" }; -static bool PathEndsIn(const CString &path, const CString &match) +static bool PathEndsIn(const mpt::PathString &path_, const mpt::PathString &match_) { - return path.Mid(path.GetLength() - match.GetLength() - 1, match.GetLength()) == match; + std::wstring path = path_.ToWide(); + std::wstring match = match_.ToWide(); + return path.rfind(match) == (path.length() - match.length()); } static bool ShouldRunTests() { - CString theFile = theApp.GetAppDirPath().ToCString(); + mpt::PathString theFile = theApp.GetAppDirPath(); // Only run the tests when we're in the project directory structure. for(std::size_t i = 0; i < CountOf(debugPaths); ++i) { - if(PathEndsIn(theFile, debugPaths[i])) + const mpt::PathString debugPath = mpt::PathString::FromUTF8(debugPaths[i]); + if(PathEndsIn(theFile, debugPath)) { return true; } @@ -1361,20 +1364,20 @@ return false; } -static std::string GetTestFilenameBase() +static mpt::PathString GetTestFilenameBase() { - CString theFile = theApp.GetAppDirPath().ToCString(); + mpt::PathString theFile = theApp.GetAppDirPath(); for(std::size_t i = 0; i < CountOf(debugPaths); ++i) { - if(PathEndsIn(theFile, debugPaths[i])) + const mpt::PathString debugPath = mpt::PathString::FromUTF8(debugPaths[i]); + if(PathEndsIn(theFile, debugPath)) { - std::size_t count = CString(debugPaths[i]).GetLength() + 1; - theFile.Delete(theFile.GetLength() - count, count); + theFile = mpt::PathString::FromWide(theFile.ToWide().substr(0, theFile.ToWide().length() - debugPath.ToWide().length())); break; } } - theFile.Append("test/test."); - return theFile.GetString(); + theFile += mpt::PathString::FromUTF8("test/test."); + return theFile; } typedef CModDoc *TSoundFileContainer; @@ -1384,9 +1387,9 @@ return sndFile->GetrSoundFile(); } -static TSoundFileContainer CreateSoundFileContainer(const std::string filename) +static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename.c_str(), FALSE); + CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename.ToCString(), FALSE); return pModDoc; } @@ -1395,23 +1398,23 @@ sndFile->OnCloseDocument(); } -static void SaveIT(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveIT(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } -static void SaveXM(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveXM(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } -static void SaveS3M(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveS3M(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } @@ -1423,9 +1426,9 @@ return true; } -static std::string GetTestFilenameBase() +static mpt::PathString GetTestFilenameBase() { - return "../test/test."; + return mpt::PathString::FromUTF8("../test/test."); } typedef std::shared_ptr<CSoundFile> TSoundFileContainer; @@ -1435,9 +1438,9 @@ return *sndFile.get(); } -static TSoundFileContainer CreateSoundFileContainer(const std::string &filename) +static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - mpt::ifstream stream(filename, std::ios::binary); + mpt::ifstream stream(filename.AsNative().c_str(), std::ios::binary); FileReader file(&stream); std::shared_ptr<CSoundFile> pSndFile(new CSoundFile()); pSndFile->Create(file, CSoundFile::loadCompleteModule); @@ -1451,19 +1454,19 @@ #ifndef MODPLUG_NO_FILESAVE -static void SaveIT(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveIT(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveIT(filename.c_str(), false); + sndFile->SaveIT(filename, false); } -static void SaveXM(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveXM(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveXM(filename.c_str(), false); + sndFile->SaveXM(filename, false); } -static void SaveS3M(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveS3M(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveS3M(filename.c_str()); + sndFile->SaveS3M(filename); } #endif @@ -1480,17 +1483,17 @@ { return; } - std::string filenameBase = GetTestFilenameBase(); + mpt::PathString filenameBase = GetTestFilenameBase(); // Test MPTM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "mptm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveIT(sndFileContainer, filenameBase + "saved.mptm"); + SaveIT(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.mptm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1499,7 +1502,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.mptm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); @@ -1509,7 +1512,7 @@ // Test XM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "xm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1523,7 +1526,7 @@ #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveXM(sndFileContainer, filenameBase + "saved.xm"); + SaveXM(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.xm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1532,7 +1535,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.xm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1542,13 +1545,13 @@ // Test S3M file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "s3m"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), false); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveS3M(sndFileContainer, filenameBase + "saved.s3m"); + SaveS3M(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.s3m")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1557,7 +1560,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.s3m"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), true); @@ -1570,7 +1573,7 @@ void RunITCompressionTest(const std::vector<int8> &sampleData, ChannelFlags smpFormat, bool it215, int testcount) //--------------------------------------------------------------------------------------------------------------- { - std::string filename = GetTestFilenameBase() + "itcomp" + Stringify(testcount) + ".raw"; + mpt::PathString filename = GetTestFilenameBase() + mpt::PathString::FromUTF8("itcomp" + Stringify(testcount) + ".raw"); ModSample smp; smp.uFlags = smpFormat; @@ -1578,13 +1581,13 @@ smp.nLength = sampleData.size() / smp.GetBytesPerSample(); { - FILE *f = fopen(filename.c_str(), "wb"); + FILE *f = mpt_fopen(filename, "wb"); ITCompression compression(smp, it215, f); fclose(f); } { - FILE *f = fopen(filename.c_str(), "rb"); + FILE *f = mpt_fopen(filename, "rb"); fseek(f, 0, SEEK_END); std::vector<int8> fileData(ftell(f), 0); fseek(f, 0, SEEK_SET); @@ -1598,7 +1601,7 @@ VERIFY_EQUAL_NONCONT(memcmp(&sampleData[0], &sampleDataNew[0], sampleData.size()), 0); fclose(f); } - while(remove(filename.c_str()) == EACCES) + while(remove(filename.ToLocale().c_str()) == EACCES) { // wait for windows virus scanners #ifdef WIN32 @@ -1611,6 +1614,10 @@ void TestITCompression() //---------------------- { + if(!ShouldRunTests()) + { + return; + } // Test loading / saving of IT-compressed samples const int sampleDataSize = 65536; std::vector<int8> sampleData(sampleDataSize, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |